25 #include <Base/Common/W32Compat.hh>
27 #include "Tensor3D.hh"
34 : _Data(NULL), _DataArray(NULL), _Dim1(0), _Dim2(0), _Dim3(0)
40 : _Data(NULL), _DataArray(NULL), _Dim1(0), _Dim2(0), _Dim3(0)
65 if (i!=_Dim1 || j!=_Dim2 || k!=_Dim3){
74 int xyPlaneSize=_Dim1*_Dim2;
75 _DataArray=
new T**[_Dim3];
76 for (
int z=0; z<_Dim3; z++){
77 _DataArray[z]=
new T*[_Dim2];
78 for (
int y=0; y<_Dim2; y++){
79 _DataArray[z][y]=_Data+z*xyPlaneSize+y*_Dim1;
84 for (
int m=0; m<_Size; m++){
92 if (_Data) {
delete[] _Data; _Data=NULL; }
94 for (
int z=0; z<_Dim3; z++){
95 delete[] _DataArray[z]; _DataArray[z]=NULL;
97 delete[] _DataArray; _DataArray=NULL;
126 memset((
void *)_Data, 0,
sizeof(T)*_Size);
133 memcpy((
void *)_Data, (
void *)t.
GetData(), _Size*
sizeof(T));
140 if ( t.
GetDim1() != GetDim1() ||
142 t.
GetDim3() != GetDim3() )
return false;
143 for(
int i=0; i<(GetDim1()*GetDim2()*GetDim3()) ; i++)
144 if ( t.
GetData()[i]!=_Data[i] )
return false;
152 int rows = GetDim1()*GetDim2()*GetDim3();
155 for(
int i=0; i<GetDim1(); i++)
156 for(
int j=0; j<GetDim2(); j++)
157 for(
int k=0; k<GetDim3(); k++)
158 result[i*GetDim1()*GetDim2() + j*GetDim2() + k] = _DataArray[i][j][k];
167 BIASASSERT( (
int)v.
Size() >= GetDim1()*GetDim2()*GetDim3() );
169 for(
int i=0; i<GetDim1(); i++)
170 for(
int j=0; j<GetDim2(); j++)
171 for(
int k=0; k<GetDim3(); k++)
172 _DataArray[i][j][k] = v[i*GetDim1()*GetDim2() + j*GetDim2() + k];
179 for(
int i=0; i<_Size; i++)
180 _Data[i] = _Data[i] * factor;
188 for(
int i=0; i<_Size; i++)
189 Length += _Data[i] * _Data[i];
196 template class BIASMathBase_EXPORT BIAS::Tensor3D<type>;\
bool operator==(const Tensor3D< T > &t)
checks if all tensor entries are equal (up-to-scale-equality is not checked)
Tensor3D< T > & operator=(const Tensor3D< T > &t)
class for column vectors with arbitrary size
BIAS::Vector< T > ToVector()
void SetFromVector(const BIAS::Vector< T > &v)
set the tensor by the rows of the vector.
void Destroy()
frees internal data
unsigned int Size() const
length of the vector
void NewSize(const int i, const int j, const int k, const T &def=(T) 0.0)
allocates internal data
void SetZero()
set all elements to zero