vnl_matops.cxx
Go to the documentation of this file.
1 // This is core/vnl/vnl_matops.cxx
2 //:
3 // \file
4 // \author Andrew W. Fitzgibbon, Oxford RRG
5 // \date 05 Aug 96
6 //
7 //-----------------------------------------------------------------------------
8 
9 #include "vnl_matops.h"
10 #include <cassert>
11 
13 {
14  assert(A.rows() == B.rows());
15 
16  vnl_matrix<double> M(A.rows(),A.columns()+B.columns());
17  M.update(A,0,0);
18  M.update(B,0,A.columns());
19 
20  return M;
21 }
22 
24 {
25  assert(A.rows() == B.size());
26 
27  vnl_matrix<double> M(A.rows(),A.columns()+1);
28  M.update(A,0,0);
29  M.set_column(A.columns(),B);
30 
31  return M;
32 }
33 
35 {
36  assert(A.size() == B.rows());
37 
38  vnl_matrix<double> M(B.rows(),B.columns()+1);
39  M.set_column(0,A);
40  M.update(B,0,1);
41 
42  return M;
43 }
44 
46 {
47  assert(A.columns() == B.columns());
48 
49  vnl_matrix<double> M(A.rows()+B.rows(),A.columns());
50  M.update(A,0,0);
51  M.update(B,A.rows(),0);
52 
53  return M;
54 }
55 
56 //: Return fro_norm( (A ./ B) - mean(A ./ B) )
58 {
60 
61  return (ratio - ratio.mean()).fro_norm();
62 }
63 
64 #define implement_converters(U,V) \
65 vnl_matrix<U> make_matrix_ ## U(vnl_matrix<V> const& M) \
66 { \
67  unsigned m = M.rows(); \
68  unsigned n = M.columns(); \
69  vnl_matrix<U> ret(m, n); \
70  for (unsigned i = 0; i < m; ++i) \
71  for (unsigned j = 0; j < n; ++j) \
72  ret(i,j) = static_cast<U>(M(i,j)); \
73  return ret; \
74 } \
75  \
76 vnl_vector<U> make_vector_ ## U(vnl_vector<V> const& v) \
77 { \
78  unsigned n = v.size(); \
79  vnl_vector<U> ret(n); \
80  for (unsigned i = 0; i < n; ++i) \
81  ret[i] = static_cast<U>(v[i]); \
82  return ret; \
83 } \
84 
85 implement_converters(double,float)
86 
87 implement_converters(float,double)
88 
89 vnl_matrix<double> vnl_matops::f2d(vnl_matrix<float> const& M)
90 {
91  return make_matrix_double(M);
92 }
93 
95 {
96  return make_matrix_float(M);
97 }
98 
100 {
101  return make_vector_double(M);
102 }
105 {
106  return make_vector_float(M);
107 }
static double homg_diff(vnl_matrix< double > const &A, vnl_matrix< double > const &B)
Return fro_norm( (A .
Definition: vnl_matops.cxx:56
#define implement_converters(U, V)
Definition: vnl_matops.cxx:63
size_t size() const
Return the length, number of elements, dimension of this vector.
Definition: vnl_vector.h:126
static vnl_matrix< float > d2f(vnl_matrix< double > const &)
Definition: vnl_matops.cxx:93
A collection of Matrix operations.
vnl_matrix & set_column(unsigned i, T const *v)
Set the elements of the i'th column to v[i] (No bounds checking).
static vnl_matrix< double > cat(vnl_matrix< double > const &A, vnl_matrix< double > const &B)
Laminating.
Definition: vnl_matops.cxx:11
T mean() const
Return mean of all matrix elements.
Definition: vnl_matrix.h:544
VNL_EXPORT m element_quotient(m const &, m const &)
unsigned int rows() const
Return the number of rows.
Definition: vnl_matrix.h:179
static vnl_matrix< double > vcat(vnl_matrix< double > const &A, vnl_matrix< double > const &B)
Definition: vnl_matops.cxx:44
A collection of vnl_matrix operations, provided as static methods.
Definition: vnl_matops.h:24
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].
Definition: vnl_matrix.hxx:707
unsigned int columns() const
Return the number of columns.
Definition: vnl_matrix.h:187
static vnl_matrix< double > f2d(vnl_matrix< float > const &)
Conversions.
Definition: vnl_matops.cxx:88