![]() |
Blitz Support : |
From: Faheem Mitha (faheem_at_[hidden])
Date: 2005-05-20 21:14:36
On Fri, 20 May 2005, Julian Cummings wrote:
> Hello Faheem,
>
> The depth value that you are getting for the 2-dimensional Array is
> obviously bogus. You are accessing an element in the TinyVector length_
> that is out of bounds. Bounds checking (and other sanity checks) are
> enabled by compiling with -DBZ_DEBUG. If you compile your example with
> this flag and run it, it will report the illegal element access and
> halt. Without such checking, the call to depth() will just happily hand
> you the next piece of data within the Array object, which happens to be
> an 8 (the first element of the TinyVector stride_). It's a good idea to
> always build a blitz code in debug mode including the -DBZ_DEBUG flag
> and make sure everything runs OK, then rebuild in optimized mode without
> this flag to remove the run-time checks.
>
> In the case where A is a 3-dimensional Array, blitz allows you to
> provide fewer length parameters than the number of dimensions. It will
> automatically use the final length argument for all remaining
> dimensions. This is just a convenience for lazy code writers. I
> personally don't like this feature because it can lead to unintended
> consequences. So my advice is to take care to always provide the proper
> number of length arguments or use the convenient blitz shape() function
> to produce a TinyVector of Array extents. For example, the line
>
> Array<int,3> A(shape(8,8));
>
> fails to compile because the Array constructor will not accept a
> TinyVector of extents with the wrong rank. So it forces you to write
>
> Array<int,3> A(shape(8,8,1));
>
> which produces the expected results in your example code.
Thanks. That is very helpful and informative. Faheem.