00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef TYPES_INCLUDES
00022 #error "You can't include realmat.h directly; Instead, You have to include types.h"
00023
00024 #define REALMAT_H
00025 #endif
00026
00027 #ifndef REALMAT_H
00028 #define REALMAT_H
00029
00034 namespace nnfw {
00035
00041 class NNFW_API RealMat : public MatrixData<Real, RealVec> {
00042 public:
00045
00048 RealMat( u_int rows, u_int cols );
00049
00054 RealMat( RealVec& src, u_int rstart, u_int rend, u_int rows, u_int cols );
00055
00058 ~RealMat();
00059
00061
00063
00065 RealMat& operator-() {
00066 -rawdata();
00067 return (*this);
00068 };
00069
00071 RealMat& transpose() {
00072 Real tmp;
00073 RealMat& self = *this;
00074 for( u_int i=0; i<rows(); i++ ) {
00075 for( u_int j=i+1; j<cols(); j++ ) {
00076 tmp = self[i][j];
00077 self[i][j] = self[j][i];
00078 self[j][i] = tmp;
00079 }
00080 }
00081 return (*this);
00082 };
00083
00085
00088
00090 RealMat& operator+=(const RealMat& r ) {
00091 #ifdef NNFW_DEBUG
00092 if( rows() != r.rows() || cols() != r.cols() ) {
00093 nError() << "Different dimension";
00094 return (*this);
00095 }
00096 #endif
00097 rawdata() += r.rawdata();
00098 return (*this);
00099 };
00100
00102 RealMat& operator+=(const Real& r ) {
00103 rawdata() += r;
00104 return (*this);
00105 };
00106
00108 RealMat& operator-=(const RealMat& r ) {
00109 #ifdef NNFW_DEBUG
00110 if( rows() != r.rows() || cols() != r.cols() ) {
00111 nError() << "Different dimension";
00112 return (*this);
00113 }
00114 #endif
00115 rawdata() -= r.rawdata();
00116 return (*this);
00117 };
00118
00120 RealMat& operator-=(const Real& r ) {
00121 rawdata() -= r;
00122 return (*this);
00123 };
00124
00126 RealMat& operator*=(const RealMat& r ) {
00127 #ifdef NNFW_DEBUG
00128 if( rows() != r.rows() || cols() != r.cols() ) {
00129 nError() << "Different dimension";
00130 return (*this);
00131 }
00132 #endif
00133 rawdata() *= r.rawdata();
00134 return (*this);
00135 };
00136
00138 RealMat& operator*=(const Real& r ) {
00139 rawdata() *= r;
00140 return (*this);
00141 };
00142
00144 RealMat& operator/=(const RealMat& r ) {
00145 #ifdef NNFW_DEBUG
00146 if( rows() != r.rows() || cols() != r.cols() ) {
00147 nError() << "Different dimension";
00148 return (*this);
00149 }
00150 #endif
00151 rawdata() /= r.rawdata();
00152 return (*this);
00153 };
00154
00156 RealMat& operator/=(const Real& r ) {
00157 rawdata() /= r;
00158 return (*this);
00159 };
00160
00162
00165
00172 static RealVec& mul( RealVec& y, const RealVec& x, const RealMat& m );
00173
00180 static RealVec& mul( RealVec& y, const RealMat& m, const RealVec& x );
00181
00188 RealMat& deltarule( Real rate, const RealVec& x, const RealVec& y );
00189
00191
00193
00195 RealMat& cover( const MatrixData<bool>& mask ) {
00196 RealMat& self = *this;
00197 for( u_int r=0; r<rows(); r++ ) {
00198 for( u_int c=0; c<cols(); c++ ) {
00199 if ( !mask[r][c] ) {
00200 self[r][c] = 0.0;
00201 }
00202 }
00203 }
00204 return (*this);
00205 };
00206
00208
00210
00212 RealMat& exp();
00213
00215 RealMat& scale( const Real v ) {
00216 for( u_int i=0; i<size(); i++ ) {
00217 rawdata()[i] *= v;
00218 }
00219 return (*this);
00220 };
00221
00223 RealMat& inv();
00224
00226 Real norm() {
00227 return rawdata().norm();
00228 };
00230 void normalize() {
00231 rawdata().normalize();
00232 };
00233
00235
00236
00237 friend Real* getRawData( RealMat& );
00238
00239 };
00240
00241 }
00242
00243 #endif
00244