71 using ElemType = Real;
72 using ElemPoinerType = Real*;
76 for (
unsigned int i = 0; i < Dim; i++)
77 for (
unsigned int j = 0; j < Dim; j++)
78 this->data_[i][j] = 0.0;
102 for (
unsigned int i = 0; i < Dim; i++)
103 for (
unsigned int j = 0; j < Dim; j++)
129 if (Dim == 1)
return this->data_[0][0];
134 for (
int f = 0; f < Dim; f++) {
136 SquareMatrix<Real, Dim - 1> temp = cofactor(
this, 0, f);
137 det += sign * this->data_[0][f] * temp.determinant();
150 for (
unsigned int row = 0; row < Dim; row++) {
151 for (
unsigned int col = 0; col < Dim; col++) {
154 if (row != p && col != q) {
155 m(i, j++) = this->data_[row][col];
173 for (
unsigned int i = 0; i < Dim; i++)
174 tmp += this->data_[i][i];
181 for (
unsigned int i = 0; i < Dim - 1; i++)
182 for (
unsigned int j = i; j < Dim; j++)
183 if (fabs(this->data_[i][j] - this->data_[j][i]) > epsilon)
200 for (
unsigned int i = 0; i < Dim; i++)
201 for (
unsigned int j = 0; j < Dim; j++)
202 if (i != j && fabs(this->data_[i][j]) > epsilon)
return false;
214 for (
unsigned int i = 0; i < Dim; i++) {
215 result(i) = this->data_[i][i];
224 for (
unsigned int i = 0; i < Dim; i++)
225 if (fabs(this->data_[i][i] - 1) > epsilon)
return false;
234 for (
unsigned int i = 0; i < Dim; i++)
235 for (
unsigned int j = 0; j < Dim; j++)
236 result(j, i) = this->data_[i][j];
318 int i, j, k, iq, ip, numPos;
319 Real tresh, theta, tau, t, sm, s, h, g, c, tmp;
320 Real bspace[MAX_SCRATCH_ARRAY_SIZE], zspace[MAX_SCRATCH_ARRAY_SIZE];
321 Real* b = (n <= MAX_SCRATCH_ARRAY_SIZE) ? bspace :
new Real[n];
322 Real* z = (n <= MAX_SCRATCH_ARRAY_SIZE) ? zspace :
new Real[n];
325 for (ip = 0; ip < n; ip++) {
326 for (iq = 0; iq < n; iq++) {
331 for (ip = 0; ip < n; ip++) {
332 b[ip] = w[ip] = a(ip, ip);
337 for (i = 0; i < MAX_ROTATIONS; ++i) {
339 for (ip = 0; ip < n - 1; ip++) {
340 for (iq = ip + 1; iq < n; iq++) {
341 sm += std::abs(a(ip, iq));
344 if (sm == 0.0) {
break; }
347 tresh = 0.2 * sm / (n * n);
352 for (ip = 0; ip < n - 1; ip++) {
353 for (iq = ip + 1; iq < n; iq++) {
354 g = 100.0 * std::abs(a(ip, iq));
357 if (i > 3 && (std::abs(w[ip]) + g) == std::abs(w[ip]) &&
358 (std::abs(w[iq]) + g) == std::abs(w[iq])) {
360 }
else if (std::abs(a(ip, iq)) > tresh) {
362 if ((std::abs(h) + g) == std::abs(h)) {
365 theta = 0.5 * h / (a(ip, iq));
366 t = 1.0 / (std::abs(theta) + std::sqrt(1.0 + theta * theta));
367 if (theta < 0.0) { t = -t; }
369 c = 1.0 / std::sqrt(1 + t * t);
380 for (j = 0; j <= ip - 1; ++j) {
381 ROTATE(a, j, ip, j, iq);
384 for (j = ip + 1; j <= iq - 1; ++j) {
385 ROTATE(a, ip, j, j, iq);
388 for (j = iq + 1; j < n; ++j) {
389 ROTATE(a, ip, j, iq, j);
391 for (j = 0; j < n; ++j) {
392 ROTATE(v, j, ip, j, iq);
398 for (ip = 0; ip < n; ip++) {
406 if (i >= MAX_ROTATIONS) {
407 std::cout <<
"SquareMatrix::Jacobi: Error extracting eigenfunctions"
409 if (n > MAX_SCRATCH_ARRAY_SIZE) {
417 for (j = 0; j < n - 1; ++j) {
420 for (i = j + 1; i < n; ++i) {
429 for (i = 0; i < n; i++) {
440 int ceil_half_n = (n >> 1) + (n & 1);
441 for (j = 0; j < n; ++j) {
442 for (numPos = 0, i = 0; i < n; ++i) {
443 if (v(i, j) >= 0.0) { numPos++; }
445 if (numPos < ceil_half_n) {
446 for (i = 0; i < n; ++i) {
452 if (n > MAX_SCRATCH_ARRAY_SIZE) {
static int jacobi(SquareMatrix< Real, Dim > &a, Vector< Real, Dim > &d, SquareMatrix< Real, Dim > &v)
Jacobi iteration routines for computing eigenvalues/eigenvectors of real symmetric matrix.