MatrixT.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libbasicvector - A simple vector library
  4. * See file License for license information.
  5. */
  6. #ifndef _EMATRIX_BASICVECTOR_H
  7. #define _EMATRIX_BASICVECTOR_H
  8. #include <cstdlib>
  9. #include <string>
  10. #include <sstream>
  11. #include <stdexcept>
  12. #include <core/basics/numerictools.h>
  13. #include <core/basics/Exception.h>
  14. //#include <core/basics/Streamable.h>
  15. #ifdef NICE_USELIB_LINAL
  16. #include <cstddef>
  17. #include <LinAl/matrixCF.h>
  18. #endif
  19. #include "core/vector/MatrixBase.h"
  20. #include "core/vector/VectorT.h"
  21. namespace NICE {
  22. /**
  23. * @class MatrixT
  24. * @brief MatrixT is a simple matrix template class
  25. * @author Ferid Bajramovic (based on \c extarray from ckolumbus)
  26. *
  27. * \c MatrixT is a simple matrix class which provides the (optional) ability
  28. * to use externally allocated memory as storage.
  29. * The main features are:
  30. * - In concept an efficient implementation of a mathematical matrix
  31. * - An array-like storage class
  32. * - Support for externally allocated memory
  33. * - Ability to get pointer to internal memory
  34. * - Thus the ability to <b>directly</b> interface with other libraries such as
  35. * LinAl without time consuming data copying
  36. *
  37. * @note MatrixT objects can only be copied and assigned to each other to
  38. * a limited degree. This means that care has to be taken when putting
  39. * VectorT objects into STL containers (such as std::vector).
  40. * More information can be found in the documentation of VectorT.
  41. *
  42. * Todo: is the distinction between shallow and deep copy always clear?
  43. *
  44. * @example basicvector_matrix_overview.cpp
  45. */
  46. template<class ElementType>
  47. class MatrixT : public MatrixBase {
  48. public:
  49. //! STL-like typedef for type of elements
  50. typedef ElementType value_type;
  51. //! STL-like typedef for const element reference
  52. typedef const ElementType& const_reference;
  53. //! STL-like typedef for iterator
  54. typedef ElementType* iterator;
  55. //! STL-like typedef for const iterator
  56. typedef const ElementType* const_iterator;
  57. //! STL-like typedef for element reference
  58. typedef ElementType& reference;
  59. /**
  60. * @brief Create an empty \c MatrixT with size zero.
  61. *
  62. * Such an object is actually useless, but sometimes you may need to have
  63. * such instances to initalize some data structure.
  64. * The only way to turn such an object into something useful is operator=().
  65. */
  66. MatrixT();
  67. /**
  68. * @brief Create an \c MatrixT with size \c size.
  69. * Data will not be initialized.
  70. * @param rows number of rows of the \c MatrixT
  71. * @param cols number of rows of the \c MatrixT
  72. */
  73. explicit MatrixT(const size_t rows, const size_t cols);
  74. /**
  75. * @brief Create an \c MatrixT with size \c size.
  76. * Data will be initialized to \c element.
  77. * @param rows number of rows of the \c MatrixT
  78. * @param cols number of rows of the \c MatrixT
  79. * @param element Initial value of all elements
  80. */
  81. MatrixT(const size_t rows, const size_t cols, const ElementType& element);
  82. /**
  83. * @brief Create an \c MatrixT of size \c size.
  84. * It will be initialized with the data pointed to by \c _data.
  85. *
  86. * That is the first \c size elements of \c _data will be copied.
  87. * @param _data Data to be copied
  88. * @param rows number of rows of the \c MatrixT
  89. * @param cols number of rows of the \c MatrixT
  90. */
  91. MatrixT(const ElementType* _data, const size_t rows, const size_t cols);
  92. /**
  93. * @brief Create an \c MatrixT of size \c size
  94. * with optionally external storage.
  95. *
  96. * It will be initialized with the data pointed to by \c _data.
  97. * The parameter _external control whether the data will be copied or
  98. * the pointer \c _data is directly kept as storage for the \c MatrixT.
  99. * In case of external storage the data will not be deleted in the destructor.
  100. * @param _data External data storage
  101. * @param rows number of rows of the external storage
  102. * @param cols number of cols of the external storage
  103. * @param mode Storage mode: keep external memory or copy data.
  104. */
  105. MatrixT(ElementType* _data, const size_t rows, const size_t cols,
  106. const MatrixBase::Mode mode = copy);
  107. // /**
  108. // * @brief Read from input stream.
  109. // * @param input Read from here
  110. // */
  111. //explicit MatrixT(std::istream& input);
  112. /**
  113. * @brief copy constructor
  114. * @param v MatrixT where to copy data from
  115. */
  116. MatrixT(const MatrixT<ElementType>& v);
  117. /**
  118. * @brief destructor
  119. */
  120. virtual ~MatrixT();
  121. void deleteRow ( const int & index);
  122. void deleteCol ( const int & index);
  123. //not const, because they get sorted internally
  124. void deleteRows ( std::vector<int> & indices);
  125. void deleteCols ( std::vector<int> & indices);
  126. /**
  127. * @brief Create a const MatrixT of size \c size
  128. * with <b>external</b> storage.
  129. *
  130. * It will be initialized with the data pointed to by %_data.
  131. * The data will not be deleted in the destructor.
  132. * @param _data External data storage
  133. * @param rows number of rows of the external storage
  134. * @param cols number of cols of the external storage
  135. */
  136. inline static const MatrixT<ElementType>* createConst(
  137. const ElementType* _data,
  138. const size_t rows,
  139. const size_t cols);
  140. /**
  141. * @brief Read access to elements.
  142. * @param row row to access
  143. * @param col col to access
  144. * @return Element (as const reference)
  145. * @example basicvector_matrix_access_operator1.cpp
  146. */
  147. inline const_reference operator()(const ptrdiff_t row,
  148. const ptrdiff_t col) const {
  149. return constData[col * rows() + row];
  150. }
  151. /**
  152. * @brief Read access to elements.
  153. * @param row row to access
  154. * @param col col to access
  155. * @return Element (as const reference)
  156. */
  157. inline reference operator()(const ptrdiff_t row,
  158. const ptrdiff_t col) {
  159. return data[col * rows() + row];
  160. }
  161. /**
  162. * @brief Get a sub-matrix of the current matrix
  163. * @param row_tl row of the top left element
  164. * @param col_tl column of the top left element
  165. * @param row_br row of the bottom right element
  166. * @param col_br column of the bottom right element
  167. * @return sub-matrix as a copy
  168. */
  169. MatrixT<ElementType> operator()(const uint row_tl,
  170. const uint col_tl,
  171. const uint row_br,
  172. const uint col_br) const;
  173. /**
  174. * @brief Get a const pointer to the internal memory.
  175. */
  176. // operator ElementType const* () const { return constData; }
  177. /**
  178. * @brief Get a const_iterator pointing to the first element.
  179. *
  180. * (Actually the same as \c getDataPointer())
  181. */
  182. inline const_iterator begin() const { return constData; }
  183. /**
  184. * @brief Get an iterator pointing beyond the last element.
  185. */
  186. inline const_iterator end() const { return constData + rows() * cols(); }
  187. /**
  188. * @brief Return the number of rows of this MatrixT.
  189. * @return Size of this MatrixT.
  190. */
  191. inline size_t rows() const { return m_rows; }
  192. /**
  193. * @brief Return the number of columns of this MatrixT.
  194. * @return Size of this MatrixT.
  195. */
  196. inline size_t cols() const { return m_cols; }
  197. /**
  198. * Maximum of elements
  199. * @return Max of elements
  200. */
  201. inline ElementType Max() const;
  202. /**
  203. * Minimum of elements
  204. * @return Min of elements
  205. */
  206. inline ElementType Min() const;
  207. /**
  208. * @brief Compare \c v with \c this.
  209. * @pre Size of \c v and \c this must be equal
  210. * @param v data to compare with
  211. * @return true if \c v and \c this are equal
  212. */
  213. inline bool operator== (const MatrixT<ElementType>& v) const;
  214. /**
  215. * @brief Compare \c v with \c this.
  216. * @pre Size of \c v and \c this must be equal
  217. * @param v data to compare with
  218. * @return \c *this
  219. * @return true if \c v and \c this are not equal
  220. */
  221. inline bool operator!= (const MatrixT<ElementType>& v) const;
  222. /**
  223. * @brief Change the number of MatrixT elements
  224. * @param rows new number of rows
  225. * @param cols new number of cols
  226. * @throw std::runtime_error if using external storage and \c size > \c size()
  227. * @note Changing the size of the vector invalidates all iterators
  228. * and pointers held to the data.
  229. */
  230. inline void resize(size_t rows, size_t cols);
  231. /**
  232. * @brief Transpose a quadratic MatrixT.
  233. * @throw Exception if matrix is not square.
  234. */
  235. inline void transposeInplace();
  236. /**
  237. * @brief return a transposed MatrixT.
  238. * @return transposed matrix
  239. */
  240. MatrixT<ElementType> transpose() const;
  241. /*! @copydoc MatrixT::transpose() **/
  242. MatrixT<ElementType> operator !()
  243. { return transpose(); };
  244. /**
  245. * @brief Copy data from \c v to \c this.
  246. * @pre Size of \c v and \c this must be equal
  247. * @param v New data
  248. * @return \c *this
  249. */
  250. inline MatrixT<ElementType>& operator=(const MatrixT<ElementType>& v);
  251. /**
  252. * @brief Set all elements to value \c element
  253. * @param element New value of all elements
  254. */
  255. inline MatrixT<ElementType>& operator=(const ElementType& element);
  256. /**
  257. * @brief Set all elements to value \c element
  258. * @param element New value of all elements
  259. */
  260. inline void set(const ElementType& element) {
  261. *this = element;
  262. }
  263. /**
  264. * Set a subblock of the matrix.
  265. * @param top row of top left position of block
  266. * @param left column of top left position of block
  267. * @param m data to be copied into the block
  268. */
  269. void setBlock(uint top, uint left, MatrixT<ElementType> m);
  270. /**
  271. * Set a specific row of the matrix.
  272. * @param row index of the row to be set
  273. * @param v new data for the specified row
  274. */
  275. void setRow(const uint & row, const NICE::VectorT<ElementType> & v);
  276. /**
  277. * Exchange two rows of the matrix
  278. * @param r1 first row to exchange
  279. * @param r2 second row to exchange
  280. */
  281. void exchangeRows(const uint & r1, const uint & r2);
  282. /**
  283. * Add m to Set a subblock of the matrix.
  284. * @param top row of top left position of block
  285. * @param left column of top left position of block
  286. * @param m data to be added to the block
  287. */
  288. void addToBlock(uint top, uint left, MatrixT<ElementType> m);
  289. /**
  290. * @brief Get a pointer to the internal memory.
  291. */
  292. // inline operator ElementType* () { return data; }
  293. /**
  294. * @brief Get a pointer to the internal memory.
  295. */
  296. inline ElementType* getDataPointer() { return data; }
  297. /**
  298. * @brief Get the ith column of the matrix and return an VectorT with is a reference to the internal memory.
  299. * @param i number of column
  300. */
  301. inline const VectorT<ElementType> getColumnRef(uint i) const;
  302. /**
  303. * @brief Get the ith column of the matrix and return an VectorT with is a reference to the internal memory.
  304. * @param i number of column
  305. */
  306. inline VectorT<ElementType> getColumnRef(uint i);
  307. /**
  308. * @brief Get the ith column of the matrix and return it as VectorT.
  309. * @param i number of column
  310. */
  311. inline VectorT<ElementType> getColumn(uint i) const;
  312. /**
  313. * @brief Get the ith row of the matrix and return it as VectorT.
  314. * @param i number of row
  315. */
  316. inline VectorT<ElementType> getRow(uint i) const;
  317. /**
  318. * @brief Get a const pointer to the internal memory.
  319. */
  320. inline const ElementType* getDataPointer() const { return constData; }
  321. /**
  322. * @brief Get an iterator pointing to the first element.
  323. *
  324. * (Actually the same as \c getDataPointer())
  325. * @example basicvector_matrix_access_iterator.cpp
  326. */
  327. inline iterator begin() { return data; }
  328. /**
  329. * @brief Get an iterator pointing beyond the last element.
  330. */
  331. inline iterator end() { return data + rows() * cols(); }
  332. /**
  333. * @brief Add \c e to each element of \c this.
  334. * @param e value
  335. * @return \c *this
  336. * @example basicvector_matrix_operator.cpp
  337. */
  338. inline MatrixT<ElementType>& operator+= (const ElementType& e);
  339. /**
  340. * @brief Subtract \c e from each element of \c this.
  341. * @param e value
  342. * @return \c *this
  343. */
  344. inline MatrixT<ElementType>& operator-= (const ElementType& e);
  345. /**
  346. * @brief Multiply each element of \c this with \c e.
  347. * @param e value
  348. * @return \c *this
  349. */
  350. inline MatrixT<ElementType>& operator*= (const ElementType& e);
  351. /**
  352. * @brief Divide each element of \c this through \c e.
  353. * @param e value
  354. * @return \c *this
  355. */
  356. inline MatrixT<ElementType>& operator/= (const ElementType& e);
  357. /**
  358. * @brief Add \c v to \c this.
  359. * @pre Size of \c v and \c this must be equal
  360. * @param v New data
  361. * @return \c *this
  362. */
  363. inline MatrixT<ElementType>& operator+= (const MatrixT<ElementType>& v);
  364. /**
  365. * @brief Subtract \c v from \c this.
  366. * @pre Size of \c v and \c this must be equal
  367. * @param v New data
  368. * @return \c *this
  369. */
  370. inline MatrixT<ElementType>& operator-= (const MatrixT<ElementType>& v);
  371. // /**
  372. // * @brief Multiplicate elementwise \c v to \c this.
  373. // * @pre Size of \c v and \c this must be equal
  374. // * @param v New data
  375. // * @return \c *this
  376. // */
  377. // inline MatrixT<ElementType>& operator*= (const MatrixT<ElementType>& v);
  378. // /**
  379. // * @brief Divide elementwise \c v from \c this.
  380. // * @pre Size of \c v and \c this must be equal
  381. // * @param v New data
  382. // * @return \c *this
  383. // */
  384. // inline MatrixT<ElementType>& operator/= (const MatrixT<ElementType>& v);
  385. /**
  386. * @brief Set this matrix to be the identity matrix
  387. */
  388. inline void setIdentity() {
  389. *this = ElementType(0);
  390. unsigned int m = std::min(rows(), cols());
  391. for (unsigned int i = 0; i < m; i++) {
  392. (*this)(i, i) = ElementType(1);
  393. }
  394. }
  395. /** add \c scale to each element of the main diagonal */
  396. void addIdentity( double scale );
  397. /** add \c scale * \c m to this */
  398. void addScaledMatrix( const ElementType & scale , const MatrixT<ElementType>& m);
  399. /** add diagonal matrix (represented as a vector) */
  400. void addDiagonal( const VectorT<ElementType> & D );
  401. /**
  402. * Tensor product v * w^T, result goes to this matrix.
  403. * @param v First input vector
  404. * @param w Second input vector
  405. * @throw Exception if formats are inconsistent
  406. */
  407. void tensorProduct(const VectorT<ElementType>& v,
  408. const VectorT<ElementType>& w);
  409. /**
  410. * Tensor product lambda * v * w^T, result goes to this matrix.
  411. * @param v First input vector
  412. * @param w Second input vector
  413. * @param lambda scale parameter
  414. * @throw Exception if formats are inconsistent
  415. */
  416. void addTensorProduct(double lambda, const VectorT<ElementType>& v,
  417. const VectorT<ElementType>& w);
  418. /**
  419. * Matrix multiplication: this = a^{T if atranspose} * b^{T if btranspose}.
  420. * The formats of this, a and b must be consistent.
  421. * If this is empty (size 0x0), it will be resize.
  422. * @param a matrix to multiply (must NOT be the same object as \c this !)
  423. * @param b matrix to multiply (must NOT be the same object as \c this !)
  424. * @param atranspose use a.transpose() instead of a
  425. * @param btranspose use b.transpose() instead of b
  426. * @throw Exception if formats are inconsistent
  427. */
  428. void multiply(const MatrixT<ElementType>& a, const MatrixT<ElementType>& b,
  429. bool atranspose=false, bool btranspose=false);
  430. /**
  431. * Is an entry NaN?
  432. * @note This method is defined on floating point matrices only!
  433. */
  434. bool containsNaN() const;
  435. /**
  436. * @brief Returns 'true' if the memory is allocated externally
  437. * @return true if external storage
  438. */
  439. inline bool isExternal() const { return externalStorage; }
  440. /**
  441. * @brief Compare \c v with \c this.
  442. * @pre Size of \c v and \c this must be equal
  443. * @param a data to compare with
  444. * @param threshold difference of each entry which can be neglected
  445. * @return true if \c v and \c this are equal
  446. */
  447. inline bool isEqual(const MatrixT<ElementType> &a, ElementType threshold=static_cast<ElementType>(0)) const;
  448. /**
  449. * Square of the frobenius norm of this matrix.
  450. * Only defined for numerical ElementType.
  451. * @example basicvector_matrix_norm.cpp
  452. */
  453. ElementType squaredFrobeniusNorm() const;
  454. /**
  455. * Trace of the matrix.
  456. * Only defined for numeric ElementType, but also defined
  457. * for non-quadratic matrices!
  458. */
  459. ElementType trace() const;
  460. /**
  461. * Bilinear form: v^T Matrix v
  462. * Only defined for numerical ElementType and quadratic matrizes.
  463. */
  464. ElementType bilinear( const VectorT<ElementType> & v ) const;
  465. /**
  466. * Divide each row with its sum of all absolute values (L1-norm).
  467. * The L1-norm of each row is 1 after this operation,
  468. * except for rows with a prior L1-norm near zero.
  469. */
  470. void normalizeRowsL1();
  471. /**
  472. * Divide each column with its sum of all absolute values (L1-norm).
  473. * The L1-norm of each column is 1 after this operation,
  474. * except for columns with a prior L1-norm near zero.
  475. */
  476. void normalizeColumnsL1();
  477. /**
  478. * Frobenius norm of this matrix. Only defined for numerical ElementType.
  479. */
  480. inline ElementType frobeniusNorm() const {
  481. return static_cast<ElementType>(sqrt(squaredFrobeniusNorm()));
  482. }
  483. #ifdef NICE_USELIB_LINAL
  484. /**
  485. * Copy data from linal matrix
  486. */
  487. explicit MatrixT(const LinAl::Matrix<ElementType>& m);
  488. /**
  489. * @brief Copy data from \c v to \c this.
  490. * @pre Size of \c v and \c this must be equal or this must have size 0x0
  491. * @param v New data
  492. * @return \c *this
  493. */
  494. inline MatrixT<ElementType>& operator=(const LinAl::Matrix<ElementType>& v);
  495. /**
  496. * Shallow copy data to LinAl matrix
  497. */
  498. inline LinAl::MatrixCF<ElementType> linal() {
  499. return LinAl::MatrixCF<ElementType>(data, rows(), cols(), true);
  500. }
  501. /**
  502. * Copy data to LinAl matrix
  503. */
  504. inline LinAl::MatrixCF<ElementType> linal() const {
  505. return LinAl::MatrixCF<ElementType>(data, rows(), cols());
  506. }
  507. #endif // NICE_USELIB_LINAL
  508. protected:
  509. /**
  510. * Are we using external storage?
  511. */
  512. bool externalStorage;
  513. /**
  514. * Const pointer to the data.
  515. */
  516. const ElementType* constData;
  517. /**
  518. * Pointer to the data.
  519. * @note This has to point to the same adress as constData!
  520. * (NULL is only const data is available)
  521. */
  522. ElementType* data;
  523. /**
  524. * Size of the vector
  525. */
  526. size_t m_rows;
  527. size_t m_cols;
  528. inline void setDataPointer(ElementType* _data, size_t rows, size_t cols,
  529. bool _externalStorage) {
  530. data = _data;
  531. constData = _data;
  532. m_rows = rows;
  533. m_cols = cols;
  534. externalStorage = _externalStorage;
  535. }
  536. inline void setConstDataPointer(const ElementType* _data,
  537. size_t rows, size_t cols) {
  538. data = NULL;
  539. constData = _data;
  540. m_rows = rows;
  541. m_cols = cols;
  542. externalStorage = true;
  543. }
  544. // virtual void read(std::istream& stream);
  545. //
  546. // virtual void write(std::ostream& stream) const;
  547. };
  548. template <class ElementType>
  549. inline std::istream&
  550. operator >> (std::istream& input, MatrixT<ElementType>& v) {
  551. size_t w, h;
  552. char c;
  553. input >> w >> c >> h;
  554. if (c != 'x') {
  555. fthrow(Exception, "Error reading MatrixT from stream: expected x, got " << c);
  556. }
  557. v.resize(w, h);
  558. for (size_t r = 0; r < v.rows(); r++) {
  559. for (size_t c = 0; c < v.cols(); c++) {
  560. input >> v(r, c);
  561. }
  562. }
  563. return input;
  564. }
  565. template <class ElementType>
  566. inline std::ostream&
  567. operator << (std::ostream& output, const MatrixT<ElementType>& v) {
  568. output << v.rows() << " x " << v.cols() << std::endl;
  569. for (size_t r = 0; r < v.rows(); r++) {
  570. for (size_t c = 0; c < v.cols(); c++) {
  571. output << v(r, c) << " ";
  572. }
  573. output << std::endl;
  574. }
  575. return output;
  576. }
  577. template <class Tp>
  578. inline NICE::ibinstream& operator>>(NICE::ibinstream& s, MatrixT<Tp> &r)
  579. {
  580. unsigned int rows;
  581. unsigned int cols;
  582. s >> rows;
  583. s >> cols;
  584. r.resize(rows,cols);
  585. typename MatrixT<Tp>::iterator it=r.begin();
  586. for(;it!=r.end();it++)
  587. s>>*it;
  588. return s;
  589. }
  590. template <class Tp>
  591. inline NICE::obinstream& operator<<(NICE::obinstream& s, const MatrixT<Tp>& r)
  592. {
  593. unsigned int rows=r.rows();
  594. unsigned int cols=r.cols();
  595. s<<rows;
  596. s<<cols;
  597. typename MatrixT<Tp>::const_iterator it=r.begin();
  598. for(;it!=r.end();it++)
  599. s << *it;
  600. return s;
  601. }
  602. typedef MatrixT<bool> BoolMatrix;
  603. typedef MatrixT<char> CharMatrix;
  604. typedef MatrixT<int> IntMatrix;
  605. typedef MatrixT<float> FloatMatrix;
  606. typedef MatrixT<double> Matrix;
  607. /** Matrix addition */
  608. template<class ElementType>
  609. MatrixT<ElementType> operator+(const MatrixT<ElementType> &, const MatrixT<ElementType>&);
  610. /** Matrix substraction */
  611. template<class ElementType>
  612. MatrixT<ElementType> operator-(const MatrixT<ElementType>&, const MatrixT<ElementType>&);
  613. /** Matrix (right) multiplication with a scalar */
  614. template<class ElementType>
  615. MatrixT<ElementType> operator*(const MatrixT<ElementType>&, const double);
  616. /** Matrix (left) multiplication with a scalar */
  617. template<class ElementType>
  618. MatrixT<ElementType> operator*(const double, const MatrixT<ElementType>&);
  619. /** Matrix multiplication with a vector */
  620. template<class ElementType>
  621. VectorT<ElementType> operator*(const MatrixT<ElementType>&, const VectorT<ElementType>& );
  622. /** Matrix multiplication with a matrix */
  623. template<class ElementType>
  624. MatrixT<ElementType> operator*(const MatrixT<ElementType>&, const MatrixT<ElementType>& );
  625. /** Kronecker product of two matrices */
  626. template<class ElementType>
  627. void kroneckerProduct (const MatrixT<ElementType>& A, const MatrixT<ElementType>& B, MatrixT<ElementType>& dst);
  628. /** Multiply the kronecker product of two matrices with a vector */
  629. template <typename T>
  630. void kroneckerProductMultiplication ( const MatrixT<T> & A, const MatrixT<T> & B, const Vector & x, Vector & y );
  631. /** The vector x is divided in parts of size blockSize, these parts are multiplied with A and concatenated
  632. * to the results. The operation is equivalent to kroneckerProductMultiplication with B being a identity matrix. */
  633. template <typename T>
  634. void blockwiseMultiplication ( const MatrixT<T> & A, uint blockSize, const Vector & x, Vector & y );
  635. }
  636. //#ifdef __GNUC__
  637. #include "core/vector/MatrixT.tcc"
  638. //#endif
  639. #endif // _EMATRIX_BASICVECTOR_H