libidx
ebl::idx< T > Class Template Reference

#include <idx.h>

Inheritance diagram for ebl::idx< T >:
ebl::smart_pointer ebl::idxlooper< T >

List of all members.

Public Member Functions

virtual ~idx ()
 destructor: unlocks the srg.
 idx (int n, intg *dims, intg *mods)
 idx (const idx< T > &other)
 Construct an idx from another one.
 idx (const T *mat, intg s0, intg s1)
 idx (const T *mat, intg s0, intg s1, intg s2)
 idx ()
 creates an idx0 from scratch;
 idx (intg size0)
 creates an idx1 of size size0.
 idx (intg size0, intg size1)
 creates an idx2 of size (size0,size1).
 idx (intg size0, intg size1, intg size2)
 creates an idx3 of size (size0,size1,size2).
 idx (intg s0, intg s1, intg s2, intg s3, intg s4=-1, intg s5=-1, intg s6=-1, intg s7=-1)
 creates an idx of any order.
 idx (const idxdim &d)
 creates an idx from an array of dimensions contained in an idxdim
 idx (srg< T > *srg, idxspec &s)
 generic constructor with idxspec.
 idx (srg< T > *srg, intg o, intg n, intg *dims, intg *mods)
 constructor with existing storage and array pointers for dim and mod
 idx (srg< T > *srg, intg o)
 creates an idx0 with existing srg and offset.
 idx (srg< T > *srg, intg o, intg size0)
 creates an idx1 of size size0, with existing srg and offset.
 idx (srg< T > *srg, intg o, intg size0, intg size1)
 idx (srg< T > *srg, intg o, intg size0, intg size1, intg size2)
 idx (srg< T > *srg, intg o, intg s0, intg s1, intg s2, intg s3, intg s4=-1, intg s5=-1, intg s6=-1, intg s7=-1)
 creates an idx of any order with existing srg and offset.
 idx (srg< T > *srg, intg o, const idxdim &d)
 Creates an idx with dimensions 'd' using storage 'srg' and offset 'o'.
virtual idx< T > & operator= (T other)
virtual idx< T > & operator= (const idx< T > &other)
 Copy an idx into another.
virtual idx< T > operator[] (const intg i)
virtual void add_offset (intg n)
 Adds 'n' to current offset to storage.
virtual intg setoffset (intg o)
virtual void resize (intg s0=-1, intg s1=-1, intg s2=-1, intg s3=-1, intg s4=-1, intg s5=-1, intg s6=-1, intg s7=-1)
virtual void resize (const idxdim &d)
virtual void resize1 (intg dimn, intg size)
virtual void resize_chunk (intg s_chunk, intg s0=-1, intg s1=-1, intg s2=-1, intg s3=-1, intg s4=-1, intg s5=-1, intg s6=-1, intg s7=-1)
idx< T > select (int d, intg i)
idx< T > narrow (int d, intg s, intg o)
idx< T > transpose (int d1, int d2)
idx< T > transpose (int *p)
virtual idx< T > unfold (int d, intg k, intg s)
idx< T > view_as_order (int n)
idx< T > shift_dim (int d, int pos)
virtual srg< T > * getstorage ()
 return pointer to storage
virtual intg dim (int d) const
 return size of idx in d-th dimension.
virtual const intg * dims ()
 return const ptr to dims
virtual intg mod (int d) const
 return stride of idx in d-th dimension.
virtual const intg * mods ()
 return const ptr to mods
virtual int order () const
 return order of idx (number of dimensions).
virtual intg offset ()
 return offset of idx.
virtual intg nelements () const
 return total number of elements
virtual intg footprint () const
virtual bool contiguousp () const
virtual bool same_dim (const idxdim &d)
virtual bool same_dim (intg s0, intg s1, intg s2, intg s3, intg s4, intg s5, intg s6, intg s7)
virtual idxdimget_idxdim ()
virtual idxdim get_idxdim () const
virtual T * idx_ptr ()
 return pointer on data chunk (on first element)
virtual const T * idx_ptr () const
 return pointer on data chunk (on first element), const version
