CUDA
C/C++    Fortran   

dim4 Class Reference

array dimensions descriptor More...

#include <dims.h>

Public Member Functions

 dim4 ()
 dim4 (unsigned x, unsigned y=1, unsigned z=1, unsigned w=1)
 If only x is specified, constructs column vector.
 dim4 (unsigned ndims, const unsigned *dims)
 dim4 (const dim4 &)
unsigned elements () const
 Number of elements (product of dimensions)
unsigned rest (unsigned i) const
 Product of dimensions i on.
unsigned numdims () const
 Number of dimensions set.
const unsigned * dims () const
 Access underlying array.
bool isempty () const
 Is empty array?
bool isscalar () const
 Is scalar array (one element)?
bool isvector () const
 Is array vector (row or column or scalar)?
bool iscolumn () const
 Is column vector?
bool isrow () const
 Is row vector?
unsigned & operator[] (unsigned)
 Get specified dimension.
unsigned operator[] (unsigned) const
 Get specified dimension.
bool operator== (const dim4 &) const
 Check is dimensions are equal.
bool operator!= (const dim4 &) const
 Check is dimensions are equal.
dim4operator= (const dim4 &)
 Copy constructor.

Friends

std::ostream & operator<< (std::ostream &, const dim4 &)
 Prints dimensions.

Detailed Description


Constructor & Destructor Documentation

dim4 ( )
dim4 ( unsigned  x,
unsigned  y = 1,
unsigned  z = 1,
unsigned  w = 1 
)

If only x is specified, constructs column vector.

dim4 ( unsigned  ndims,
const unsigned *  dims 
)
dim4 ( const dim4 )

Member Function Documentation

unsigned elements ( ) const

Number of elements (product of dimensions)

           array a = constant(0,5,5,5);
           cout << a.dims().elements() << endl;
           //Returns 125 (5x5x5)
unsigned rest ( unsigned  i) const

Product of dimensions i on.

           array a = constant(0,4,5,6);
           cout << a.dims().rest(1) << endl;
           //Returns 30 (5x6), dimension 1 on
unsigned numdims ( ) const

Number of dimensions set.

           array a = constant(0,4,5,6);
           cout << a.dims().numdims() << endl;
           //Returns 3
const unsigned* dims ( ) const

Access underlying array.

           dim4 dims(4,2);
           const unsigned *d = dims.dims();
           cout << dims[0] << " " << dims[1] << " " << dims[2] << " " << dims[3] << endl;
           //Prints "4 2 1 1"
bool isempty ( ) const [inline]

Is empty array?

           dim4 d(0);

           //returns true
           return d.isempty();
bool isscalar ( ) const [inline]

Is scalar array (one element)?

           dims4 d(1);

           //returns true
           return d.iscalar();
bool isvector ( ) const [inline]

Is array vector (row or column or scalar)?

           dim4 c(20);
           dim4 r(1,20);

           return c.isvector() && r.isvector(); //returns true
bool iscolumn ( ) const [inline]

Is column vector?

           dim4 c(20);

           return c.iscolumn(); //returns true
bool isrow ( ) const [inline]

Is row vector?

           dim4 r(1,20);

           return r.isrow(); //returns true
unsigned& operator[] ( unsigned  )

Get specified dimension.

           dim4 d(4,5,6,7);

           unsigned& w = d[3]; // w = 7
unsigned operator[] ( unsigned  ) const

Get specified dimension.

           dim4 d(4,5,6,7);

           const unsigned w = d[3]; // w = 7
bool operator== ( const dim4 ) const

Check is dimensions are equal.

           dim4 a(4,5);
           dim4 b(4,5);
bool operator!= ( const dim4 ) const

Check is dimensions are equal.

           dim4 a(4,5);
           dim4 b(4,5);
dim4& operator= ( const dim4 )

Copy constructor.

           dim4 d(4,5,2);
           dim4 e(2,1,1);

           e = d;
           cout << e[0] << endl;
           //prints 4

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  ,
const dim4  
) [friend]

Prints dimensions.

           dim4 d(4,5);

           cout << d << endl;
           //prints {4,5}

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