2 #ifndef vnl_matrix_fixed_ref_h_ 3 #define vnl_matrix_fixed_ref_h_ 144 # include <vcl_msvc_warnings.h> 150 #include "vnl/vnl_export.h" 169 template <
class T,
unsigned num_rows,
unsigned num_cols>
176 : data_(rhs.data_block())
191 for (
unsigned int j = 0; j < num_cols; j++)
192 v[j] = (*
this)(row_index,j);
200 for (
unsigned int j = 0; j < num_rows; j++)
201 v[j] = (*
this)(j,column_index);
208 const T * data_block()
const {
return data_; }
222 T
const & operator() (
unsigned r,
unsigned c)
const 224 #if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG) 228 return *(data_ + num_cols * r + c);
233 T
const * operator[] (
unsigned r)
const {
return data_ + num_cols * r; }
236 unsigned rows()
const {
return num_rows; }
240 unsigned columns()
const {
return num_cols; }
244 unsigned cols()
const {
return num_cols; }
248 unsigned size()
const {
return num_rows*num_cols; }
251 void print(std::ostream& os)
const;
253 void copy_out(T *)
const;
272 unsigned top=0,
unsigned left=0)
const;
275 vnl_matrix<T> get_n_rows (
unsigned rowstart,
unsigned n)
const;
278 vnl_matrix<T> get_n_columns(
unsigned colstart,
unsigned n)
const;
293 abs_t absolute_value_sum()
const {
return array_one_norm(); }
296 abs_t absolute_value_max()
const {
return array_inf_norm(); }
299 abs_t operator_one_norm()
const;
302 abs_t operator_inf_norm()
const;
308 abs_t fro_norm()
const {
return frobenius_norm(); }
331 bool empty()
const {
return num_rows==0 && num_cols==0; }
334 bool is_identity()
const;
337 bool is_identity(
double tol)
const;
340 bool is_zero()
const;
343 bool is_zero(
double tol)
const;
346 bool is_finite()
const;
349 bool has_nans()
const;
354 void assert_size(
unsigned rowz,
unsigned colz)
const 356 void assert_size(
unsigned ,
unsigned )
const 360 assert_size_internal(rowz, colz);
365 void assert_finite()
const 368 assert_finite_internal();
387 assert(!
"Assignment is illegal for a vnl_matrix_fixed_ref_const");
391 void assert_finite_internal()
const;
393 void assert_size_internal(
unsigned,
unsigned)
const;
397 template <
class T,
unsigned num_rows,
unsigned num_cols>
406 return const_cast<T*>(this->data_);
409 : base(rhs.data_block())
427 void put (
unsigned r,
unsigned c, T
const&
v) { (*this)(r,c) =
v; }
430 T get (
unsigned r,
unsigned c)
const {
return (*
this)(r,c); }
440 #if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG) 444 return *(this->
data_block() + num_cols * r + c);
551 assert(
m.rows() == num_rows &&
m.cols() == num_cols );
564 assert(
m.rows() == num_rows &&
m.cols() == num_cols );
580 for (
unsigned i = 0; i < num_rows; ++i)
581 for (
unsigned j = 0; j < num_cols; ++j)
584 for (
unsigned k = 1; k < num_cols; ++k)
585 accum += this->
operator()(i,k) * s(k,j);
701 bool read_ascii(std::istream& s)
const;
770 template<
class T,
unsigned m,
unsigned n>
779 template<
class T,
unsigned m,
unsigned n>
788 template<
class T,
unsigned m,
unsigned n>
797 template<
class T,
unsigned m,
unsigned n>
806 template<
class T,
unsigned m,
unsigned n>
815 template<
class T,
unsigned m,
unsigned n>
824 template<
class T,
unsigned m,
unsigned n>
833 template<
class T,
unsigned m,
unsigned n>
842 template<
class T,
unsigned m,
unsigned n>
852 template<
class T,
unsigned m,
unsigned n>
863 template<
class T,
unsigned m,
unsigned n>
877 template <
class T,
unsigned M,
unsigned N>
884 for (
unsigned i = 0; i < M; ++i)
886 T accum = a(i,0) * b(0);
887 for (
unsigned k = 1; k < N; ++k)
888 accum += a(i,k) * b(k);
895 template <
class T,
unsigned M,
unsigned N,
unsigned O>
902 for (
unsigned i = 0; i < M; ++i)
903 for (
unsigned j = 0; j < O; ++j)
905 T accum = a(i,0) * b(0,j);
906 for (
unsigned k = 1; k < N; ++k)
907 accum += a(i,k) * b(k,j);
918 template <
class T,
unsigned M,
unsigned N>
927 template <
class T,
unsigned M,
unsigned N,
unsigned O>
938 template<
class T,
unsigned m,
unsigned n>
941 return a.as_ref() + b;
944 template<
class T,
unsigned m,
unsigned n>
947 return a + b.as_ref();
950 template<
class T,
unsigned m,
unsigned n>
953 return a.as_ref() - b;
956 template<
class T,
unsigned m,
unsigned n>
959 return a - b.as_ref();
962 template<
class T,
unsigned m,
unsigned n>
965 return a.as_ref() * b;
968 template<
class T,
unsigned m,
unsigned n>
971 return a * b.as_ref();
974 template<
class T,
unsigned m,
unsigned n>
977 return a.as_ref() * b;
980 template<
class T,
unsigned n>
989 template<
class T,
unsigned m,
unsigned n>
997 template<
class T,
unsigned m,
unsigned n>
1005 #endif // vnl_matrix_fixed_ref_h_
vnl_vector_fixed< T, n > element_quotient(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
vnl_matrix_fixed< T, M, O > vnl_matrix_fixed_mat_mat_mult(const vnl_matrix_fixed_ref_const< T, M, N > &a, const vnl_matrix_fixed_ref_const< T, N, O > &b)
vnl_vector_fixed< T, M > vnl_matrix_fixed_mat_vec_mult(const vnl_matrix_fixed_ref_const< T, M, N > &a, const vnl_vector_fixed_ref_const< T, N > &b)
Fixed size vnl_vector using user-supplied storage See vnl_matrix_fixed_ref for rationale.
const vnl_matrix_fixed_ref_const< T, num_rows, num_cols > & operator=(const vnl_matrix_fixed_ref_const< T, num_rows, num_cols > &) const
static unsigned arg_min(T const *, unsigned)
Returns location of min value of the vector.
T const * operator[](unsigned r) const
return pointer to given row.
T const * data_block() const
Access the contiguous block storing the elements in the matrix row-wise. O(1).
bool read_ascii(std::istream &s) const
const_iterator begin() const
Iterator pointing to start of data.
static void mul(const T *a, const T *b, T *r)
vnl_vector_fixed< T, n > element_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
static abs_t rms_norm(T const *p, unsigned n)
rms_norm : sqrt of mean sum of squared abs values.
static void sub(const T *a, const T *b, T *r)
void add(const vnl_bignum &b1, const vnl_bignum &b2, vnl_bignum &sum)
add two non-infinite vnl_bignum values and save their sum.
Fixed size, stack-stored, space-efficient matrix.
const_iterator end() const
Iterator pointing to element beyond end of data.
static bool equal(const T *a, const T *b)
static abs_t one_norm(T const *p, unsigned n)
one_norm : sum of abs values.
static abs_t two_norm(T const *p, unsigned n)
two_norm : sqrt of sum of squared abs values.
static void div(const T *a, T b, T *r)
T const * const_iterator
Const iterators.
vnl_c_vector< T >::abs_t abs_t
Type def for norms.
const T * data_block() const
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
vnl_matrix_fixed< T, m, n > operator-(const vnl_matrix_fixed_ref_const< T, m, n > &mat1, const vnl_matrix_fixed_ref_const< T, m, n > &mat2)
static unsigned arg_max(T const *, unsigned)
Returns location of max value of the vector.
static T min_value(T const *, unsigned)
Returns min value of the vector.
An ordinary mathematical matrix.
static T mean(T const *p, unsigned n)
bool operator!=(long r1, vnl_bignum const &r2)
unsigned size() const
Return number of elements.
static bool equal(const T *a, const T *b)
static void add(const T *a, T b, T *r)
vnl_numeric_traits< T >::abs_t abs_t
T const & operator()(unsigned r, unsigned c) const
Mathematical vector class, templated by type of element.
Fixed length stack-stored, space-efficient vector.
Fixed length stack-stored vector.
void print(std::ostream &os) const
Print matrix to os in some hopefully sensible format.
const T element_type
Type defs for iterators.
VNL_EXPORT std::istream & operator>>(std::istream &s, vnl_decnum &r)
decimal input.
bool operator==(const vnl_amoeba_SimplexCorner &a, const vnl_amoeba_SimplexCorner &b)
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
static void mul(const T *a, T b, T *r)
static T max_value(T const *, unsigned)
Returns max value of the vector.
static void sub(T a, const T *b, T *r)
static void sub(const T *a, T b, T *r)
const T * iterator
Type defs for iterators.
static void div(const T *a, const T *b, T *r)
vnl_bignum operator/(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the division of two bignum numbers.
vnl_matrix reference to user-supplied storage.
vnl_bignum operator *(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the product of two bignum numbers.
Fixed size stack-stored vnl_matrix.
Math on blocks of memory.
static abs_t inf_norm(T const *p, unsigned n)
inf_norm : max of abs values.
static void add(const T *a, const T *b, T *r)
const vnl_vector_ref< T > as_ref() const
Explicit conversion to a vnl_vector_ref.