|
PLearn 0.1
|
#include <Tensor.h>

Public Types | |
| typedef TTensorElementIterator< T > | iterator |
| typedef TTensorSubTensorIterator< T > | subTensorIterator |
Public Member Functions | |
| TTensor () | |
| TTensor (IVec len) | |
| TTensor (const IVec &len, const T &init_value) | |
| int | resize (const IVec &len) |
| don't call this from a subTensor !! | |
| int | ndims () const |
| IVec | width () const |
| IVec | sizes () const |
| int | size (int k) const |
| int | totalElements () const |
| int | linearIndex (const IVec &pos) const |
| int | linearIndex (const vector< int > &pos) const |
| TTensor< T > | subTensor (const IVec &from, const IVec &len) |
| TTensor< T > | DEPRECATEDsubTensor (const IVec &from, const IVec &len, bool throw_useless_dimensions=true) |
| TTensor< T > | operator[] (int i) |
| void | selectDimensions (const IVec &dim) |
| T & | operator() (const IVec &pos) const |
| T & | operator() (const vector< int > &pos) const |
| void | fill (const T &val) |
| T * | data () const |
| IVec | lastElementPos () const |
| iterator | begin () |
| returns an iterator over elements | |
| iterator | end () |
| subTensorIterator | getSubTensorIterator (const IVec &v) |
| returns an iterator over subTensors | |
Protected Attributes | |
| int | offset_ |
| IVec | stride_ |
| IVec | width_ |
| PP< Storage< T > > | storage |
Friends | |
| class | TTensorElementIterator< T > |
| class | TTensorSubTensorIterator< T > |
| typedef TTensorElementIterator<T> PLearn::TTensor< T >::iterator |
| typedef TTensorSubTensorIterator<T> PLearn::TTensor< T >::subTensorIterator |
| PLearn::TTensor< T >::TTensor | ( | ) | [inline] |
| PLearn::TTensor< T >::TTensor | ( | IVec | len | ) | [inline] |
Definition at line 196 of file Tensor.h.
References i, j, and PLearn::TTensor< T >::resize().
:offset_(0), stride_(0), width_(len) { stride_.resize(len.size()); for(int i=0;i<ndims();i++) { stride_[i]=1; for(int j=i-1;j>=0;j--) stride_[i]*=len[j]; } storage = new Storage<T>(totalElements()); }

| PLearn::TTensor< T >::TTensor | ( | const IVec & | len, |
| const T & | init_value | ||
| ) | [inline] |
Definition at line 209 of file Tensor.h.
References i, j, and PLearn::TTensor< T >::resize().
:offset_(0), stride_(0), width_(len) { stride_.resize(len.size()); for(int i=0;i<ndims();i++) { stride_[i]=1; for(int j=i-1;j>=0;j--) stride_[i]*=len[j]; } storage = new Storage<T>(totalElements()); fill(init_value); }

| iterator PLearn::TTensor< T >::begin | ( | ) | [inline] |
| T* PLearn::TTensor< T >::data | ( | ) | const [inline] |
| TTensor<T> PLearn::TTensor< T >::DEPRECATEDsubTensor | ( | const IVec & | from, |
| const IVec & | len, | ||
| bool | throw_useless_dimensions = true |
||
| ) | [inline] |
Definition at line 305 of file Tensor.h.
References PLearn::TinyVector< T, N, TTrait >::empty(), i, PLearn::TTensor< T >::offset_, PLERROR, PLearn::TinyVector< T, N, TTrait >::push_back(), PLearn::TTensor< T >::selectDimensions(), and PLearn::TTensor< T >::width_.
{
TTensor<T> subt = *this;
subt.width_ = len;
subt.offset_ = linearIndex(from);
IVec idx;
for(int i=0;i<ndims();i++)
{
if(from[i]<0 || from[i]+len[i]>width_[i] || len[i]<0)
PLERROR("TTensor::subTensor : at index %i : from, len, width = %i %i %i",i,from[i],len[i],width_[i]);
if(len[i]>1 || !throw_useless_dimensions)
idx.push_back(i);
}
// if idx is empty, it is because all lengths are 1 since a single element was selected,
// so we need to create a single dimension.
if(idx.empty())
idx.push_back(0);
subt.selectDimensions(idx);
return subt;
}

