14 using namespace Eigen;
20 matOut.setZero(nR, nC);
22 for (
int i = 0; i < nR; ++i)
24 for (
int j = 0; j < nC; ++j)
26 matOut(i, j) = arrayIn[i][j];
31 void VecBy3DimArray(
const MatrixXd &vec,
const MatrixXd &arr3dim, MatrixXd &retArray)
50 int nRow, nCol, nVec, nColFin;
52 nRow = arr3dim.rows();
53 nCol = arr3dim.cols();
55 nColFin = nCol / nVec;
59 if ((nVec * nColFin) != nCol)
61 std::cerr << std::endl <<
"nVec (" << nVec <<
") ; nColFin (" << nColFin <<
") ; nCol (" << nCol <<
")";
66 retArray.setZero(nRow, nColFin);
68 for (ii = 0; ii < nRow; ii++)
70 for (jj = 0; jj < nColFin; jj++)
72 for (kk = 0; kk < nVec; kk++)
74 retArray(ii, jj) += arr3dim(ii, jj + kk * nColFin) * vec(0, kk);
80 void Deriv1stChainScalar(
const MatrixXd &dSdc,
const MatrixXd &dcdd, MatrixXd &dSdd)
85 void Deriv2ndChainScalar(
const MatrixXd &dSdc,
const MatrixXd &dcdd,
const MatrixXd &HSc,
const MatrixXd &Hcd,
88 VecBy3DimArray(dSdc, Hcd, HSd);
91 errFlag |= dcdd.rows() != HSc.cols();
92 errFlag |= dcdd.cols() != HSd.cols();
93 errFlag |= HSd.rows() != HSd.cols();
96 std::cerr << std::endl <<
"dSdc: [" << dSdc.rows() <<
", " << dSdc.cols() <<
"]" << std::endl;
98 std::cerr << std::endl <<
"dcdd: [" << dcdd.rows() <<
", " << dcdd.cols() <<
"]" << std::endl;
100 std::cerr << std::endl <<
"HSc: [" << HSc.rows() <<
", " << HSc.cols() <<
"]" << std::endl;
102 std::cerr << std::endl <<
"HSd: [" << HSd.rows() <<
", " << HSd.cols() <<
"]" << std::endl;
105 std::cerr << std::endl <<
"dSdc: [" << dSdc.rows() <<
", " << dSdc.cols() <<
"]";
106 std::cerr << std::endl <<
"dcdd: [" << dcdd.rows() <<
", " << dcdd.cols() <<
"]";
107 std::cerr << std::endl <<
"HSc: [" << HSc.rows() <<
", " << HSc.cols() <<
"]";
108 std::cerr << std::endl <<
"HSd: [" << HSd.rows() <<
", " << HSd.cols() <<
"]" << std::endl;
114 HSd = HSd + (dcdd.transpose() * HSc * dcdd);
117 void PrintMatrix(
const MatrixXd &mat)
123 for (ii = 0; ii < ni; ++ii)
125 for (jj = 0; jj < nj; ++jj)
127 cout << mat(ii, jj) <<
" ";
132 void PrintMatrixFile(
const MatrixXd &mat,
const char *name)
135 myfile.open(name, ios::app);
136 PrintMatrixFile(mat, myfile);
140 void PrintMatrixFile(
const MatrixXd &mat, std::ostream &myfile)
147 for (ii = 0; ii < ni; ++ii)
149 for (jj = 0; jj < nj; ++jj)
151 myfile << mat(ii, jj) <<
" ";
158 void PrintMatrix(
const VectorXd &mat)
163 for (ii = 0; ii < ni; ++ii)
165 cout << mat[ii] <<
" ";
169 void PrintMatrix(
const RowVectorXd &mat)
174 for (ii = 0; ii < ni; ++ii)
176 cout << mat[ii] <<
" ";
181 double StreamStatistics(
const VectorXd &&vec, ostream &out,
const string &&sep)
187 double norm = vec.norm();
191 out << std::setw(out.precision() + 7) << vec.mean() << sep;
192 out << std::setw(out.precision() + 7) << sqrt((vec.array() - vec.mean()).square().sum() / (vec.size() - 1))
194 out << std::setw(out.precision() + 7) << vec.maxCoeff() << sep;
195 out << std::setw(out.precision() + 7) << vec.minCoeff() << sep;
201 void StreamOutVector(
const VectorXd &&vec, std::ostream &out,
const string &&sep)
209 for (i = 0; i < n; ++i)
211 out << vec[i] << sep;
Provides a 2D std::vector based container.
Provides the error and warning system used by the RSVS3D project.
#define RSVS3D_ERROR_LOGIC(M)
Throw a logic_error.
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.