76 m_Array.
Create(
sizeof(
double), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_2);
82 m_Array.
Create(
sizeof(
double), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_2);
95 m_Array.
Create(
sizeof(
double), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_2);
108 memcpy(
Get_Data(), Data, n *
sizeof(
double));
112 memset(
Get_Data(), 0, n *
sizeof(
double));
227 CSG_String s, sep(Separator && *Separator ? Separator :
SG_T(
" "));
422 Get_Data()[0] = v[1] * Vector[2] - v[2] * Vector[1];
423 Get_Data()[1] = v[2] * Vector[0] - v[0] * Vector[2];
424 Get_Data()[2] = v[0] * Vector[1] - v[1] * Vector[0];
581 return( Vector * Scalar );
627 double d = v[i]; v[i] = v[j]; v[j] = d;
648 if( bAscending ==
false )
718 z += Vector[i] * Z[i];
726 return( acos(z / (
A *
B)) );
752 double sin_a = sin(Angle);
753 double cos_a = cos(Angle);
757 x = t * cos_a - y * sin_a;
758 y = t * sin_a + y * cos_a;
782 double sin_a = sin(Angle);
783 double cos_a = cos(Angle);
788 Vector[1] = v[1] * cos_a - v[2] * sin_a;
789 Vector[2] = v[1] * sin_a + v[2] * cos_a;
793 Vector[0] = v[0] * cos_a + v[2] * sin_a;
794 Vector[2] =-v[0] * sin_a + v[2] * cos_a;
798 Vector[0] = v[0] * cos_a - v[1] * sin_a;
799 Vector[1] = v[0] * sin_a + v[1] * cos_a;
838 return(
Create(Matrix.m_nx, Matrix.m_ny, Matrix.m_z[0]) );
846 Create(nCols, nRows, Data);
851 if( nCols < 1 || nRows < 1 )
858 if( nCols != m_nx || nRows != m_ny )
862 if( (m_z = (
double **)
SG_Malloc(nRows *
sizeof(
double *))) == NULL
863 || (m_z[0] = (
double *)
SG_Malloc(nRows * nCols *
sizeof(
double ))) == NULL )
873 for(
sLong y=1; y<m_ny; y++)
875 m_z[y] = m_z[y - 1] + m_nx;
881 memcpy(m_z[0], Data, m_ny * m_nx *
sizeof(
double));
885 memset(m_z[0], 0, m_ny * m_nx *
sizeof(
double));
896 Create(nCols, nRows, Data);
901 if(
Create(nCols, nRows) )
905 for(
sLong y=0; y<m_ny; y++)
907 memcpy(m_z[y], Data[y], m_nx *
sizeof(
double));
941 void CSG_Matrix::_On_Construction(
void)
943 m_z = NULL; m_nx = m_ny = 0;
992 if( nCols > 0 && m_ny > 0 )
996 if(
Create(Tmp.m_nx + nCols, Tmp.m_ny) )
998 for(
sLong y=0; y<Tmp.m_ny; y++)
1000 memcpy(m_z[y], Tmp.m_z[y], Tmp.m_nx *
sizeof(
double));
1013 if( nRows > 0 && m_nx > 0 )
1017 m_z = (
double **)
SG_Realloc(m_z , m_ny *
sizeof(
double *));
1018 m_z[0] = (
double *)
SG_Realloc(m_z[0], m_ny * m_nx *
sizeof(
double ));
1020 for(
sLong y=1; y<m_ny; y++)
1022 m_z[y] = m_z[y - 1] + m_nx;
1025 memset(m_z[m_ny - nRows], 0, nRows * m_nx *
sizeof(
double));
1039 if( nCols > 0 && m_ny > 0 && nCols < m_nx )
1043 if(
Create(Tmp.m_nx - nCols, Tmp.m_ny) )
1045 for(
sLong y=0; y<Tmp.m_ny; y++)
1047 memcpy(m_z[y], Tmp.m_z[y], m_nx *
sizeof(
double));
1063 if( nRows > 0 && m_nx > 0 && nRows < m_ny )
1067 m_z = (
double **)
SG_Realloc(m_z , m_ny *
sizeof(
double *));
1068 m_z[0] = (
double *)
SG_Realloc(m_z[0], m_ny * m_nx *
sizeof(
double ));
1125 if( Col >= 0 && Col <= m_nx )
1129 if(
Create(Tmp.m_nx + 1, Tmp.m_ny) )
1131 for(
sLong y=0; y<m_ny; y++)
1133 double *pz = m_z[y], *pz_tmp = Tmp.m_z[y];
1135 for(
sLong x=0; x<m_nx; x++, pz++)
1139 *pz = *pz_tmp; pz_tmp++;
1163 if( Row >= 0 && Row <= m_ny )
1167 if(
Create(Tmp.m_nx, Tmp.m_ny + 1) )
1169 for(
sLong y=0, y_tmp=0; y<m_ny; y++)
1173 memcpy(m_z[y], Tmp.m_z[y_tmp++], m_nx *
sizeof(
double));
1177 memcpy(m_z[y], Data, m_nx *
sizeof(
double));
1196 if( Data && Col >= 0 && Col < m_nx )
1198 for(
int y=0; y<m_ny; y++)
1200 m_z[y][Col] = Data[y];
1226 if( Data && Row >= 0 && Row < m_ny )
1228 memcpy(m_z[Row], Data, m_nx *
sizeof(
double));
1258 if( Col >= 0 && Col < m_nx )
1262 if(
Create(Tmp.m_nx - 1, Tmp.m_ny) )
1264 for(
sLong y=0; y<m_ny; y++)
1266 double *pz = m_z[y], *pz_tmp = Tmp.m_z[y];
1268 for(
sLong x_tmp=0; x_tmp<Tmp.m_nx; x_tmp++, pz_tmp++)
1272 *pz = *pz_tmp; pz++;
1292 if( Row >= 0 && Row < m_ny )
1296 if(
Create(Tmp.m_nx, Tmp.m_ny - 1) )
1298 for(
sLong y=0, y_tmp=0; y_tmp<Tmp.m_ny; y_tmp++)
1302 memcpy(m_z[y++], Tmp.m_z[y_tmp], m_nx *
sizeof(
double));
1318 if( Col >= 0 && Col < m_nx )
1322 for(
int y=0; y<m_ny; y++)
1324 Vector[y] = m_z[y][Col];
1336 if( Row >= 0 && Row < m_ny )
1338 Vector.
Create(m_nx, m_z[Row]);
1352 CSG_String s, sep(Separator && *Separator ? Separator :
SG_T(
" "));
1356 for(
sLong y=0; y<m_ny; y++)
1360 for(
sLong x=0; x<m_nx; x++)
1406 if( m_nx < Matrix.m_nx || m_ny < Matrix.m_ny )
1411 for(
sLong y=0; y<m_ny; y++)
for(
sLong x=0; x<m_nx; x++)
1413 if( m_z[y][x] != Matrix.m_z[y][x] )
1425 if( m_nx > 0 && m_ny > 0 )
1427 for(
sLong y=0; y<m_ny; y++)
1429 for(
sLong x=0; x<m_nx; x++)
1444 return(
Create(Matrix) );
1450 if( m_nx > 0 && m_ny > 0 )
1452 for(
sLong y=0; y<m_ny; y++)
1454 for(
sLong x=0; x<m_nx; x++)
1456 m_z[y][x] += Scalar;
1469 if( m_nx == Matrix.m_nx && m_ny == Matrix.m_ny )
1471 for(
sLong y=0; y<m_ny; y++)
1473 for(
sLong x=0; x<m_nx; x++)
1475 m_z[y][x] += Matrix.m_z[y][x];
1488 if( m_nx == Matrix.m_nx && m_ny == Matrix.m_ny )
1490 for(
sLong y=0; y<m_ny; y++)
1492 for(
sLong x=0; x<m_nx; x++)
1494 m_z[y][x] -= Matrix.m_z[y][x];
1507 if( m_nx > 0 && m_ny > 0 )
1509 for(
sLong y=0; y<m_ny; y++)
1511 for(
sLong x=0; x<m_nx; x++)
1513 m_z[y][x] *= Scalar;
1529 for(
sLong y=0; y<m_ny; y++)
1533 for(
sLong x=0; x<m_nx; x++)
1535 z += m_z[y][x] * Vector(x);
1549 if( m_nx == Matrix.m_ny && m.
Create(Matrix.m_nx, m_ny) )
1551 for(
int y=0; y<m.m_ny; y++)
1553 for(
int x=0; x<m.m_nx; x++)
1557 for(
int n=0; n<m_nx; n++)
1559 z += m_z[y][n] * Matrix.m_z[n][x];
1701 return( Matrix * Scalar );
1712 return(
Create(m_nx, m_ny) );
1718 if( m_nx > 0 && m_ny > 0 )
1720 for(
int y=0; y<m_ny; y++)
1722 for(
int x=0; x<m_nx; x++)
1724 m_z[y][x] = x == y ? 1. : 0.;
1741 for(
int y=0; y<m_ny; y++)
1743 for(
int x=0; x<m_nx; x++)
1745 m_z[y][x] = m.m_z[x][y];
1760 if( nSubSquare > 0 )
1762 if( nSubSquare <= m_nx && nSubSquare <= m_ny )
1787 for(
int i=0; i<n; i++)
1816 d = n % 2 ? -1. : 1.;
1818 for(
int i=0; i<
Get_NX(); i++)
1833 for(
sLong y=0; y<m_ny; y++)
1835 for(
sLong x=0; x<m_nx; x++)
1837 m.m_z[x][y] = m_z[y][x];
1870 double sin_a = sin(R), cos_a = cos(R);
1874 M[0][0] = cos_a; M[0][1] = -sin_a;
1875 M[1][0] = sin_a; M[1][1] = cos_a;
1889 double sin_a = sin(Rx), cos_a = cos(Rx);
1890 double sin_b = sin(Ry), cos_b = cos(Ry);
1891 double sin_c = sin(Rz), cos_c = cos(Rz);
1895 M[0][0] = cos_a * cos_b; M[0][1] = cos_a * sin_b * sin_c - sin_a * cos_c; M[0][2] = cos_a * sin_b * cos_c + sin_a * sin_c;
1896 M[1][0] = sin_a * cos_b; M[1][1] = sin_a * sin_b * sin_c + cos_a * cos_c; M[1][2] = sin_a * sin_b * cos_c - cos_a * sin_c;
1897 M[2][0] = -sin_b; M[2][1] = cos_b * sin_c ; M[2][2] = cos_b * cos_c ;
1912 int n = Vector.
Get_N();
1914 if( n > 0 && n == Matrix.
Get_NX() && n == Matrix.
Get_NY() )
1935 CSG_Vector Intermediate; Eigen_Vectors = Matrix;
1950 CSG_Vector Vector(n);
if( nRowChanges ) { (*nRowChanges) = 0; }
1956 for(
int j=0; j<n; j++)
1958 double d = fabs(Matrix[i][j]);
1971 Vector[i] = 1. / dMax;
1978 for(
int i=0; i<j; i++)
1980 double Sum = Matrix[i][j];
1982 for(
int k=0; k<i; k++)
1984 Sum -= Matrix[i][k] * Matrix[k][j];
1992 for(
int i=j; i<n; i++)
1994 double Sum = Matrix[i][j];
1996 for(
int k=0; k<j; k++)
1998 Sum -= Matrix[i][k] * Matrix[k][j];
2003 double d = Vector[i] * fabs(Sum);
2014 for(
int k=0; k<n; k++)
2016 double d = Matrix[iMax][k];
2017 Matrix[iMax][k] = Matrix[j ][k];
2021 Vector[iMax] = Vector[j];
2023 if( nRowChanges ) { (*nRowChanges)++; }
2026 Permutation[j] = iMax;
2028 if( Matrix[j][j] == 0. )
2035 double d = 1. / (Matrix[j][j]);
2037 for(
int i=j+1; i<n; i++)
2053 bool SG_Matrix_LU_Solve(
int n,
const int *Permutation,
const double **Matrix,
double *Vector,
bool bSilent)
2057 double Sum = Vector[Permutation[i]]; Vector[Permutation[i]] = Vector[i];
2061 for(
int j=k; j<=i-1; j++)
2063 Sum -= Matrix[i][j] * Vector[j];
2076 double Sum = Vector[i];
2078 for(
int j=i+1; j<n; j++)
2080 Sum -= Matrix[i][j] * Vector[j];
2083 Vector[i] = Sum / Matrix[i][i];
2099 if(
A.Get_NX() !=
A.Get_NY() )
2111 for(
int i=n-1, l=n-2; i>=1; i--, l--)
2119 for(
int k=0; k<=l; k++)
2121 scale += fabs(
A[i][k]);
2130 for(
int k=0; k<=l; k++)
2133 h +=
A[i][k] *
A[i][k];
2137 double g = f > 0. ? -sqrt(h) : sqrt(h);
2143 for(
int j=0; j<=l; j++)
2145 A[j][i] =
A[i][j]/h;
2148 for(
int k=0; k<=j; k++)
2150 g +=
A[j][k] *
A[i][k];
2153 for(
int k=j+1; k<=l; k++)
2155 g +=
A[k][j] *
A[i][k];
2159 f += e[j] *
A[i][j];
2162 double hh = f / (h + h);
2164 for(
int j=0; j<=l; j++)
2167 e[j] = g = e[j] - hh * f;
2169 for(
int k=0; k<=j; k++)
2171 A[j][k] -= (f * e[k] + g *
A[i][k]);
2187 for(
int i=0, l=-1; i<n; i++, l++)
2191 for(
int j=0; j<=l; j++)
2195 for(
int k=0; k<=l; k++)
2197 g +=
A[i][k] *
A[k][j];
2200 for(
int k=0; k<=l; k++)
2202 A[k][j] -= g *
A[k][i];
2210 for(
int j=0; j<=l; j++)
2212 A[j][i] =
A[i][j] = 0.;
2234 int m, l, iter, i, k, n;
2235 double s, r, p, g, f, dd, c, b;
2252 for(m=l; m<n-1; m++)
2254 dd = fabs(d[m]) + fabs(d[m + 1]);
2256 if( fabs(e[m]) + dd == dd )
2269 g = (d[l+1] - d[l]) / (2. * e[l]);
2270 r = sqrt((g * g) + 1.);
2271 g = d[m] - d[l] + e[l] / (g +
M_SET_SIGN(r, g));
2275 for(i = m-1; i >= l; i--)
2280 if (fabs(f) >= fabs(g))
2283 r = sqrt((c * c) + 1.);
2290 r = sqrt((s * s) + 1.);
2296 r = (d[i] - g) * s + 2. * c * b;
2304 Q[k][i+1] = s * Q[k][i] + c * f;
2305 Q[k][i] = c * Q[k][i] - s * f;