![]() |
Blitz Devel : |
From: Derrick Bass (derrick_at_[hidden])
Date: 1998-08-22 02:50:25
Hi. I've been working a lot recently with arrays with strange bases,
and I need a function that can reindex an array, i.e. return an array
with the same data but a different base vector.
Is there any way to do this without support from within the Array
class itself? All my kludges had memory leaks because I could not
access the reference counting mechanism. If it can't be done
externally, I've hacked the function into the Array class. Below
is a pair of context diffs for blitz/array.h and
blitz/array/methods.cc (I hacked version 0.4.2). If you think this is
useful and want to include it (or some modified form of it) in Blitz, go
ahead, but you'd better check it first. My understanding of Blitz
internals is a little shaky.
Derrick Bass
*** array.h.orig Fri Aug 21 22:09:21 1998
--- array.h Fri Aug 21 22:23:21 1998
***************
*** 1187,1192 ****
--- 1187,1198 ----
T_array reverse(int rank);
void reverseSelf(int rank);
+ // Added by Derrick Bass
+ T_array reindex(const TinyVector<int,N_rank>&);
+ void reindexSelf(const
+ TinyVector<int,N_rank>&);
+ // End Derrick Bass additions
+
int rows() const
{ return length_[0]; }
*** array/methods.cc.orig Tue Jun 23 16:29:27 1998
--- array/methods.cc Fri Aug 21 23:51:03 1998
***************
*** 55,60 ****
--- 55,82 ----
}
+ // Added by Derrick Bass
+ /* These routines reindex the current array to use a new base vector.
+ The first reindexes the array, the second just returns a reindex view
+ of the current array, leaving the current array unmodified.
+ */
+ template<class P_numtype, int N_rank>
+ _bz_inline2 void Array<P_numtype, N_rank>::reindexSelf(const
+ TinyVector<int, N_rank>& newBase) {
+ data_ += dot( base() - newBase, stride_ );
+ storage_.setBase(newBase);
+ calculateZeroOffset();
+ }
+
+ template<class P_numtype, int N_rank>
+ _bz_inline2 Array<P_numtype, N_rank>
+ Array<P_numtype, N_rank>::reindex(const TinyVector<int, N_rank>& newBase) {
+ T_array B(*this);
+ B.reindexSelf(newBase);
+ return B;
+ }
+ // End Derrick Bass additions
+
/*
* This routine takes the storage information for the array
* (ascendingFlag_[], base_[], and ordering_[]) and the size
--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo_at_[hidden], with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/