2 #ifndef TEMPLATEDARRAYUTILITIES_H_
3 #define TEMPLATEDARRAYUTILITIES_H_
10 namespace Approximation
13 template<
typename MatType>
23 template<
typename MatrixType>
24 unsigned GetShape(MatrixType
const& mat,
unsigned dim)
26 return mat.dimension(dim);
29 template<
typename ScalarType,
int rows,
int cols>
30 unsigned GetShape(Eigen::Matrix<ScalarType, rows, cols>
const& mat,
unsigned dim)
33 return dim==0 ? mat.rows() : mat.cols();
36 template<
typename Derived>
40 return dim==0 ? mat.
rows() : mat.
cols();
44 template<
typename Derived>
45 unsigned GetShape(Eigen::Ref<Derived>
const& mat,
unsigned dim)
48 return dim==0 ? mat.rows() : mat.cols();
55 template<
typename VectorType1,
typename VectorType2>
56 double CalcSquaredDistance(VectorType1
const& v1, VectorType2
const& v2,
int startDim=0,
int endDim=-1)
63 const int dim = endDim-startDim;
64 const int minDim = 10;
70 for(
int i=0; i<dim; ++i)
72 output += std::pow(v1(startDim+i)-v2(startDim+i), 2.0);
79 int midDim = startDim + std::floor(0.5*dim);
87 template<
typename VectorType1,
typename VectorType2>
104 template<
typename MatType>
135 operator Eigen::VectorXd()
const
142 Eigen::VectorXd output(
rows());
143 for(
int i=0; i<
rows(); ++i)
144 output(i) = (*this)(i);
152 template<
typename VecType>
171 std::vector<unsigned>
const&
inds;
174 template<
typename MatType>
191 template<
typename Derived>
194 assert(otherMat.rows()==
numRows);
195 assert(otherMat.cols()==
numCols);
197 for(
unsigned j=0; j<
numCols; ++j)
199 for(
unsigned i=0; i<
numRows; ++i)
221 template<
typename MatType>
227 template<
typename MatType>
234 template<
typename MatType>
double operator()(unsigned row) const
ColumnSlice(MatType &matrixIn, unsigned colIn)
unsigned dimension(unsigned dim) const
double & operator()(unsigned row, unsigned col2)
double operator()(unsigned row, unsigned col2) const
double & operator()(unsigned row)
Eigen::VectorXd eval() const
double & operator()(unsigned row, unsigned col)
MatrixBlock & operator=(Eigen::DenseBase< Derived > const &otherMat)
double operator()(unsigned row, unsigned col) const
MatrixBlock(MatType &matrixIn, unsigned startRowIn, unsigned startColIn, unsigned numRowsIn, unsigned numColsIn)
double operator()(unsigned row) const
VectorSlice(VecType const &vectorIn, std::vector< unsigned > const &indsIn)
unsigned dimension(unsigned dim) const
std::vector< unsigned > const & inds
double & operator()(unsigned row)
double CalcDistance(VectorType1 const &v1, VectorType2 const &v2)
MatrixBlock< MatType > GetBlock(MatType &matrix, unsigned rowStart, unsigned colStart, unsigned numRows, unsigned numCols)
VectorSlice< MatType > GetSlice(MatType &matrix, std::vector< unsigned > const &inds)
double CalcSquaredDistance(VectorType1 const &v1, VectorType2 const &v2, int startDim=0, int endDim=-1)
Calculates the distance squared between two points defined by vectors v1 and v2.
unsigned GetShape(MatrixType const &mat, unsigned dim)
ColumnSlice< MatType > GetColumn(MatType &matrix, unsigned col)