27 #ifndef _TNT_EXTENSION_HPP_
28 #define _TNT_EXTENSION_HPP_
45 inline Vector<T> Array1D2Vector(Array1D<T> A)
47 Vector<T> V(A.dim(), &A[0]);
55 inline Array1D<T> Vector2Array1D(Vector<T> V)
57 Array1D<T> A(V.dim(), &V[0]);
65 inline Matrix<T> Array2D2Matrix(Array2D<T> A)
67 Matrix<T> M(A.dim1(), A.dim2(), A[0]);
75 inline Array2D<T> Matrix2Array2D(Matrix<T> M)
77 Array2D<T> A(M.dim1(), M.dim2(), M[0]);
85 inline Matrix<T> Array1D2Matrix(Array1D<T> A)
87 Matrix<T> M(1, A.dim(), &A[0]);
97 inline Array1D<T> Matrix2Array1D(Matrix<T> M)
101 Array1D<T> A(M.dim2(), M[0]);
104 else if (M.dim2() == 1)
106 Array1D<T> A(M.dim1(), M[0]);
119 inline Array2D<double> makeIdentity(
int order)
121 Array2D<double> I(order,order,0.0);
122 for (
int i=0;i<order;i++)
131 inline Array1D<T> copyrow(
const Array2D<T> &Array,
134 if (r >= Array.dim1())
139 int m = Array.dim2();
141 for (
int c=0; c<m; c++)
150 inline Array1D<T> copycolumn(
const Array2D<T> &Array,
153 if (c >= Array.dim2())
158 int n = Array.dim1();
160 for (
int r=0; r<n; r++)
169 inline Array2D<T> copyArray2D(
const Array3D<T> &Array,
172 if (m >= Array.dim1())
177 int n = Array.dim2();
178 int o = Array.dim3();
180 for (
int r=0; r<n; r++)
181 for (
int c=0; c<o; c++)
182 A[r][c] = Array[m][r][c];
190 inline int injectrow(Array2D<T> &A2D,
191 const Array1D<T> &A1D,
195 if (m == A1D.dim() && r < A2D.dim1())
197 for (
int c=0; c<m; c++)
209 inline int injectcolumn(Array2D<T> &A2D,
210 const Array1D<T> &A1D,
214 if (n == A1D.dim() && c < A2D.dim2())
216 for (
int r=0; r<n; r++)
227 inline int injectArray2D(Array3D<T> &A3D,
228 const Array2D<T> &A2D,
233 if (n == A2D.dim1() && o == A2D.dim2() && m < A3D.dim1())
235 for (
int r=0; r<n; r++)
236 for (
int c=0; c<o; c++)
237 A3D[m][r][c] = A2D[r][c];
256 inline Matrix<T> mult_transpose(
const Matrix<T> &A,
260 #ifdef TNT_BOUNDS_CHECK
261 assert(A.num_cols() == B.num_cols());
264 Subscript M = A.num_cols();
265 Subscript N = A.num_rows();
266 Subscript K = B.num_rows();
271 for (Subscript i=0; i<N; i++)
272 for (Subscript k=0; k<K; k++)
275 for (Subscript j=0; j<M; j++)
276 sum = sum + A[i][j] * B[k][j];
Definition: tnt_extension.hpp:39