1 #ifndef array2dmatrix_h 2 #define array2dmatrix_h 37 sz1<1?(sz0<1?1:sz0):sz1) { setAll(); }
44 inline Array2DMatrix& operator =(
const Array2DMatrix& oth )
45 {
return a2d_ = oth.
a2d_; }
47 {
return a2d_ = a2d; }
49 {
return a2d_ = a2d; }
51 {
return isEq( oth.
a2d_, fT(1e-6)) ; }
52 inline bool isEq(
const Array2D<fT>&,fT eps=fT(1e-6))
const;
54 inline int size(
bool dim1=
false)
const;
55 inline void set(
int i0,
int i1, fT v ) { a2d_.set(i0,i1,v); }
56 inline fT&
get(
int i0,
int i1);
57 inline fT
get(
int i0,
int i1 )
const {
return a2d_.get(i0,i1); }
59 inline void setAll( fT v=fT(0) ) { a2d_.setAll( v ); }
60 inline void setDiagonal(fT);
64 inline void add(
const Array2DMatrix&);
65 inline void multiply(fT);
66 inline void multiply(
const Array2DMatrix&);
67 inline void transpose();
69 inline void getSum(
const Array2DMatrix&,Array2DMatrix&)
const;
71 inline void getProduct(
const Array2DMatrix&,Array2DMatrix&)
const;
72 inline void getTransposed(Array2DMatrix&);
73 inline bool getCholesky(Array2DMatrix&)
const;
81 #define mDefineA2DMatSizes(m,nm) \ 82 const int nm##0 = (m).size( false ); const int nm##1 = (m).size( true ) 88 return a2d_.info().getSize( dim1 ? 1 : 0 );
95 const od_int64 offset = a2d_.info().getOffset( i0, i1 );
96 return a2d_.getData()[offset];
100 #define mDefineImplA2DMatSizes mDefineA2DMatSizes(*this,sz) 107 if ( a2d_.info().getSize(0) != sz0 || a2d_.info().getSize(1) != sz1 )
110 for (
int idx0=0; idx0<sz0; idx0++ )
112 for (
int idx1=0; idx1<sz1; idx1++ )
114 if ( !
isFPEqual(
get(idx0,idx1), a2d.
get(idx0,idx1), eps ) )
126 const int sz = sz0 > sz1 ? sz1 : sz0;
128 for (
int idx=0; idx<sz; idx++ )
137 for (
int idx0=0; idx0<sz0; idx0++ )
138 for (
int idx1=0; idx1<sz1; idx1++ )
139 get( idx0, idx1 ) += val;
148 const int outsz0 = insz0 > sz0 ? sz0 : insz0;
149 const int outsz1 = insz1 > sz1 ? sz1 : insz1;
151 for (
int idx0=0; idx0<outsz0; idx0++ )
153 for (
int idx1=0; idx1<outsz1; idx1++ )
156 for (
int idx=0; idx<sz1; idx++ )
157 get( idx0, idx1 ) += in.
get( idx0, idx1 );
167 for (
int idx0=0; idx0<sz0; idx0++ )
168 for (
int idx1=0; idx1<sz1; idx1++ )
169 get( idx0, idx1 ) *= fac;
176 const Array2DMatrix
copy( *
this );
181 #define mA2DMatHandleDimErr(v1,v2) \ 184 BufferString emsg( "Dim error: " #v1 "=", v1, " " #v2 "=" ); \ 185 emsg.add( v2 ); pErrMsg( emsg ); \ 187 const_cast<int&>( v2 ) = v1; \ 189 const_cast<int&>( v1 ) = v2; \ 195 Array2DMatrix& out )
const 199 const int outsz0 = insz0 > sz0 ? sz0 : insz0;
200 const int outsz1 = insz1 > sz1 ? sz1 : insz1;
203 for (
int idx0=0; idx0<outsz0; idx0++ )
205 for (
int idx1=0; idx1<outsz1; idx1++ )
208 for (
int idx=0; idx<sz1; idx++ )
209 out.
set( idx0, idx1,
get(idx0,idx1) + in.
get(idx0,idx1) );
224 for (
int idx0=0; idx0<sz0; idx0++ )
227 for (
int idx1=0; idx1<sz1; idx1++ )
228 res +=
get( idx0, idx1 ) * vin.
get( idx1 );
229 vout.
set( idx0, res );
236 Array2DMatrix& out )
const 243 for (
int idx0=0; idx0<sz0; idx0++ )
245 for (
int idx1=0; idx1<insz1; idx1++ )
248 for (
int idx=0; idx<sz1; idx++ )
249 res += in.
get( idx, idx1 ) *
get( idx0, idx );
250 out.
set( idx0, idx1, res );
259 const Array2DMatrix
copy( *
this );
270 for (
int idx0=0; idx0<sz0; idx0++ )
272 for (
int idx1=0; idx1<sz1; idx1++ )
273 out.
set( idx1, idx0,
get( idx0, idx1 ) );
287 for(
int idx0=0; idx0<sz0; idx0++ )
289 for (
int idx1=0; idx1<=idx0; idx1++ )
292 for (
int j=0; j<idx1; j++ )
293 sum += out.
get( idx0, j ) * out.
get( idx1, j );
298 val =
get( idx0, idx0 ) - sum;
305 const fT dividend =
get( idx0, idx1 ) - sum;
306 const fT divideby = out.
get( idx1, idx1 );
308 val = dividend / divideby;
312 out.
set( idx0, idx1, val );
Array2DMatrix(const Array2D< fT > &a2d)
Definition: array2dmatrix.h:42
Array1DImpl< float > Array1DVector
Definition: array2dmatrix.h:21
Array2DMatrix(const Array2DMatrix &oth)
Definition: array2dmatrix.h:38
void getTransposed(Array2DMatrix &)
Definition: array2dmatrix.h:265
void multiply(fT)
Definition: array2dmatrix.h:164
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
virtual T get(int p0, int p1) const =0
void add(fT)
Definition: array2dmatrix.h:134
#define mDefineA2DMatSizes(m, nm)
easily define the matrix dimension sizes
Definition: array2dmatrix.h:81
#define od_int64
Definition: plftypes.h:36
void getProduct(const Array1DVector &, Array1DVector &) const
Definition: array2dmatrix.h:216
bool isEq(const Array2D< fT > &, fT eps=fT(1e-6)) const
Definition: array2dmatrix.h:104
fT & get(int i0, int i1)
Definition: array2dmatrix.h:93
Matrix class based on Array2D. Initialized to 0.
Definition: array2dmatrix.h:32
void set(int pos, T)
Definition: arrayndimpl.h:360
#define mA2DMatHandleDimErr(v1, v2)
Definition: array2dmatrix.h:181
void set(int i0, int i1, fT v)
Definition: array2dmatrix.h:55
virtual int getSize(int dim) const =0
bool isFPEqual(T1 v1, T2 v2, eT eps)
Definition: commondefs.h:42
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:131
bool setSize(int)
Definition: arrayndimpl.h:401
Array2DImpl< fT > a2d_
Definition: array2dmatrix.h:75
void setDiagonal(fT)
Definition: array2dmatrix.h:123
void setAll(fT v=fT(0))
Definition: array2dmatrix.h:59
void getProduct(const ArrayND< T > &in1, const ArrayND< T > &in2, ArrayND< T > &out, bool noudf, bool parallel)
computes the product array between two arrays
Definition: arrayndalgo.h:1747
void getSum(const Array2DMatrix &, Array2DMatrix &) const
Definition: array2dmatrix.h:194
#define mDefineImplA2DMatSizes
Definition: array2dmatrix.h:100
Array2DMatrix(int sz0=1, int sz1=0)
Definition: array2dmatrix.h:35
bool setSize(int, int)
Definition: arrayndimpl.h:516
void setToIdentity()
Definition: array2dmatrix.h:61
int size(bool dim1=false) const
Definition: array2dmatrix.h:86
Array2DMatrix(const Array2DImpl< fT > &a2d)
Definition: array2dmatrix.h:40
void copy(TypeSetBase< T, I > &to, const TypeSetBase< S, I > &from)
Definition: typeset.h:212
#define mClass(module)
Definition: commondefs.h:164
bool getCholesky(Array2DMatrix &) const
Definition: array2dmatrix.h:279
const Array1DInfo & info() const
Definition: arrayndimpl.h:76
void transpose()
Definition: array2dmatrix.h:257
T getSum(const ArrayND< T > &in, bool noudf, bool parallel)
returns the sum of all defined values in the Array. Returns UDF if empty or only udfs encountered...
Definition: arrayndalgo.h:1594
T get(int pos) const
Definition: arrayndimpl.h:372