vnl_transpose.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_transpose.h
2 #ifndef vnl_transpose_h_
3 #define vnl_transpose_h_
4 //:
5 // \file
6 // \brief Efficient matrix transpose
7 // \author Andrew W. Fitzgibbon, Oxford RRG
8 // \date 23 Dec 96
9 //
10 // \verbatim
11 // Modifications
12 // LSB (Manchester) 19/3/01 Tidied documentation
13 // \endverbatim
14 
15 #include <iostream>
16 #ifdef _MSC_VER
17 # include <vcl_msvc_warnings.h>
18 #endif
19 #include <vnl/vnl_fastops.h>
20 #include "vnl/vnl_export.h"
21 
22 //: Efficient matrix transpose
23 // vnl_transpose is an efficient way to write C = vnl_transpose(A) * B.
24 // The vnl_transpose class holds a reference to the original matrix
25 // and when involved in an operation for which it has been specialized,
26 // performs the operation without copying.
27 //
28 // If the operation has not been specialized, the vnl_transpose performs
29 // a copying conversion to a matrix, printing a message to stdout.
30 // At that stage, the user may choose to implement the particular operation
31 // or use vnl_transpose::asMatrix() to clear the warning.
32 //
33 // NOTE: This is a reference class, so should be shorter-lived than the
34 // matrix to which it refers.
35 //
36 // NOTE: This only works for arguments of type vnl_matrix<double>
37 
38 class VNL_EXPORT vnl_transpose
39 {
41  public:
42 
43  //: Make a vnl_transpose object referring to matrix M
44  vnl_transpose(const vnl_matrix<double>& M): M_(M) {}
45 
46  //: Noisily convert a vnl_transpose to a matrix
47  operator vnl_matrix<double> () const {
48  std::cerr << "vnl_transpose being converted to matrix -- help! I don't wanna go!\n";
49  return M_.transpose();
50  }
51 
52  //: Quietly convert a vnl_transpose to a matrix
53  vnl_matrix<double> asMatrix () const { return M_.transpose(); }
54 
55  //: Return M' * O
57  vnl_matrix<double> ret(M_.columns(), O.columns());
58  vnl_fastops::AtB(ret, M_, O);
59  return ret;
60  }
61 
62  //: Return M' * O
64  vnl_vector<double> ret(M_.columns());
65  vnl_fastops::AtB(ret, M_, O);
66  return ret;
67  }
68 
69  //: Return A * B'
71  vnl_matrix<double> ret(A.rows(), B.M_.rows());
72  vnl_fastops::ABt(ret, A, B.M_);
73  return ret;
74  }
75 };
76 
77 #endif // vnl_transpose_h_
Efficient matrix transpose.
Definition: vnl_transpose.h:38
vnl_matrix< T > transpose() const
Return transpose.
Definition: vnl_matrix.hxx:682
vnl_matrix< double > asMatrix() const
Quietly convert a vnl_transpose to a matrix.
Definition: vnl_transpose.h:53
const vnl_matrix< double > & M_
Definition: vnl_transpose.h:40
vnl_vector< T > operator *(vnl_matrix_inverse< T > const &i, vnl_vector< T > const &B)
static void AtB(vnl_matrix< double > &out, const vnl_matrix< double > &A, const vnl_matrix< double > &B)
Compute $A^\top B$.
Definition: vnl_fastops.cxx:84
Collection of C-style matrix functions.
vnl_transpose(const vnl_matrix< double > &M)
Make a vnl_transpose object referring to matrix M.
Definition: vnl_transpose.h:44
unsigned int rows() const
Return the number of rows.
Definition: vnl_matrix.h:179
unsigned int columns() const
Return the number of columns.
Definition: vnl_matrix.h:187
static void ABt(vnl_matrix< double > &out, const vnl_matrix< double > &A, const vnl_matrix< double > &B)
Compute $A B^\top$.