jplus-0.4.7
jarray_of_type< T > Class Template Reference

Typed variant of jarray, performs automatic type conversion on instantiation. More...

#include <src/jarray.h>

Inheritance diagram for jarray_of_type< T >:
Collaboration diagram for jarray_of_type< T >:

Public Member Functions

 jarray_of_type (const jarray &ja)
 Initialize with type conversion.
 
Toperator[] (const I i)
 Directly access element of ravel.
 
const Toperator[] (const I i) const
 Direct read-only access to an element of ravel.
 
 jarray_of_type (jengine *je_)
 Conveniently allocate scalar.
 
 jarray_of_type (jengine *je_, const I l0)
 Conveniently allocate 1-D array.
 
Toperator() (const I i0)
 conveniently access 1-D array.
 
const Toperator() (const I i0) const
 Convenient read-only access to 1-D array.
 
 jarray_of_type (jengine *je_, const I l0, const I l1)
 Conveniently allocate 2-D array.
 
Toperator() (const I i0, const I i1)
 Conveniently access 2-D array.
 
const Toperator() (const I i0, const I i1) const
 Convenient read-only access to 2-D array.
 
 jarray_of_type (jengine *je_, const I l0, const I l1, const I l2)
 Conveniently allocate 3-D array.
 
Toperator() (const I i0, const I i1, const I i2)
 Conveniently access 3-D array.
 
const Toperator() (const I i0, const I i1, const I i2) const
 Convenient read-only access to 3-D array.
 
 jarray_of_type (jengine *je_, const I l0, const I l1, const I l2, const I l3)
 Conveniently allocate 4-D array.
 
Toperator() (const I i0, const I i1, const I i2, const I i3)
 Conveniently access 4-D array.
 
const Toperator() (const I i0, const I i1, const I i2, const I i3) const
 Convenient read-only access to 4-D array.
 
 jarray_of_type (jengine *je_, const I l0, const I l1, const I l2, const I l3, const I l4)
 Conveniently allocate 5-D array.
 
Toperator() (const I i0, const I i1, const I i2, const I i3, const I i4)
 Conveniently access 5-D array.
 
const Toperator() (const I i0, const I i1, const I i2, const I i3, const I i4) const
 Convenient read-only access to 5-D array.
 
 jarray_of_type (jengine *je_, const I rank, const I *shape)
 Conveniently allocate n-D array.
 
 jarray_of_type (jengine *je_, const std::vector< I > &shape)
 Conveniently allocate n-D array.
 
Toperator() (const std::vector< I > &subscripts)
 Conveniently access n-D array.
 
const Toperator() (const std::vector< I > &subscripts) const
 Convenient read-only access to n-D array.
 
Toperator() (const I *subscripts)
 Conveniently access n-D array.
 
const Toperator() (const I *subscripts) const
 Convenient read-only access to n-D array.
 
- Public Member Functions inherited from jarray
I getRefcount () const
 returns the array refcount
 
template<class T >
int get (T &v, const int i) const
 Obtains the value of a specified element of ravel.
 
template<class T >
int set (const int i, const T v)
 Assigns the value of the specified element of ravel.
 
template<class T >
int get (std::vector< T > &v) const
 Fits ravel of the array into the specified STL vector.
 
template<class T >
int get (T &v)
 Attempts to fit the whole array into the specified type.
 
 jarray ()
 Invalid array, a valid array can be assigned to it.
 
 jarray (jengine *je_, std::istream &in)
 Loads the array from binary representation in a stream.
 
jarray::I esize () const
 Size (in bytes) of the single element of this array.
 
void addhash (SHA1 &sha)
 Add this array (both shape and values) to the hash.
 
bool write (std::ostream &out)
 Writes binary representation of this array into the specified output stream.
 
bool isValid () const
 Returns true if the array is valid.
 
const I type () const
 Returns array type.
 
const I rank () const
 Rank (dimensionality) of the array.
 
Ishape () const
 Returns pointer to the first element of the shape.
 
int extent (int dimension) const
 Returns the extent of the specified dimension, element of shape.
 
void shape (std::vector< I > &shape) const
 Copies array shape into STL vector.
 
const int size () const
 Number of elements in ravel.
 
Idata () const
 Returns pointer to the beginning of the array data.
 
