📄 arrays-members.texi
字号:
@findex isMajorRank()@cindex Array member functions @code{isMajorRank()}@examplebool isMajorRank(int dimension) const;@end exampleReturns true if the dimension has the largest stride. For C-style arrays(the default), the first dimension always has the largest stride. ForFortran-style arrays, the last dimension has the largest stride. See also@code{isMinorRank()} below and the note about dimension parameters such as@code{firstDim} in the previous section.@findex isMinorRank()@cindex Array member functions @code{isMinorRank()}@examplebool isMinorRank(int dimension) const;@end exampleReturns true if the dimension @emph{does not} have the largest stride. Seealso @code{isMajorRank()}.@findex isRankStoredAscending()@cindex Array member functions @code{isRankStoredAscending()}@examplebool isRankStoredAscending(int dimension) const;@end exampleReturns true if the dimension is stored in ascending order in memory. Thisis the default. It will only return false if you have reversed a dimensionusing @code{reverse()} or have created a custom storage order with adescending dimension.@findex isStorageContiguous()@cindex Array member functions @code{isStorageContiguous()}@examplebool isStorageContiguous() const;@end exampleReturns true if the array data is stored contiguously in memory. If youslice the array or work on subarrays, there can be skips -- the array datais interspersed with other data not part of the array. See also the various@code{data..()} functions. If you need to ensure that the storage iscontiguous, try @code{reference(copy())}.@findex lbound()@cindex Array member functions @code{lbound()}@exampleint lbound(int dimension) const;TinyVector<int,N_rank> lbound() const;@end exampleThe first version returns the lower bound of the valid index range for adimension. The second version returns a vector of lower bounds for alldimensions. The lower bound is the first valid index value. If you'reusing a C-style array (the default), the lbound will be zero; Fortran-stylearrays have lbound equal to one. The lbound can be different for eachdimension, but only if you deliberately set them that way using a Rangeconstructor or a custom storage ordering. This function is equivalent to@code{base(dimension)}. See the note about dimension parameters such as@code{firstDim} in the previous section.@findex makeUnique()@cindex Array member functions @code{makeUnique()}@cindex Array making unique copy@examplevoid makeUnique();@end exampleIf the array's data is being shared with another Blitz++ array object, thismember function creates a copy so the array object has a unique view of thedata. @findex numElements()@cindex Array member functions @code{numElements()}@cindex Array number of elements in@exampleint numElements() const;@end exampleReturns the total number of elements in the array, calculated by taking theproduct of the extent in each dimension. Same as @code{size()}.@findex ordering()@cindex Array member functions @code{ordering()}@cindex Array storage ordering of@exampleconst TinyVector<int, N_rank>& ordering() const;int ordering(int storageRankIndex) const;@end exampleThese member functions return information about how the data is ordered inmemory. The first version returns the complete ordering vector; the secondversion returns a single element from the ordering vector. The argument forthe second version must be in the range 0 .. @code{N_rank}-1. The orderingvector is a list of dimensions in increasing order of stride;@code{ordering(0)} will return the dimension number with the smalleststride, and @code{ordering(N_rank-1)} will return the dimension number withlargest stride. For a C-style array, the ordering vector contains theelements (@code{N_rank}-1, @code{N_rank}-2, ..., 0). For a Fortran-stylearray, the ordering vector is (0, 1, ..., @code{N_rank}-1). See also thedescription of custom storage orders in section @ref{Array storage}.@findex rank()@cindex Array member functions @code{rank()}@exampleint rank() const;@end exampleReturns the rank (number of dimensions) of the array. The return value isequal to @code{N_rank}. Equivalent to @code{dimensions()}.@findex reference()@cindex Array member functions @code{reference()}@cindex Array referencing another@examplevoid reference(Array<T_numtype,N_rank>& A);@end exampleThis causes the array to adopt another array's data as its own. After thismember function is used, the array object and the array @code{A} areindistinguishable -- they have identical sizes, index ranges, and data. Thedata is shared between the two arrays.@findex reindex(), reindexSelf()@cindex Array member functions @code{reindex()}@cindex Array member functions @code{reindexSelf()}@cindex Array reindexing@examplevoid reindexSelf(const TinyVector<int,N_rank>&);Array<T,N> reindex(const TinyVector<int,N_rank>&);@end exampleThese methods reindex an array to use a new base vector. The first versionreindexes the array, and the second just returns a reindexed view of thearray, leaving the original array unmodified.@findex resize()@cindex Array member functions @code{resize()}@cindex Array resizing@examplevoid resize(int extent1, ...);void resize(const TinyVector<int,N_rank>&);@end exampleThese functions resize an array to the specified size. If the array isalready the size specified, then no memory is allocated. After resizing,the contents of the array are garbage. See also @code{resizeAndPreserve()}.@findex resizeAndPreserve()@cindex Array member functions @code{resizeAndPreserve()}@examplevoid resizeAndPreserve(int extent1, ...);void resizeAndPreserve(const TinyVector<int,N_rank>&);@end exampleThese functions resize an array to the specified size. If the array isalready the size specified, then no change occurs (the array is notreallocated and copied). The contents of the array are preserved wheneverpossible; if the new array size is smaller, then some data will be lost.Any new elements created by resizing the array are left uninitialized.@findex reverse(), reverseSelf()@cindex Array member functions @code{reverse()}@cindex Array member functions @code{reverseSelf()}@cindex Array reversing@exampleArray<T,N> reverse(int dimension);void reverseSelf(int dimension);@end exampleThis method reverses the array in the specified dimension. For example, if@code{reverse(firstDim)} is invoked on a 2-dimensional array, then theordering of rows in the array will be reversed; @code{reverse(secondDim)}would reverse the order of the columns. Note that this is implemented bytwiddling the strides of the array, and doesn't cause any data copying. Thefirst version returns a reversed ``view'' of the array data; the secondversion applies the reversal to the array itself.@findex rows()@cindex Array member functions @code{rows()}@exampleint rows() const;@end exampleReturns the extent (length) of the array in the first dimension. Thisfunction is equivalent to @code{extent(firstDim)}. See also@code{columns()}, and @code{depth()}.@findex size()@cindex Array member functions @code{size()}@exampleint size() const;@end exampleReturns the total number of elements in the array, calculated by taking theproduct of the extent in each dimension. Same as @code{numElements()}.@cindex @code{shape()} (Array method)@cindex Array member functions @code{shape()}@cindex Array shape of@exampleconst TinyVector<int, N_rank>& shape() const;@end exampleReturns the vector of extents (lengths) of the array.@findex stride()@cindex Array member functions @code{stride()}@cindex Array strides of@exampleconst TinyVector<int, N_rank>& stride() const;int stride(int dimension) const;@end exampleThe first version returns the stride vector; the second version returns thestride associated with a dimension. A stride is the distance betweenpointers to two array elements which are adjacent in a dimension. Forexample, @code{A.stride(firstDim)} is equal to @code{&A(1,0,0) - &A(0,0,0)}.The stride for the second dimension, @code{A.stride(secondDim)}, is equal to@code{&A(0,1,0) - &A(0,0,0)}, and so on. For more information aboutstrides, see the description of custom storage formats in Section@ref{Array storage}. See also the description of parameters like@code{firstDim} and @code{secondDim} in the previous section.@cindex Array member functions @code{transpose()}@cindex Array member functions @code{transposeSelf()}@cindex Array transposing@cindex transposing arrays@findex transpose(), transposeSelf()@exampleArray<T,N> transpose(int dimension1, int dimension2, ...);void transposeSelf(int dimension1, int dimension2, ...);@end exampleThese methods permute the dimensions of the array. The dimensions of thearray are reordered so that the first dimension is @code{dimension1}, thesecond is @code{dimension2}, and so on. The arguments should be apermutation of the symbols @code{firstDim, secondDim, ...}. Note that thisis implemented by twiddling the strides of the array, and doesn't cause anydata copying. The first version returns a transposed ``view'' of the arraydata; the second version transposes the array itself.@cindex Array member functions @code{ubound()}@findex ubound()@exampleint ubound(int dimension) const;TinyVector<int,N_rank> ubound() const;@end exampleThe first version returns the upper bound of the valid index range for adimension. The second version returns a vector of upper bounds for alldimensions. The upper bound is the last valid index value. If you're usinga C-style array (the default), the ubound will be equal to the@code{extent(dimension)-1}. Fortran-style arrays will have ubound equal to@code{extent(dimension)}. The ubound can be different for each dimension.The return value of @code{ubound(dimension)} will always be equal to@code{lbound(dimension)+extent(dimension)-1}. See the note aboutdimension parameters such as @code{firstDim} in the previous section.@findex zeroOffset()@cindex Array member functions @code{zeroOffset()}@exampleint zeroOffset() const;@end exampleThis function has to do with the storage of arrays in memory. You may wantto refer to the description of the @code{data..()} member functions and ofcustom storage orders in Section @ref{Array storage} forclarification. The return value of @code{zeroOffset()} is the distance fromthe first element in the array to the (possibly nonexistant) element@code{(0,0,...,0)}. In this context, ``first element'' returns to the element@code{(base(firstDim),base(secondDim),...)}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -