Next: Array I/O, Previous: Array members, Up: Arrays [Contents][Index]
void allocateArrays(TinyVector<int,N>& shape, Array<T,N>& A, Array<T,N>& B, ...);
This function will allocate interlaced arrays, but only if interlacing is
desirable for your architecture. This is controlled by the
BZ_INTERLACE_ARRAYS
flag in blitz/tuning.h. You can provide up to
11 arrays as parameters. Any views currently associated with the array
objects are lost. Here is a typical use:
Array<int,2> A, B, C; allocateArrays(shape(64,64),A,B,C);
If array interlacing is enabled, then the arrays are stored in memory like
this: A(0,0)
, B(0,0)
, C(0,0)
, A(0,1)
,
B(0,1)
, ... If interlacing is disabled, then the arrays are
allocated in the normal fashion: each array has its own block of memory.
Once interlaced arrays are allocated, they can be used just like regular
arrays.
#include <blitz/array/convolve.h> Array<T,1> convolve(const Array<T,1>& B, const Array<T,1>& C);
This function computes the 1-D convolution of the arrays B and C: A[i] = sum(B[j] * C[i-j], j) If the array B has domain b_l \ldots b_h, and array C has domain c_l \ldots c_h, then the resulting array has domain a_l \ldots a_h, with l = b_l + c_l and a_h = b_h + c_h.
A new array is allocated to contain the result. To avoid copying the result
array, you should use it as a constructor argument. For example:
Array<float,1> A = convolve(B,C);
The convolution is computed in the
spatial domain. Frequency-domain transforms are not used. If you are
convolving two large arrays, then this will be slower than using a Fourier
transform.
Note that if you need a cross-correlation, you can use the convolve function with one of the arrays reversed. For example:
Array<float,1> A = convolve(B,C.reverse());
Autocorrelation can be performed using the same approach.
void cycleArrays(Array<T,N>& A, Array<T,N>& B); void cycleArrays(Array<T,N>& A, Array<T,N>& B, Array<T,N>& C); void cycleArrays(Array<T,N>& A, Array<T,N>& B, Array<T,N>& C, Array<T,N>& D); void cycleArrays(Array<T,N>& A, Array<T,N>& B, Array<T,N>& C, Array<T,N>& D, Array<T,N>& E);
These routines are useful for time-stepping PDEs. They take a set of arrays
such as [A,B,C,D
] and cyclically rotate them to [B,C,D,A
];
i.e. the A
array then refers to what was B
’s data, the
B
array refers to what was C
’s data, and the D
array
refers to what was A
’s data. These functions operate in constant
time, since only the handles change (i.e. no data is copied; only pointers
change).
void find(Array<TinyVector<int,Expr::rank>,1>& indices, const _bz_ArrayExpr<Expr>& expr); void find(Array<TinyVector<int,N>,1>& indices, const Array<bool,N>& exprVals);
This is an analogue to the Matlab find()
method, which takes a
boolean array expression or an array of bools and returns a 1d array
of indices for all locations where the array or expression is true.
Array<T,N> imag(Array<complex<T>,N>&);
This method returns a view of the imaginary portion of the array.
void interlaceArrays(TinyVector<int,N>& shape, Array<T,N>& A, Array<T,N>& B, ...);
This function is similar to allocateArrays()
above, except that the
arrays are always interlaced, regardless of the setting of the
BZ_INTERLACE_ARRAYS
flag.
Array<T,N> real(Array<complex<T>,N>&);
This method returns a view of the real portion of the array.
TinyVector<int,1> shape(int L); TinyVector<int,2> shape(int L, int M); TinyVector<int,3> shape(int L, int M, int N); TinyVector<int,4> shape(int L, int M, int N, int O); ... [up to 11 dimensions]
These functions may be used to create shape parameters. They package the
set of integer arguments as a TinyVector
of appropriate length. For
an example use, see allocateArrays()
above.
void swap(Array<T,N>& A, Array<T,N>& B);
This function swaps the storage of two arrays, just like the std::swap()
function does for STL container types. This is a synonym for the
two-argument version of cycleArrays()
above.
Next: Array I/O, Previous: Array members, Up: Arrays [Contents][Index]