2 #ifndef vnl_matrix_hxx_ 3 #define vnl_matrix_hxx_ 91 # include <vcl_msvc_warnings.h> 99 # define vnl_matrix_construct_hack() 102 #define vnl_matrix_alloc_blah() \ 104 if (this->num_rows && this->num_cols) { \ 106 this->data = vnl_c_vector<T>::allocate_Tptr(this->num_rows); \ 108 T* elmns = vnl_c_vector<T>::allocate_T(this->num_rows * this->num_cols); \ 110 for (unsigned int i = 0; i < this->num_rows; ++ i) \ 111 this->data[i] = elmns + i*this->num_cols; \ 115 (this->data = vnl_c_vector<T>::allocate_Tptr(1))[0] = 0; \ 120 #define vnl_matrix_free_blah \ 123 if (this->num_cols && this->num_rows) { \ 124 vnl_c_vector<T>::deallocate(this->data[0], this->num_cols * this->num_rows); \ 125 vnl_c_vector<T>::deallocate(this->data, this->num_rows); \ 128 vnl_c_vector<T>::deallocate(this->data, 1); \ 138 : num_rows(rowz), num_cols(colz)
148 : num_rows(rowz), num_cols(colz)
152 std::fill_n( this->
data[0], rowz * colz, value );
158 : num_rows(r), num_cols(c)
163 case vnl_matrix_identity:
165 for (
unsigned int i = 0; i < r; ++ i)
166 for (
unsigned int j = 0; j < c; ++ j)
167 this->
data[i][j] = (i==j) ? T(1) : T(0);
170 std::fill_n( this->
data[0], r * c, T(0) );
178 #if 1 // fsm: who uses this? 183 : num_rows(rowz), num_cols(colz)
189 std::copy( values, values + n, this->
data[0] );
198 : num_rows(rowz), num_cols(colz)
202 std::copy( datablck, datablck + rowz * colz, this->
data[0] );
211 : num_rows(from.num_rows), num_cols(from.num_cols)
216 T
const *src = from.
data[0];
230 : num_rows(A.num_rows), num_cols(A.num_cols)
241 T
const *a = A.
data[0];
242 T
const *b = B.
data[0];
243 T *dst = this->
data[0];
245 for (
unsigned int i=0; i<n; ++i)
246 dst[i] = T(a[i] + b[i]);
251 : num_rows(A.num_rows), num_cols(A.num_cols)
262 T
const *a = A.
data[0];
263 T
const *b = B.
data[0];
264 T *dst = this->
data[0];
266 for (
unsigned int i=0; i<n; ++i)
267 dst[i] = T(a[i] - b[i]);
272 : num_rows(M.num_rows), num_cols(M.num_cols)
278 T
const *
m = M.
data[0];
279 T *dst = this->
data[0];
281 for (
unsigned int i=0; i<n; ++i)
282 dst[i] = T(
m[i] * s);
287 : num_rows(M.num_rows), num_cols(M.num_cols)
293 T
const *
m = M.
data[0];
294 T *dst = this->
data[0];
296 for (
unsigned int i=0; i<n; ++i)
297 dst[i] = T(
m[i] / s);
302 : num_rows(M.num_rows), num_cols(M.num_cols)
308 T
const *
m = M.
data[0];
309 T *dst = this->
data[0];
311 for (
unsigned int i=0; i<n; ++i)
312 dst[i] = T(
m[i] + s);
317 : num_rows(M.num_rows), num_cols(M.num_cols)
323 T
const *
m = M.
data[0];
324 T *dst = this->
data[0];
326 for (
unsigned int i=0; i<n; ++i)
327 dst[i] = T(
m[i] - s);
332 : num_rows(A.num_rows), num_cols(B.num_cols)
346 for (
unsigned int i=0; i<l; ++i) {
347 for (
unsigned int k=0; k<n; ++k) {
349 for (
unsigned int j=0; j<
m; ++j)
350 sum += T(A.
data[i][j] * B.
data[j][k]);
351 this->
data[i][k] = sum;
394 if (this->num_rows == rowz && this->num_cols == colz)
399 this->num_rows = rowz; this->num_cols = colz;
404 this->num_rows = rowz; this->num_cols = colz;
411 #undef vnl_matrix_alloc_blah 412 #undef vnl_matrix_free_blah 423 std::fill_n( this->data[0], this->num_rows * this->num_cols, value );
432 for (
unsigned int i = 0; i < this->num_rows && i < this->num_cols; ++i)
433 this->data[i][i] = value;
442 assert(diag.
size() >= this->num_rows ||
443 diag.
size() >= this->num_cols);
447 for (
unsigned int i = 0; i < this->num_rows && i < this->num_cols; ++i)
448 this->data[i][i] = diag[i];
457 #if VNL_CONFIG_CHECK_BOUNDS 461 return this->data[r][c];
469 #if VNL_CONFIG_CHECK_BOUNDS 473 return this->data[r][c];
488 std::copy( rhs.
data[0], rhs.
data[0] + this->num_rows * this->num_cols, this->data[0] );
502 for (
unsigned int i = 0; i < this->rows(); i++) {
503 for (
unsigned int j = 0; j < this->columns(); j++)
504 os << this->data[i][j] <<
' ';
515 for (
unsigned int i = 0; i <
m.rows(); ++i) {
516 for (
unsigned int j = 0; j <
m.columns(); ++j)
517 os <<
m(i, j) <<
' ';
535 for (
unsigned int i = 0; i < this->num_rows; i++)
536 for (
unsigned int j = 0; j < this->num_cols; j++)
537 this->data[i][j] += value;
544 for (
unsigned int i = 0; i < this->num_rows; i++)
545 for (
unsigned int j = 0; j < this->num_cols; j++)
546 this->data[i][j] -= value;
553 for (
unsigned int i = 0; i < this->num_rows; i++)
554 for (
unsigned int j = 0; j < this->num_cols; j++)
555 this->data[i][j] *= value;
562 for (
unsigned int i = 0; i < this->num_rows; i++)
563 for (
unsigned int j = 0; j < this->num_cols; j++)
564 this->data[i][j] /= value;
576 if (this->num_rows != rhs.
num_rows ||
579 this->num_rows, this->num_cols,
582 for (
unsigned int i = 0; i < this->num_rows; i++)
583 for (
unsigned int j = 0; j < this->num_cols; j++)
584 this->data[i][j] += rhs.
data[i][j];
597 if (this->num_rows != rhs.
num_rows ||
600 this->num_rows, this->num_cols,
603 for (
unsigned int i = 0; i < this->num_rows; i++)
604 for (
unsigned int j = 0; j < this->num_cols; j++)
605 this->data[i][j] -= rhs.
data[i][j];
614 for (
unsigned int i = 0; i <
m.rows(); i++)
615 for (
unsigned int j = 0; j <
m.columns(); j++)
616 result.
put(i,j, T(value -
m.get(i,j)) );
627 for (
unsigned int i = 0; i < this->num_rows; i++)
628 for (
unsigned int j = 0; j < this->num_cols; j++)
629 result.
data[i][j] = - this->data[i][j];
658 for (
unsigned int i = 0; i < this->num_rows; ++i)
659 v.put(i,f(this->get_row(i)));
670 for (
unsigned int i = 0; i < this->num_cols; ++i)
671 v.put(i,f(this->get_column(i)));
685 for (
unsigned int i = 0; i < this->num_cols; i++)
686 for (
unsigned int j = 0; j < this->num_rows; j++)
687 result.
data[i][j] = this->data[j][i];
708 unsigned top,
unsigned left)
710 unsigned int bottom = top +
m.num_rows;
711 unsigned int right = left +
m.num_cols;
713 if (this->num_rows < bottom || this->num_cols < right)
715 bottom, right,
m.num_rows,
m.num_cols);
717 for (
unsigned int i = top; i < bottom; i++)
718 for (
unsigned int j = left; j < right; j++)
719 this->data[i][j] =
m.data[i-top][j-left];
729 unsigned top,
unsigned left)
const {
731 this->extract( result, top, left );
737 unsigned top,
unsigned left)
const {
738 unsigned const rowz = submatrix.
rows();
739 unsigned const colz = submatrix.
cols();
741 unsigned int bottom = top + rowz;
742 unsigned int right = left + colz;
743 if ((this->num_rows < bottom) || (this->num_cols < right))
745 this->num_rows, this->num_cols, bottom, right);
747 for (
unsigned int i = 0; i < rowz; i++)
748 for (
unsigned int j = 0; j < colz; j++)
749 submatrix.
data[i][j] = data[top+i][left+j];
809 for (
unsigned int i = 0; i < m1.
rows(); i++)
810 for (
unsigned int j = 0; j < m1.
columns(); j++)
811 result.
put(i,j, T(m1.
get(i,j) * m2.
get(i,j)) );
828 for (
unsigned int i = 0; i < m1.
rows(); i++)
829 for (
unsigned int j = 0; j < m1.
columns(); j++)
830 result.
put(i,j, T(m1.
get(i,j) / m2.
get(i,j)) );
839 std::copy( p, p + this->num_rows * this->num_cols, this->data[0] );
848 std::copy( this->data[0], this->data[0] + this->num_rows * this->num_cols, p );
855 for (
unsigned int i = 0; i < this->num_rows; ++i)
856 for (
unsigned int j = 0; j < this->num_cols; ++j)
857 this->data[i][j] = (i==j) ? T(1) : T(0);
869 for (
unsigned int i = 0; i < this->num_rows; ++i) {
871 for (
unsigned int j = 0; j < this->num_cols; ++j)
875 abs_real_t scale = abs_real_t(1)/(std::sqrt((abs_real_t)norm));
876 for (
unsigned int j = 0; j < this->num_cols; ++j)
877 this->data[i][j] = T(Real_t(this->data[i][j]) * scale);
891 for (
unsigned int j = 0; j < this->num_cols; j++) {
893 for (
unsigned int i = 0; i < this->num_rows; i++)
897 abs_real_t scale = abs_real_t(1)/(std::sqrt((abs_real_t)norm));
898 for (
unsigned int i = 0; i < this->num_rows; i++)
899 this->data[i][j] = T(Real_t(this->data[i][j]) * scale);
910 if (row_index >= this->num_rows)
913 for (
unsigned int j = 0; j < this->num_cols; j++)
914 this->data[row_index][j] *= value;
923 if (column_index >= this->num_cols)
926 for (
unsigned int j = 0; j < this->num_rows; j++)
927 this->data[j][column_index] *= value;
936 if (row + n > this->num_rows)
949 if (column + n > this->num_cols)
954 for (
unsigned int c = 0; c < n; ++c)
955 for (
unsigned int r = 0; r < this->num_rows; ++r)
956 result(r, c) = data[r][column + c];
964 #ifdef ERROR_CHECKING 965 if (row_index >= this->num_rows)
970 for (
unsigned int j = 0; j < this->num_cols; j++)
971 v[j] = this->data[row_index][j];
979 #ifdef ERROR_CHECKING 980 if (column_index >= this->num_cols)
985 for (
unsigned int j = 0; j < this->num_rows; j++)
986 v[j] = this->data[j][column_index];
997 for (
unsigned int j = 0; j < i.
size(); ++j)
998 m.set_row(j, this->get_row(i.
get(j)));
1009 for (
unsigned int j = 0; j < i.
size(); ++j)
1010 m.set_column(j, this->get_column(i.
get(j)));
1018 vnl_vector<T> v(this->num_rows < this->num_cols ? this->num_rows : this->num_cols);
1019 for (
unsigned int j = 0; j < this->num_rows && j < this->num_cols; ++j)
1020 v[j] = this->data[j][j];
1029 v.copy_in(this->data_block());
1038 for (
unsigned int c = 0; c < this->num_cols; ++c)
1039 for (
unsigned int r = 0; r < this->num_rows; ++r)
1040 v[c*this->num_rows+r] = this->data[r][c];
1050 for (
unsigned int j = 0; j < this->num_cols; j++)
1051 this->data[row_index][j] =
v[j];
1060 if (
v.size() != this->num_cols)
1063 set_row(row_index,
v.data_block());
1071 for (
unsigned int j = 0; j < this->num_cols; j++)
1072 this->data[row_index][j] =
v;
1082 for (
unsigned int i = 0; i < this->num_rows; i++)
1083 this->data[i][column_index] =
v[i];
1092 if (
v.size() != this->num_rows)
1095 set_column(column_index,
v.data_block());
1103 for (
unsigned int j = 0; j < this->num_rows; j++)
1104 this->data[j][column_index] =
v;
1114 if (this->num_rows !=
m.num_rows ||
1115 this->num_cols <
m.num_cols + starting_column)
1117 this->num_rows, this->num_cols,
1118 m.num_rows,
m.num_cols);
1121 for (
unsigned int j = 0; j <
m.num_cols; ++j)
1122 for (
unsigned int i = 0; i < this->num_rows; i++)
1123 this->data[i][starting_column + j] =
m.data[i][j];
1144 for (
unsigned int i = 0; i < this->num_rows; i++)
1145 for (
unsigned int j = 0; j < this->num_cols; j++)
1146 if (!(this->data[i][j] == rhs.
data[i][j]))
1161 for (
unsigned int i = 0; i < this->rows(); ++i)
1162 for (
unsigned int j = 0; j < this->columns(); ++j)
1175 for (
unsigned int i = 0; i < this->rows(); ++i)
1176 for (
unsigned int j = 0; j < this->columns(); ++j) {
1177 T xm = (*this)(i,j);
1178 if ( !((i == j) ? (xm == one) : (xm == zero)) )
1189 for (
unsigned int i = 0; i < this->rows(); ++i)
1190 for (
unsigned int j = 0; j < this->columns(); ++j) {
1191 T xm = (*this)(i,j);
1203 for (
unsigned int i = 0; i < this->rows(); ++i)
1204 for (
unsigned int j = 0; j < this->columns(); ++j)
1205 if ( !( (*
this)(i, j) == zero) )
1215 for (
unsigned int i = 0; i < this->rows(); ++i)
1216 for (
unsigned int j = 0; j < this->columns(); ++j)
1227 for (
unsigned int i = 0; i < this->rows(); ++i)
1228 for (
unsigned int j = 0; j < this->columns(); ++j)
1239 for (
unsigned int i = 0; i < this->rows(); ++i)
1240 for (
unsigned int j = 0; j < this->columns(); ++j)
1254 std::cerr <<
"\n\n" __FILE__
": " << __LINE__ <<
": matrix has non-finite elements\n";
1256 if (rows() <= 20 && cols() <= 20) {
1257 std::cerr << __FILE__
": here it is:\n" << *
this;
1260 std::cerr << __FILE__
": it is quite big (" << rows() <<
'x' << cols() <<
")\n" 1261 << __FILE__
": in the following picture '-' means finite and '*' means non-finite:\n";
1263 for (
unsigned int i=0; i<rows(); ++i) {
1264 for (
unsigned int j=0; j<cols(); ++j)
1269 std::cerr << __FILE__
": calling abort()\n";
1277 if (this->rows()!=rs || this->cols()!=cs) {
1278 std::cerr << __FILE__
": size is " << this->rows() <<
'x' << this->cols()
1279 <<
". should be " << rs <<
'x' << cs << std::endl;
1290 std::cerr << __FILE__
": vnl_matrix<T>::read_ascii: Called with bad stream\n";
1294 bool size_known = (this->rows() != 0);
1297 for (
unsigned int i = 0; i < this->rows(); ++i)
1298 for (
unsigned int j = 0; j < this->columns(); ++j)
1299 s >> this->data[i][j];
1301 return s.good() || s.eof();
1306 std::vector<T> first_row_vals;
1308 std::cerr << __FILE__
": vnl_matrix<T>::read_ascii: Determining file dimensions: ";
1317 if (!std::isspace(c)) {
1318 if (!s.putback(
char(c)).good())
1319 std::cerr <<
"vnl_matrix<T>::read_ascii: Could not push back '" << c <<
"'\n";
1324 if (c ==
'\n' && first_row_vals.size() > 0) {
1332 first_row_vals.push_back(val);
1337 std::size_t colz = first_row_vals.size();
1339 if (debug) std::cerr << colz <<
" cols, ";
1346 std::vector<T*> row_vals;
1347 row_vals.reserve(1000);
1351 for (
unsigned int k = 0; k < colz; ++k)
1352 row[k] = first_row_vals[k];
1353 row_vals.push_back(row);
1359 if (row ==
nullptr) {
1360 std::cerr <<
"vnl_matrix<T>::read_ascii: Error, Out of memory on row " 1361 << row_vals.size() << std::endl;
1370 for (
unsigned int k = 1; k < colz; ++k) {
1372 std::cerr <<
"vnl_matrix<T>::read_ascii: Error, EOF on row " 1373 << row_vals.size() <<
", column " << k << std::endl;
1379 std::cerr <<
"vnl_matrix<T>::read_ascii: Error, row " 1380 << row_vals.size() <<
" failed on column " << k << std::endl;
1384 row_vals.push_back(row);
1387 std::size_t rowz = row_vals.size();
1390 std::cerr << rowz <<
" rows.\n";
1392 set_size((
unsigned int)rowz, (
unsigned int)colz);
1394 T* p = this->data[0];
1395 for (
unsigned int i = 0; i < rowz; ++i) {
1396 for (
unsigned int j = 0; j < colz; ++j)
1397 *p++ = row_vals[i][j];
1431 const unsigned int n = this->rows();
1432 const unsigned int colz = this->columns();
1434 const unsigned int m = n / 2;
1435 for (
unsigned int r = 0; r <
m; ++r) {
1436 const unsigned int r1 = r;
1437 const unsigned int r2 = n - 1 - r;
1438 for (
unsigned int c = 0; c < colz; ++c) {
1439 const T tmp = (*this)(r1, c);
1440 (*this)(r1, c) = (*
this)(r2, c);
1441 (*this)(r2, c) = tmp;
1451 const unsigned int n = this->cols();
1452 const unsigned int rowz = this->rows();
1454 const unsigned int m = n / 2;
1455 for (
unsigned int c = 0; c <
m; ++c) {
1456 const unsigned int c1 = c;
1457 const unsigned int c2 = n - 1 - c;
1458 for (
unsigned int r = 0; r < rowz; ++r) {
1459 const T tmp = (*this)(r, c1);
1460 (*this)(r, c1) = (*
this)(r, c2);
1461 (*this)(r, c2) = tmp;
1473 for (
unsigned int j=0; j<this->num_cols; ++j) {
1475 for (
unsigned int i=0; i<this->num_rows; ++i)
1489 for (
unsigned int i=0; i<this->num_rows; ++i) {
1491 for (
unsigned int j=0; j<this->num_cols; ++j)
1499 template <
class doublereal>
1504 int iter, i1, i2, im, i1c, i2c, ncount, max_;
1528 for (
unsigned i = 0; i < n; ++i)
1529 for (
unsigned j = i+1; j < n; ++j) {
1539 for (
unsigned i = 0; i < iwrk; ++i)
1541 if (
m > 2 && n > 2) {
1545 int ir0 = ir2 % ir1;
1570 if (iter <= (
int)iwrk) {
1576 while (i2 > iter && i2 < max_) {
1578 i2 =
m * i1 - k * (i1 / n);
1589 i2 =
m * i1 - k * (i1 / n);
1591 if (i1 <= (
int)iwrk)
1593 if (i1c <= (
int)iwrk)
1599 doublereal d = b; b = c; c = d;
1621 unsigned m = rows();
1622 unsigned n = columns();
1623 unsigned iwrk = (
m+n)/2;
1624 std::vector<char> move(iwrk);
1628 std::cerr << __FILE__
" : inplace_transpose() -- iok = " << iok <<
'\n';
1639 for (
unsigned i=0; i<n; ++i)
1640 data[i] = tmp + i *
m;
1647 #define VNL_MATRIX_INSTANTIATE(T) \ 1648 template class VNL_EXPORT vnl_matrix<T >; \ 1649 template VNL_EXPORT vnl_matrix<T > operator-(T const &, vnl_matrix<T > const &); \ 1652 template VNL_EXPORT T dot_product(vnl_matrix<T > const &, vnl_matrix<T > const &); \ 1653 template VNL_EXPORT T inner_product(vnl_matrix<T > const &, vnl_matrix<T > const &); \ 1654 template VNL_EXPORT T cos_angle(vnl_matrix<T > const &, vnl_matrix<T > const &); \ 1655 template VNL_EXPORT vnl_matrix<T > element_product(vnl_matrix<T > const &, vnl_matrix<T > const &); \ 1656 template VNL_EXPORT vnl_matrix<T > element_quotient(vnl_matrix<T > const &, vnl_matrix<T > const &); \ 1657 template VNL_EXPORT int vnl_inplace_transpose(T*, unsigned, unsigned, char*, unsigned); \ 1658 template VNL_EXPORT std::ostream & operator<<(std::ostream &, vnl_matrix<T > const &); \ 1659 template VNL_EXPORT std::istream & operator>>(std::istream &, vnl_matrix<T > &) 1661 #endif // vnl_matrix_hxx_ vnl_matrix< T > & operator=(T const &v)
Set all elements to value v.
static void deallocate(T **, const std::size_t n_when_allocated)
vnl_c_vector< std::complex< double > >::abs_t abs_t
Type def for norms.
vnl_matrix & set_diagonal(vnl_vector< T > const &)
Sets the diagonal elements of this matrix to the specified list of values.
vnl_vector_fixed< T, n > element_quotient(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
unsigned int cols() const
Return the number of columns.
vnl_matrix< T > get_columns(vnl_vector< unsigned int > i) const
Get a matrix composed of columns from the indices specified in the supplied vector.
T & operator()(unsigned r, unsigned c)
Access an element for reading or writing.
vnl_matrix()
Default constructor creates an empty matrix of size 0,0.
bool is_zero() const
Return true if all elements equal to zero.
static void conjugate(T const *, T *, unsigned)
vnl_matrix & copy_in(T const *)
Fills (laminates) this matrix with the given data, then returns it.
bool has_nans() const
Return true if matrix contains NaNs.
vnl_matrix & fill_diagonal(T const &)
Sets all diagonal elements of matrix to specified value; returns "*this".
void swap(double &a, double &b)
An ordinary mathematical matrix.
vnl_matrix< T > get_n_columns(unsigned colstart, unsigned n) const
Get n columns beginning at colstart.
vnl_matrix< T > conjugate_transpose() const
Return conjugate transpose.
vnl_matrix< T > & operator+=(T value)
Add rhs to each element of lhs matrix in situ.
vnl_vector< T > apply_rowwise(T(*f)(vnl_vector< T > const &)) const
Make a vector by applying a function across rows.
vnl_matrix< T > transpose() const
Return transpose.
vnl_vector< T > flatten_row_major() const
Flatten row-major (C-style).
vnl_matrix & scale_row(unsigned row, T value)
Scales elements in given row by a factor T, and returns "*this".
vnl_matrix< T > operator-() const
Negate all elements of matrix.
Templated zero/one/precision.
vnl_matrix< T > extract(unsigned r, unsigned c, unsigned top=0, unsigned left=0) const
Extract a sub-matrix of size r x c, starting at (top,left).
vnl_vector_fixed< T, n > element_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
size_t size() const
Return the length, number of elements, dimension of this vector.
#define vnl_matrix_alloc_blah()
vnl_matrix< T > & operator *=(T value)
Scalar multiplication in situ of lhs matrix by rhs.
Namespace with standard math functions.
iterator begin()
Iterator pointing to start of data.
void vnl_error_matrix_row_index(char const *fcn, int r)
Raise exception for invalid row index.
abs_t operator_one_norm() const
void vnl_error_matrix_col_index(char const *fcn, int c)
Raise exception for invalid col index.
enum VNL_EXPORT vnl_matrix_type
vnl_bignum squared_magnitude(vnl_bignum const &x)
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
static void apply(T const *, unsigned, T(*f)(T), T *v_out)
vnl_matrix & normalize_rows()
Normalizes each row so it is a unit vector, and returns "*this".
T get(unsigned r, unsigned c) const
get element with boundary checks if error checking is on.
vnl_matrix< T > & operator-=(T value)
Subtract rhs from each element of lhs matrix in situ.
vnl_matrix & normalize_columns()
Normalizes each column so it is a unit vector, and returns "*this".
vnl_matrix & inplace_transpose()
Transposes this matrix efficiently, and returns it.
void vnl_error_vector_dimension(char const *fcn, int l1, int l2)
Raise exception for invalid dimension.
bool isnan(vnl_bignum const &)
void assert_size_internal(unsigned r, unsigned c) const
Abort unless M has the given size.
vnl_matrix & set_column(unsigned i, T const *v)
Set the elements of the i'th column to v[i] (No bounds checking).
vnl_matrix< T > get_rows(vnl_vector< unsigned int > i) const
Get a matrix composed of rows from the indices specified in the supplied vector.
int vnl_inplace_transpose(doublereal *a, unsigned m, unsigned n, char *move, unsigned iwrk)
void assert_finite_internal() const
Abort if any element of M is inf or nan.
vnl_matrix< T > get_n_rows(unsigned rowstart, unsigned n) const
Get n rows beginning at rowstart.
static T * allocate_T(const std::size_t n)
vnl_matrix< T > & operator/=(T value)
Scalar division of lhs matrix in situ by rhs.
An ordinary mathematical matrix.
bool is_identity() const
Return true if all elements equal to identity.
void clear()
Make the matrix as if it had been default-constructed.
vnl_matrix & fill(T const &)
Sets all elements of matrix to specified value, and returns "*this".
static T inner_product(T const *, T const *, unsigned)
conjugate second.
vnl_matrix & flipud()
Reverses the order of rows, and returns "*this".
bool isfinite(vnl_bignum const &x)
T dot_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
static T ** allocate_Tptr(const std::size_t n)
Memory allocation.
void swap(vnl_matrix< T > &that)
Swap this matrix with that matrix.
void print(std::ostream &os) const
Print matrix to os in some hopefully sensible format.
vnl_decnum max(vnl_decnum const &x, vnl_decnum const &y)
Mathematical vector class, templated by type of element.
abs_t operator_inf_norm() const
T const * data_block() const
Access the contiguous block storing the elements in the matrix row-wise. O(1).
#define vnl_matrix_construct_hack()
vnl_vector< T > get_column(unsigned c) const
Get a vector equal to the given column.
bool operator_eq(vnl_matrix< T > const &rhs) const
Return true if *this == rhs.
vnl_matrix & set_columns(unsigned starting_column, vnl_matrix< T > const &M)
Set columns to those in M, starting at starting_column, then return *this.
vnl_vector< T > flatten_column_major() const
Flatten column-major (Fortran-style).
T cos_angle(vnl_matrix< T > const &a, vnl_matrix< T > const &b)
vnl_vector< T > get_row(unsigned r) const
Get a vector equal to the given row.
static vnl_matrix< T > read(std::istream &s)
Read a vnl_matrix from an ascii std::istream, automatically determining file size if the input matrix...
vnl_matrix & set_row(unsigned i, T const *v)
Set the elements of the i'th row to v[i] (No bounds checking).
vnl_bignum abs(vnl_bignum const &x)
unsigned int size() const
Return the total number of elements stored by the matrix.
void vnl_error_matrix_dimension(char const *fcn, int r1, int c1, int r2, int c2)
Raise exception for invalid dimensions.
void destroy()
Delete data.
vnl_vector< T > apply_columnwise(T(*f)(vnl_vector< T > const &)) const
Make a vector by applying a function across columns.
unsigned int rows() const
Return the number of rows.
bool is_equal(vnl_matrix< T > const &rhs, double tol) const
Return true if all elements of both matrices are equal, within given tolerance.
VNL_EXPORT std::istream & operator>>(std::istream &s, vnl_decnum &r)
decimal input.
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
vnl_matrix< T > apply(T(*f)(T)) const
Make a new matrix by applying function to each element.
bool is_finite() const
Return true if finite.
T inner_product(vnl_matrix< T > const &m1, vnl_matrix< T > const &m2)
Hermitian inner product.
vnl_matrix & scale_column(unsigned col, T value)
Scales elements in given column by a factor T, and returns "*this".
vnl_vector< T > get_diagonal() const
Return a vector with the content of the (main) diagonal.
bool set_size(unsigned r, unsigned c)
Resize to r rows by c columns. Old data lost.
bool read_ascii(std::istream &s)
Read a vnl_matrix from an ascii std::istream.
static T dot_product(T const *, T const *, unsigned)
void copy_out(T *) const
Fills the given array with this matrix.
vnl_matrix< T > & update(vnl_matrix< T > const &, unsigned top=0, unsigned left=0)
Set values of this matrix to those of M, starting at [top,left].
~vnl_matrix()
Matrix destructor.
T get(size_t i) const
Get value at element i.
unsigned int columns() const
Return the number of columns.
Math on blocks of memory.
vnl_matrix & set_identity()
Sets this matrix to an identity matrix, then returns "*this".
#define vnl_matrix_free_blah
void put(unsigned r, unsigned c, T const &)
set element with boundary checks if error checking is on.
vnl_matrix & fliplr()
Reverses the order of columns, and returns "*this".