virtual intg * mod_ptr ()
 Returns a pointer to the modulos array.
virtual T * ptr ()
 return a pointer to an element (idx0 version)
virtual T * ptr (intg i0)
 return a pointer to an element (idx1 version)
virtual T * ptr (intg i0, intg i1)
 return a pointer to an element (idx2 version)
virtual T * ptr (intg i0, intg i1, intg i2)
 return a pointer to an element (idx3 version)
virtual T * ptr (intg i0, intg i1, intg i2, intg i3, intg i4=-1, intg i5=-1, intg i6=-1, intg i7=-1)
 return a pointer to an element (generic version)
virtual T get () const
 return the value of an element (idx0 version)
virtual T & get (intg i0) const
 return the value of an element (idx1 version)
virtual T get (intg i0, intg i1) const
 return the value of an element (idx2 version)
virtual T get (intg i0, intg i1, intg i2) const
 return the value of an element (idx3 version)
virtual T get (intg i0, intg i1, intg i2, intg i3, intg i4=-1, intg i5=-1, intg i6=-1, intg i7=-1)
 return the value of an element (generic version)
virtual T gget (intg i0=0, intg i1=0, intg i2=0, intg i3=0, intg i4=0, intg i5=0, intg i6=0, intg i7=0)
virtual T set (T val)
 sets the value of an element (idx0 version)
virtual T set (T val, intg i0)
 sets the value of an element (idx1 version)
virtual T set (T val, intg i0, intg i1)
 sets the value of an element (idx2 version)
virtual T set (T val, intg i0, intg i1, intg i2)
 sets the value of an element (idx3 version)
virtual T set (T val, intg i0, intg i1, intg i2, intg i3, intg i4=-1, intg i5=-1, intg i6=-1, intg i7=-1)
 sets the value of an element (generic version)
virtual T sset (T val, intg i0=0, intg i1=0, intg i2=0, intg i3=0, intg i4=0, intg i5=0, intg i6=0, intg i7=0)
virtual void pretty () const
 Pretty-prints elements to a stream.
virtual void pretty (std::ostream &out) const
 Pretty-prints Idx metadata to a stream.
virtual void pretty (FILE *) const
 Pretty-prints Idx metadata to a file pointer.
virtual void print () const
 Pretty-prints elements to a stream.
virtual std::string str () const
virtual void printElems () const
virtual void printElems (std::ostream &out, bool newline=true) const
virtual void printElems (std::string &out, bool newline=true) const
virtual int fdump (std::ostream &f)
 print content of idx on stream

Public Attributes

idxspec spec
 Contains the order, offset, dimensions and strides.

Protected Member Functions

void growstorage ()
 increase size of storage to fit the current dimension
void growstorage_chunk (intg s_chunk)
 increase size of storage to fit the current dimension + a given size
template<class stream >
void printElems_impl (int indent, stream &, bool newline=true) const
 Implementation of public printElems() method.
 idx (dummyt *dummy)

Protected Attributes

srg< T > * storage
idxdimpidxdim
idxd< intg > idd

Friends

class idxiter
class idxlooper
class contiguous_idxiter
class noncontiguous_idxiter

Detailed Description

template<class T>
class ebl::idx< T >

idx: main tensor class. This can represent vectors, matrices, and tensors up to 8 dimensions. An idx is merely an access structure that points to the data. Several idx can point to the same data.


Constructor & Destructor Documentation

template<class T>
ebl::idx< T >::idx ( int  n,
intg *  dims,
intg *  mods 
)

generic constructor with dims and mods creates the storage and set offset to zero.

template<class T>
ebl::idx< T >::idx ( const T *  mat,
intg  s0,
intg  s1 
)

Allocates an idx2 of size (s0, s1) and fills it with mat, expected to be of size (s0, s1).

constructors initialized with an array

template<class T>
ebl::idx< T >::idx ( const T *  mat,
intg  s0,
intg  s1,
intg  s2 
)

Allocates an idx3 of size (s0, s1, s2) and fills it with mat, expected to be of size (s0, s1, s2).

