Blitz logo

Blitz Support :

From: Julian C. Cummings (cummings_at_[hidden])
Date: 2004-08-23 21:28:40


Hello Simon,

I've thought about this one for a while, and I believe you have a valid
point here. Still, I'm not sure how to reconcile the code behavior with
your (reasonable) expectation.

What happens when you say a(Range(6,0,-2)) is that you construct a new Array
which references the storage of the original Array a. The data_ pointer is
moved forward by 6, so that the new zeroth element is the sixth element of
the original Array. Meanwhile, the zeroOffset_ value is set to -6,
indicating where the original element 0 is with respect to the data_
pointer. (That seems a bit strange to me. The code comments say if base_
is zero and all storage is ascending, then zeroOffset_ should be zero.) The
stride is set to the stride of the Range, which is -2. The storage in
memory does not change, it remains in ascending order (i.e., memory storage
order is in the same direction as ascending index number).

Now dataFirst() only differs from data() if one or more Array ranks are
stored in descending order. Since that is not the case here, you get the
same result for both.
Perhaps what we need to do is to modify the Array::slice() method to flip
the value of the ascendingFlag inside the storage_ member if the stride is
negative. I need to think this through a bit more, but I believe this would
solve the problem.

Regards, Julian C.

Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]
 

> -----Original Message-----
> From: blitz-support-bounces_at_[hidden]
> [mailto:blitz-support-bounces_at_[hidden]] On Behalf Of
> Simon Perreault
> Sent: Friday, August 20, 2004 12:09 PM
> To: blitz-support_at_[hidden]
> Subject: [Blitz-support] Array::dataFirst() not working?
>
>
> Hi,
>
> I am having issues with the dataFirst() array method. Take a
> look at this test
> code:
>
> -----------
> #include <blitz/array.h>
>
> using namespace blitz;
> using namespace std;
>
> int main( int argc, char* argv[] )
> {
> Array<int,1> a(7);
> a = 0, 1, 2, 3, 4, 5, 6;
> Array<int,1> b;
> b.reference( a( Range( 6, 0, -2 ) ) );
> cout << b << endl;
> cout << b.stride(0) << endl;
> cout << *b.data() << endl;
> cout << *b.dataFirst() << endl;
> }
> -----------
>
> The output of this program is:
>
> -----------
> 4
> [ 6 4 2 0 ]
> -2
> 6
> 6
> -----------
>
> Shouldn't the element pointed by dataFirst() be 0 since it
> comes in memory
> before 6?
>
> Thanks
>
> --
> Simon Perreault <nomis80_at_[hidden]> -- http://nomis80.org
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>