jenginegetEngine () const
 Returns pointer to jengine, managing memory of this array.
 
 jarray (jengine *je_, void *hdr_)
 Instantiates on top of an existing J array.
 
 jarray (jengine *je_, elementType type, I rank, I *shape)
 Creates new multidimensional array of the given J type.
 
 jarray (jengine *je_, elementType type, const std::vector< I > &shape)
 Creates new multidimensional array of the given J type.
 
 jarray (jengine *je_, const std::string &str)
 Creates T_LIT vector from C++ string.
 
 jarray (const jarray &other)
 Makes a copy of another array (increments refcount).
 
jarrayassign (const jarray &other)
 Assigns another array to this one (increments refcount and frees memory, if necessary)
 
jarrayoperator= (const jarray &other)
 Shortcut to assign.
 
bool operator== (const jarray &rhs) const
 Performs by-element comparison and return true if two arrays are the same.
 
 ~jarray ()
 Decrements refcount, frees array memory, if necessary.
 

Additional Inherited Members

- Public Types inherited from jarray
enum  errorType { ERR_CONV =10 , ERR_SHAPE =11 }
 error codes More...
 
enum  elementType {
  T_B01 =1 , T_LIT =2 , T_INT =4 , T_FL =8 ,
  T_CMPX =16
}
 Constants for possible array element types. More...
 
typedef char B
 byte type, equivalent to J
 
typedef char C
 literal type, equivalent to J
 
typedef short S
 short int type, equivalent to J
 
typedef long I
 integer type, equivalent to J
 
typedef double D
 floating point type, equivalent to J
 
- Static Public Member Functions inherited from jarray
static jarray::I esize (elementType type)
 Size (in bytes) of the particular data type.
 
- Protected Member Functions inherited from jarray
bool allocate (jengine *je_, elementType type, const I rank, const I *shape)
 Allocates new array in memory.
 
void grab () const
 Increments refcount.
 
void release ()
 Decrements refcount and frees memory, if necessary.
 
I getHeader (bool give_up_ownership=true) const
 
- Protected Attributes inherited from jarray
headerhdr
 Pointer to the array header, NULL for invalid array.
 
jengineje
 Pointer to jengine, managing the memory of this array.
 

Detailed Description

template<class T>
class jarray_of_type< T >

Typed variant of jarray, performs automatic type conversion on instantiation.

Constructor & Destructor Documentation

◆ jarray_of_type() [1/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( const jarray ja)
inline

Initialize with type conversion.

In case no conversion is needed the original array is accessed directly, otherwise a copy is made. To access the array members (subscripting) round backets are used like in Blitz++ and not the square ones, like in Boost. Convenience methods are provided for ranks up to 5, for bigger ranks one has to construct and use for indexing an integer vector.

Parameters
jajarray, holding the data.

References jarray::allocate(), jarray::assign(), jarray::get(), jarray::getEngine(), jarray::rank(), jarray::set(), jarray::shape(), jarray::size(), and jarray::type().

◆ jarray_of_type() [2/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_)
inline

Conveniently allocate scalar.

Parameters
je_jengine to manage memory of this array.

References jarray::allocate(), and jarray::shape().

◆ jarray_of_type() [3/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_,
const I  l0 
)
inline

Conveniently allocate 1-D array.

Parameters
je_jengine to manage memory of this array.
l0new array dimension

References jarray::allocate(), and jarray::shape().

◆ jarray_of_type() [4/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_,
const I  l0,
const I  l1 
)
inline

Conveniently allocate 2-D array.

Parameters
je_jengine to manage memory of this array.
l0new array 1-st dimension
l1new array 2-nd dimension

References jarray::allocate(), and jarray::shape().

◆ jarray_of_type() [5/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_,
const I  l0,
const I  l1,
const I  l2 
)
inline

Conveniently allocate 3-D array.

Parameters
je_jengine to manage memory of this array.
l0new array 1-st dimension
l1new array 2-nd dimension
l2new array 3-rd dimension

References jarray::allocate(), and jarray::shape().

◆ jarray_of_type() [6/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_,
const I  l0,
const I  l1,
const I  l2,
const I  l3 
)
inline

Conveniently allocate 4-D array.

Parameters
je_jengine to manage memory of this array.
l0new array 1-st dimension
l1new array 2-nd dimension
l2new array 3-rd dimension
l3new array 4-th dimension

References jarray::allocate(), and jarray::shape().

◆ jarray_of_type() [7/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_,
const I  l0,
const I  l1,
const I  l2,
const I  l3,
const I  l4 
)
inline

Conveniently allocate 5-D array.

Parameters
je_jengine to manage memory of this array.
l0new array 1-st dimension
l1new array 2-nd dimension
l2new array 3-rd dimension
l3new array 4-th dimension
l4new array 5-th dimension

References jarray::allocate(), and jarray::shape().

◆ jarray_of_type() [8/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_,
const I  rank,
const I shape 
)
inline

Conveniently allocate n-D array.

Parameters
je_jengine to manage memory of this array.
rankrank of new array.
shapeshape of new array.

References jarray::allocate(), jarray::rank(), and jarray::shape().

◆ jarray_of_type() [9/9]

template<class T >
jarray_of_type< T >::jarray_of_type ( jengine je_,
const std::vector< I > &  shape 
)
inline

Conveniently allocate n-D array.

Parameters
je_jengine to manage memory of this array.
shapeshape of new array.

References jarray::allocate(), and jarray::shape().

Member Function Documentation

◆ operator()() [1/14]

template<class T >
T & jarray_of_type< T >::operator() ( const I subscripts)
inline

Conveniently access n-D array.

Be careful, allocating enough subscripts.

Parameters
subscriptssubscripts of the element to access.
Returns
reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [2/14]

template<class T >
const T & jarray_of_type< T >::operator() ( const I subscripts) const
inline

Convenient read-only access to n-D array.

Be careful, allocating enough subscripts.

Parameters
subscriptssubscripts of the element to access.
Returns
const reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [3/14]

template<class T >
T & jarray_of_type< T >::operator() ( const I  i0)
inline

conveniently access 1-D array.

Parameters
i0zero-based index of the element to access.
Returns
reference to the element.

References jarray::data(), and jarray::rank().

◆ operator()() [4/14]

template<class T >
const T & jarray_of_type< T >::operator() ( const I  i0) const
inline

Convenient read-only access to 1-D array.

Parameters
i0zero-based index of the element to access.
Returns
const reference to the element.

References jarray::data(), and jarray::rank().

◆ operator()() [5/14]

template<class T >
T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1 
)
inline