template<class T>
ebl::idx< T >::idx ( srg< T > *  srg,
intg  o,
intg  size0,
intg  size1 
)

creates an idx2 of size (size0,size1), with existing srg and offset.

template<class T>
ebl::idx< T >::idx ( srg< T > *  srg,
intg  o,
intg  size0,
intg  size1,
intg  size2 
)

creates an idx3 of size (size0,size1,size2), with existing srg and offset.

template<class T>
ebl::idx< T >::idx ( dummyt dummy) [protected]

fake constructor that does nothing. This is called by the idxlooper constructor.


Member Function Documentation

template<class T>
virtual bool ebl::idx< T >::contiguousp ( ) const [inline, virtual]

return true if elements of idx are contiguous in memory.

template<class T>
virtual intg ebl::idx< T >::footprint ( ) const [inline, virtual]

return total footprint in the storage (index after last cell occupied in the storage)

template<class T >
idxdim & ebl::idx< T >::get_idxdim ( ) [virtual]

returns a reference to an idxdim object (owned by this idx) containing the order and dimensions of this idx.

template<class T >
idxdim ebl::idx< T >::get_idxdim ( ) const [virtual]

The 'const' version of get_idxdim(), i.e. does not modify internal members. This is less efficient in that it returns the full object and does not remember it internally. This is useful when dealing with a const idx, i.e. where members cannot be modified.

template<class T>
virtual srg<T>* ebl::idx< T >::getstorage ( ) [inline, virtual]

return pointer to storage

field access methods

template<class T >
T ebl::idx< T >::gget ( intg  i0 = 0,
intg  i1 = 0,
intg  i2 = 0,
intg  i3 = 0,
intg  i4 = 0,
intg  i5 = 0,
intg  i6 = 0,
intg  i7 = 0 
) [virtual]

Returns the value of an element (generic version). The difference with other 'get' methods is that the user can specify a different number of arguments than the order of the idx. All remaining dimensions will be assumed to have offset 0 or none if the dimension does not exist. This is useful when one does not know in advance the order of the idx but only needs to access some elements while remaining offsets are 0.

template<class T >
idx< T > ebl::idx< T >::narrow ( int  d,
intg  s,
intg  o 
)

narrow: return a new idx in which the d-th dimension has been reduced to size s, starting at item o. In other words, if m is an idx of order 2 of size (10,4), the call idx p = m.narrow(0,6,2) will set p to an idx or order 2 of size (6,4) whose rows are rows 2 to 7 of m.

Reimplemented in ebl::midx< T >.

template<class T >
idx< T > ebl::idx< T >::operator[] ( const intg  i) [virtual]

Return an idx that is the 'i'th slice in dimensions 0. Equivalent to select(0, i).

template<class T >
void ebl::idx< T >::pretty ( ) const [virtual]

Pretty-prints elements to a stream.

Pretty-prints Idx metadata to std::cout.

Reimplemented in ebl::midx< T >.

template<class T >
void ebl::idx< T >::resize ( const idxdim d) [virtual]

resize an idx with dimensions contained in an idxdim. The order is not allowed to change. As in realloc(), the content will be unchanged to the minimum of the old and new sizes.

template<class T >
void ebl::idx< T >::resize ( intg  s0 = -1,
intg  s1 = -1,
intg  s2 = -1,
intg  s3 = -1,
intg  s4 = -1,
intg  s5 = -1,
intg  s6 = -1,
intg  s7 = -1 
) [virtual]

resize an idx. The order (ndim) is not allowed to change. This is to prevent nasty bugs. As in realloc(), the content will be unchanged to the minimum of the old and new sizes.

template<class T >
void ebl::idx< T >::resize1 ( intg  dimn,
intg  size 
) [virtual]

resize 1 dimension of an idx. The order is not allowed to change. As in realloc(), the content will be unchanged to the minimum of the old and new sizes.

template<class T >
void ebl::idx< T >::resize_chunk ( intg  s_chunk,
intg  s0 = -1,
intg  s1 = -1,
intg  s2 = -1,
intg  s3 = -1,
intg  s4 = -1,
intg  s5 = -1,
intg  s6 = -1,
intg  s7 = -1 
) [virtual]