| iterator PLearn::TTensor< T >::end | ( | ) | [inline] |
Definition at line 389 of file Tensor.h.
{
return iterator(this,lastElementPos());
}
| void PLearn::TTensor< T >::fill | ( | const T & | val | ) | [inline] |
| subTensorIterator PLearn::TTensor< T >::getSubTensorIterator | ( | const IVec & | v | ) | [inline] |
returns an iterator over subTensors
Definition at line 395 of file Tensor.h.
{
return subTensorIterator(this, v);
}
| IVec PLearn::TTensor< T >::lastElementPos | ( | ) | const [inline] |
| int PLearn::TTensor< T >::linearIndex | ( | const IVec & | pos | ) | const [inline] |
| int PLearn::TTensor< T >::linearIndex | ( | const vector< int > & | pos | ) | const [inline] |
| int PLearn::TTensor< T >::ndims | ( | ) | const [inline] |
| T& PLearn::TTensor< T >::operator() | ( | const IVec & | pos | ) | const [inline] |
Definition at line 353 of file Tensor.h.
{return (*storage)[linearIndex(pos)];}
| T& PLearn::TTensor< T >::operator() | ( | const vector< int > & | pos | ) | const [inline] |
Definition at line 354 of file Tensor.h.
{return (*storage)[linearIndex(pos)];}
| TTensor<T> PLearn::TTensor< T >::operator[] | ( | int | i | ) | [inline] |
Definition at line 327 of file Tensor.h.
References PLearn::TinyVector< T, N, TTrait >::push_back().
{
IVec from;
IVec len;
from.push_back(i);
len.push_back(0);
for(int k=1; k<ndims(); k++)
{
from.push_back(0);
len.push_back(size(k));
}
return subTensor(from,len);
}

| int PLearn::TTensor< T >::resize | ( | const IVec & | len | ) | [inline] |
don't call this from a subTensor !!
Definition at line 224 of file Tensor.h.
References i, j, PLearn::TinyVector< T, N, TTrait >::resize(), and PLearn::TinyVector< T, N, TTrait >::size().
Referenced by PLearn::TTensor< T >::TTensor().
{
width_=len;
stride_.resize(len.size());
for(int i=0;i<ndims();i++)
{
stride_[i]=1;
for(int j=i-1;j>=0;j--)
stride_[i]*=len[j];
}
storage = new Storage<T>(totalElements());
offset_=0;
}


| void PLearn::TTensor< T >::selectDimensions | ( | const IVec & | dim | ) | [inline] |
Definition at line 341 of file Tensor.h.
References i, PLearn::TinyVector< T, N, TTrait >::push_back(), and PLearn::TinyVector< T, N, TTrait >::size().
Referenced by PLearn::TTensor< T >::DEPRECATEDsubTensor(), and PLearn::TTensor< T >::subTensor().
{
IVec newwidth,newstride;
for(int i=0;i<(signed)dim.size();i++)
{
newwidth.push_back(width_[dim[i]]);
newstride.push_back(stride_[dim[i]]);
}
stride_=newstride;
width_=newwidth;
}


| int PLearn::TTensor< T >::size | ( | int | k | ) | const [inline] |
| IVec PLearn::TTensor< T >::sizes | ( | ) | const [inline] |
| TTensor<T> PLearn::TTensor< T >::subTensor | ( | const IVec & | from, |
| const IVec & | len | ||
| ) | [inline] |
Definition at line 274 of file Tensor.h.
References PLearn::TinyVector< T, N, TTrait >::empty(), i, PLearn::TTensor< T >::offset_, PLERROR, PLearn::TinyVector< T, N, TTrait >::push_back(), PLearn::TTensor< T >::selectDimensions(), and PLearn::TTensor< T >::width_.
{
TTensor<T> subt = *this;
subt.width_ = len;
subt.offset_ = linearIndex(from);
IVec idx;
for(int i=0;i<ndims();i++)
{
if(from[i]<0 || from[i]+len[i]>width_[i] || len[i]<0)
PLERROR("TTensor::subTensor : at index %i : from, len, width = %i %i %i",i,from[i],len[i],width_[i]);
if(len[i]>0) // skip the 0 dimensions
idx.push_back(i);
}
// if idx is empty, it is because all lengths are 0: we have a scalar
if(idx.empty())
idx.push_back(0);
subt.selectDimensions(idx);
return subt;
}

| int PLearn::TTensor< T >::totalElements | ( | ) | const [inline] |
| IVec PLearn::TTensor< T >::width | ( | ) | const [inline] |
friend class TTensorElementIterator< T > [friend] |
friend class TTensorSubTensorIterator< T > [friend] |
int PLearn::TTensor< T >::offset_ [protected] |
the displacement to do with respect to storage->data
Definition at line 183 of file Tensor.h.
Referenced by PLearn::TTensor< T >::DEPRECATEDsubTensor(), and PLearn::TTensor< T >::subTensor().
PP< Storage<T> > PLearn::TTensor< T >::storage [protected] |
IVec PLearn::TTensor< T >::stride_ [protected] |
IVec PLearn::TTensor< T >::width_ [protected] |
the actual widths of each dimensions of the tensor
Definition at line 185 of file Tensor.h.
Referenced by PLearn::TTensor< T >::DEPRECATEDsubTensor(), and PLearn::TTensor< T >::subTensor().
1.7.4