FgMatrixC<T,nrows,1> colVec(uint col) const { FgMatrixC<T,nrows,1> ret; FGASSERT_FAST(col < nrows); for (uint rr=0; rr<nrows; rr++) ret[rr] = elem(rr,col); return ret; }
FgMatrixC<T,1,ncols> rowVec(uint row) const { FgMatrixC<T,1,ncols> ret; FGASSERT_FAST(row < nrows); for (uint cc=0; cc<ncols; ++cc) ret[cc] = elem(row,cc); return ret; }
T lnNormalIsotropic( FgMatrixC<T,dim,1> val, FgMatrixC<T,dim,1> mean, T stdev) { FGASSERT_FAST(stdev > T(0)); return (-0.5 * fgLn_2pi() * dim - std::log(stdev) * dim - 0.5 * (val-mean).lengthSqr() / fgSqr(stdev)); }
FgMatrixC<T,srows,scols> subMatrix(uint firstRow,uint firstCol) const { FGASSERT_FAST((firstRow+srows <= nrows) && (firstCol+scols <= ncols)); FgMatrixC<T,srows,scols> ret; uint cnt = 0; for (uint rr=firstRow; rr<firstRow+srows; ++rr) for (uint cc=firstCol; cc<firstCol+scols; ++cc) ret[cnt++] = elem(rr,cc); return ret; }
inline uint fgClip(int val,uint exclusiveUpperBound) { FGASSERT_FAST(exclusiveUpperBound > 0); if (val < 0) return 0; uint ret(val); if (ret >= exclusiveUpperBound) return exclusiveUpperBound-1; return ret; }
const T & elem(size_t ircs_x,size_t ircs_y) const { FGASSERT_FAST((ircs_x < m_dims[0]) && (ircs_y < m_dims[1])); return m_data[ircs_y*m_dims[0]+ircs_x]; }
T & elm(size_t col,size_t row) { FGASSERT_FAST((row < nrows) && (col < ncols)); return m_data[row*ncols+col]; }
const T & elem(size_t row,size_t col) const { FGASSERT_FAST((row < nrows) && (col < ncols)); return m_data[row*ncols+col]; }
const T * dataPtr() const {FGASSERT_FAST(!m_data.empty()); return &m_data[0]; }
const T & operator[](size_t ii) const {FGASSERT_FAST(ii<m_data.size()); return m_data[ii]; }
const T & operator[](FgMatrixC<uint,2,1> crd) const { FGASSERT_FAST((crd.m[0]<ncols) && (crd.m[1]<nrows)); return m[crd.m[1]*ncols+crd.m[0]]; }
const T & operator[](size_t xx) const { FGASSERT_FAST(xx < nrows*ncols); return m[xx]; }
const T & elm(uint col,uint row) const { FGASSERT_FAST((row < nrows) && (col < ncols)); return m[row*ncols+col]; }
// elem is deprecated: T & elem(uint row,uint col) { FGASSERT_FAST((row < nrows) && (col < ncols)); return m[row*ncols+col]; }