same as resize, but the storage is enlarged by a step of s_chunk if needed. As in realloc(), the content will be unchanged to the minimum of the old and new sizes.

template<class T >
bool ebl::idx< T >::same_dim ( intg  s0,
intg  s1,
intg  s2,
intg  s3,
intg  s4,
intg  s5,
intg  s6,
intg  s7 
) [virtual]

return true if this idx has same order and dimensions s0 .. s7 i.e. if all their dimensions are equal (regardless of strides).

template<class T >
bool ebl::idx< T >::same_dim ( const idxdim d) [virtual]

return element if this is an idx0, otherwise generate an error return true if this idx has same order and dimensions as idxdim d. i.e. if all their dimensions are equal (regardless of strides).

template<class T >
idx< T > ebl::idx< T >::select ( int  d,
intg  i 
)

Returns a new idx corresponding to a slice of the current idx with slice i in dimension d. In other words, if m is an idx of order 2 of size (10,4), the call idx p = m.select(0,3) will set p to an idx or order 1 containing the 4-th row of m.

Reimplemented in ebl::midx< T >.

template<class T >
intg ebl::idx< T >::setoffset ( intg  o) [virtual]

change the offset of an idx. The Storage is resized accordingly. Returns the new offset.

template<class T >
idx< T > ebl::idx< T >::shift_dim ( int  d,
int  pos 
)

Return an new idx in which dimension d is shifted to position pos, keeping the ordering of other dimensions. For example, if m is an idx of size (2,4,6), m.shift_dim(2, 0); returns an idx of size (6,2,4). No data is actually moved around, this merely manipulates the idx structure itself.

template<class T>
T ebl::idx< T >::sset ( val,
intg  i0 = 0,
intg  i1 = 0,
intg  i2 = 0,
intg  i3 = 0,
intg  i4 = 0,
intg  i5 = 0,
intg  i6 = 0,
intg  i7 = 0 
) [virtual]

Sets the value of an element (generic version). The difference with other 'set' methods is that the user can specify a different number of arguments than the order of the idx. All remaining dimensions will be assumed to have offset 0 or none if the dimension does not exist. This is useful when one does not know in advance the order of the idx but only needs to access some elements while remaining offsets are 0.

template<class T >
idx< T > ebl::idx< T >::transpose ( int  d1,
int  d2 
)

Return an new idx in which dimensions d1 and d2 are transposed. No data is actually moved around, this merely manipulates the idx structure itself.

template<class T >
idx< T > ebl::idx< T >::transpose ( int *  p)

Return an new idx in which the dimensions are permuted using the permutation vector p. For example, if m is an idx of size (2,4,6), int p[] = {1,2,0}; m.transpose(p); returns an idx of size (4,6,2). No data is actually moved around, this merely manipulates the idx structure itself.

template<class T >
idx< T > ebl::idx< T >::unfold ( int  d,
intg  k,
intg  s 
) [virtual]

Return a new idx prepared for a convolution. Returns an idx on the same storage as m (pointing to the same data) with an added dimension at the end obtained by "unfolding" the n -th dimension. The size of the new dimension is k. This essentially manipulates the mod array to make convolutions look like matrix-vector multiplies.

template<class T >
idx< T > ebl::idx< T >::view_as_order ( int  n)

Returns a new idx with an order n (the data must be contiguous, this will raise an exception otherwise). if n == 1, the data is viewed as a 1D idx, regardless of its current order. if n > 1 and n > current order, then extra dimensions of size 1 are added. if n > 1 and n < current order, this is undefined, an error is raised. if n == current order, an identical idx is returned.


Member Data Documentation

template<class T>
idxdim* ebl::idx< T >::pidxdim [protected]

A pointer to a dimensions descriptor. this is allocated when get_idxdim() method is called and destroyed by destructor.

template<class T>
srg<T>* ebl::idx< T >::storage [protected]

Pointer to the srg structure that contains the data.


The documentation for this class was generated from the following files: