// This is core/vnl/vnl_transpose.h #ifndef vnl_transpose_h_ #define vnl_transpose_h_ #ifdef VCL_NEEDS_PRAGMA_INTERFACE #pragma interface #endif //: // \file // \brief Efficient matrix transpose // \author Andrew W. Fitzgibbon, Oxford RRG // \date 23 Dec 96 // // \verbatim // Modifications // LSB (Manchester) 19/3/01 Tidied documentation // \endverbatim #include #include #include #include "vnl/vnl_export.h" //: Efficient matrix transpose // vnl_transpose is an efficient way to write C = vnl_transpose(A) * B. // The vnl_transpose class holds a reference to the original matrix // and when involved in an operation for which it has been specialized, // performs the operation without copying. // // If the operation has not been specialized, the vnl_transpose performs // a copying conversion to a matrix, printing a message to stdout. // At that stage, the user may choose to implement the particular operation // or use vnl_transpose::asMatrix() to clear the warning. // // NOTE: This is a reference class, so should be shorter-lived than the // matrix to which it refers. // // NOTE: This only works for arguments of type vnl_matrix class VNL_TEMPLATE_EXPORT vnl_transpose { const vnl_matrix& M_; public: //: Make a vnl_transpose object referring to matrix M vnl_transpose(const vnl_matrix& M): M_(M) {} //: Noisily convert a vnl_transpose to a matrix operator vnl_matrix () const { std::cerr << "vnl_transpose being converted to matrix -- help! I don't wanna go!\n"; return M_.transpose(); } //: Quietly convert a vnl_transpose to a matrix vnl_matrix asMatrix () const { return M_.transpose(); } //: Return M' * O vnl_matrix operator* (const vnl_matrix& O) { vnl_matrix ret(M_.columns(), O.columns()); vnl_fastops::AtB(ret, M_, O); return ret; } //: Return M' * O vnl_vector operator* (const vnl_vector& O) { vnl_vector ret(M_.columns()); vnl_fastops::AtB(ret, M_, O); return ret; } //: Return A * B' friend vnl_matrix operator* (const vnl_matrix& A, const vnl_transpose& B) { vnl_matrix ret(A.rows(), B.M_.rows()); vnl_fastops::ABt(ret, A, B.M_); return ret; } }; #endif // vnl_transpose_h_