Conveniently access 2-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
Returns
reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [6/14]

template<class T >
const T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1 
) const
inline

Convenient read-only access to 2-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
Returns
const reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [7/14]

template<class T >
T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1,
const I  i2 
)
inline

Conveniently access 3-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
i2zero-based 3-rd index of the element to access.
Returns
reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [8/14]

template<class T >
const T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1,
const I  i2 
) const
inline

Convenient read-only access to 3-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
i2zero-based 3-rd index of the element to access.
Returns
const reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [9/14]

template<class T >
T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1,
const I  i2,
const I  i3 
)
inline

Conveniently access 4-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
i2zero-based 3-rd index of the element to access.
i3zero-based 4-th index of the element to access.
Returns
reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [10/14]

template<class T >
const T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1,
const I  i2,
const I  i3 
) const
inline

Convenient read-only access to 4-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
i2zero-based 3-rd index of the element to access.
i3zero-based 4-th index of the element to access.
Returns
const reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [11/14]

template<class T >
T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1,
const I  i2,
const I  i3,
const I  i4 
)
inline

Conveniently access 5-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
i2zero-based 3-rd index of the element to access.
i3zero-based 4-th index of the element to access.
i4zero-based 5-th index of the element to access.
Returns
reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [12/14]

template<class T >
const T & jarray_of_type< T >::operator() ( const I  i0,
const I  i1,
const I  i2,
const I  i3,
const I  i4 
) const
inline

Convenient read-only access to 5-D array.

Parameters
i0zero-based 1-st index of the element to access.
i1zero-based 2-nd index of the element to access.
i2zero-based 3-rd index of the element to access.
i3zero-based 4-th index of the element to access.
i4zero-based 5-th index of the element to access.
Returns
const reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [13/14]

template<class T >
T & jarray_of_type< T >::operator() ( const std::vector< I > &  subscripts)
inline

Conveniently access n-D array.

Parameters
subscriptssubscripts of the element to access.
Returns
reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator()() [14/14]

template<class T >
const T & jarray_of_type< T >::operator() ( const std::vector< I > &  subscripts) const
inline

Convenient read-only access to n-D array.

Parameters
subscriptssubscripts of the element to access.
Returns
const reference to the element.

References jarray::data(), jarray::extent(), and jarray::rank().

◆ operator[]() [1/2]

template<class T >
T & jarray_of_type< T >::operator[] ( const I  i)
inline

Directly access element of ravel.

Parameters
iindex.
Returns
reference to the element.

References jarray::data().

◆ operator[]() [2/2]

template<class T >
const T & jarray_of_type< T >::operator[] ( const I  i) const
inline

Direct read-only access to an element of ravel.

Parameters
iindex.
Returns
constant reference to the element.

References jarray::data().


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