plll  1.0
matrix.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011-2014 University of Zurich
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #ifndef PLLL_INCLUDE_GUARD__MATRIX_HPP
24 #define PLLL_INCLUDE_GUARD__MATRIX_HPP
25 
26 // #define PLLL_DEBUG_MATRIX_DEBUG
27 
28 #include "helper.hpp"
29 #include "matrix-mem.hpp"
30 #include <list>
31 #include <cctype>
32 #include <iostream>
33 
34 #if __cplusplus >= 201103L
35  #include <utility>
36 #endif
37 
47 namespace plll
48 {
49  #ifndef PLLL_DEBUG_MATRIX_DEBUG
50  #define PLLL_DEBUG_OUTPUT_MESSAGE(msg)
51  #else
52  #define PLLL_DEBUG_OUTPUT_MESSAGE(msg) { std::cout << msg << "\n"; }
53 
54  template<typename T>
55  inline void * getAddress(const T & t) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
56  {
57  return &const_cast<T &>(t);
58  }
59 
60  template<typename T>
61  inline void * getAddress(const T * t); // should yield linker error
62  #endif
63 
70  namespace linalg
71  {
72  enum { Flexible = -1 };
74 
75  namespace implementation
76  {
77  template<typename S, bool def>
79 
80  template<typename S>
81  class Initialize_Impl<S, false>
82  {
83  private:
84  const S & d_ref;
85 
86  public:
87  Initialize_Impl(const S & ref) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
88  : d_ref(ref)
89  {
90  }
91 
92  const S & ref() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
93  {
94  return d_ref;
95  }
96  };
97 
98  template<typename S>
99  class Initialize_Impl<S, true>
100  {
101  private:
102  S d_obj;
103 
104  public:
105  const S & ref() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
106  {
107  return d_obj;
108  }
109  };
110  }
111 
115  template<typename S>
123  inline implementation::Initialize_Impl<S, false> Initialize(const S & ref) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
124  {
126  }
127 
128  template<typename S>
135  inline implementation::Initialize_Impl<S, true> Initialize() PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(S()))
136  {
138  }
140 
141  typedef unsigned int size_type;
143  namespace implementation
144  {
145  template<typename MatrixType>
146  struct MatrixInfo
147  {
148  enum { is_matrix = false,
149  is_const = false,
150  is_math_object = false,
151  is_expression = false,
152  can_move_from = false,
153  can_assign_to = false,
154  can_resize_rows = false,
155  can_resize_cols = false,
156  use_temporary_on_evaluate = false,
157  coeffs_are_simple_expressions = false };
158  enum { rows = 0, cols = 0 };
159  typedef void Type;
160  typedef void StorageTraits;
161  };
162  }
163 
164  template<typename T, int Rows, int Cols, typename StorageTraits, bool MathObject>
165  class base_matrix;
166 
167  namespace implementation
168  {
169  template<typename T, int Rows, int Cols, typename ST, bool MO>
170  struct MatrixInfo<base_matrix<T, Rows, Cols, ST, MO> >
171  {
172  enum { is_matrix = true,
173  is_const = false,
174  is_math_object = MO,
175  is_expression = false,
176  only_defined_for_matrices = 1,
177  can_move_from = true,
178  can_assign_to = true,
179  can_resize_rows = Rows < 0,
180  can_resize_cols = Cols < 0,
181  use_temporary_on_evaluate = false,
182  coeffs_are_simple_expressions = true };
183  enum { rows = Rows, cols = Cols };
184  typedef T Type;
185  typedef ST StorageTraits;
186  };
187 
188  template<typename T, int Rows, int Cols, typename ST, bool MO>
189  struct MatrixInfo<const base_matrix<T, Rows, Cols, ST, MO> >
190  {
191  enum { is_matrix = true,
192  is_const = true,
193  is_math_object = MO,
194  is_expression = false,
195  only_defined_for_matrices = 1,
196  can_move_from = false,
197  can_assign_to = true,
198  can_resize_rows = false, // const matrices cannot be resized
199  can_resize_cols = false,
200  use_temporary_on_evaluate = false,
201  coeffs_are_simple_expressions = true };
202  enum { rows = Rows, cols = Cols };
203  typedef T Type;
204  typedef ST StorageTraits;
205  };
206  }
207 
208 #if __cplusplus < 201103L
209  template<typename T, int Rows, int Cols, typename StorageTraits>
210  class math_matrix;
211 
212  namespace implementation
213  {
214  template<typename T, int Rows, int Cols, typename ST>
215  struct MatrixInfo<math_matrix<T, Rows, Cols, ST> >
216  {
217  enum { is_matrix = true,
218  is_const = false,
219  is_math_object = true,
220  is_expression = false,
221  only_defined_for_matrices = 1,
222  can_move_from = true,
223  can_assign_to = true,
224  can_resize_rows = Rows < 0,
225  can_resize_cols = Cols < 0,
226  use_temporary_on_evaluate = false,
227  coeffs_are_simple_expressions = true };
228  enum { rows = Rows, cols = Cols };
229  typedef T Type;
230  typedef ST StorageTraits;
231  };
232 
233  template<typename T, int Rows, int Cols, typename ST>
234  struct MatrixInfo<const math_matrix<T, Rows, Cols, ST> >
235  {
236  enum { is_matrix = true,
237  is_const = true,
238  is_math_object = true,
239  is_expression = false,
240  only_defined_for_matrices = 1,
241  can_move_from = false,
242  can_assign_to = true,
243  can_resize_rows = false, // const matrices cannot be resized
244  can_resize_cols = false,
245  use_temporary_on_evaluate = false,
246  coeffs_are_simple_expressions = true };
247  enum { rows = Rows, cols = Cols };
248  typedef T Type;
249  typedef ST StorageTraits;
250  };
251  }
252 
253  template<typename T, int Cols, typename StorageTraits, bool MO>
255 
256  namespace implementation
257  {
258  template<typename T, int Cols, typename ST, bool MO>
259  struct MatrixInfo<base_rowvector<T, Cols, ST, MO> >
260  {
261  enum { is_matrix = true,
262  is_const = false,
263  is_math_object = MO,
264  is_expression = false,
265  only_defined_for_matrices = 1,
266  can_move_from = true,
267  can_assign_to = true,
268  can_resize_rows = false,
269  can_resize_cols = Cols < 0,
270  use_temporary_on_evaluate = false,
271  coeffs_are_simple_expressions = true };
272  enum { rows = 1, cols = Cols };
273  typedef T Type;
274  typedef ST StorageTraits;
275  };
276 
277  template<typename T, int Cols, typename ST, bool MO>
278  struct MatrixInfo<const base_rowvector<T, Cols, ST, MO> >
279  {
280  enum { is_matrix = true,
281  is_const = true,
282  is_math_object = MO,
283  is_expression = false,
284  only_defined_for_matrices = 1,
285  can_move_from = false,
286  can_assign_to = true,
287  can_resize_rows = false, // const matrices cannot be resized
288  can_resize_cols = false,
289  use_temporary_on_evaluate = false,
290  coeffs_are_simple_expressions = true };
291  enum { rows = 1, cols = Cols };
292  typedef T Type;
293  typedef ST StorageTraits;
294  };
295  }
296 
297  template<typename T, int Rows, typename StorageTraits, bool MO>
299 
300  namespace implementation
301  {
302  template<typename T, int Rows, typename ST, bool MO>
303  struct MatrixInfo<base_colvector<T, Rows, ST, MO> >
304  {
305  enum { is_matrix = true,
306  is_const = false,
307  is_math_object = MO,
308  is_expression = false,
309  only_defined_for_matrices = 1,
310  can_move_from = true,
311  can_assign_to = true,
312  can_resize_rows = Rows < 0,
313  can_resize_cols = false,
314  use_temporary_on_evaluate = false,
315  coeffs_are_simple_expressions = true };
316  enum { rows = Rows, cols = 1 };
317  typedef T Type;
318  typedef ST StorageTraits;
319  };
320 
321  template<typename T, int Rows, typename ST, bool MO>
322  struct MatrixInfo<const base_colvector<T, Rows, ST, MO> >
323  {
324  enum { is_matrix = true,
325  is_const = true,
326  is_math_object = MO,
327  is_expression = false,
328  only_defined_for_matrices = 1,
329  can_move_from = false,
330  can_assign_to = true,
331  can_resize_rows = false, // const matrices cannot be resized
332  can_resize_cols = false,
333  use_temporary_on_evaluate = false,
334  coeffs_are_simple_expressions = true };
335  enum { rows = Rows, cols = 1 };
336  typedef T Type;
337  typedef ST StorageTraits;
338  };
339  }
340 
341  template<typename T, int Cols, typename StorageTraits>
343 
344  namespace implementation
345  {
346  template<typename T, int Cols, typename ST>
347  struct MatrixInfo<math_rowvector<T, Cols, ST> >
348  {
349  enum { is_matrix = true,
350  is_const = false,
351  is_math_object = true,
352  is_expression = false,
353  only_defined_for_matrices = 1,
354  can_move_from = true,
355  can_assign_to = true,
356  can_resize_rows = false,
357  can_resize_cols = Cols < 0,
358  use_temporary_on_evaluate = false,
359  coeffs_are_simple_expressions = true };
360  enum { rows = 1, cols = Cols };
361  typedef T Type;
362  typedef ST StorageTraits;
363  };
364 
365  template<typename T, int Cols, typename ST>
366  struct MatrixInfo<const math_rowvector<T, Cols, ST> >
367  {
368  enum { is_matrix = true,
369  is_const = true,
370  is_math_object = true,
371  is_expression = false,
372  only_defined_for_matrices = 1,
373  can_move_from = false,
374  can_assign_to = true,
375  can_resize_rows = false, // const matrices cannot be resized
376  can_resize_cols = false,
377  use_temporary_on_evaluate = false,
378  coeffs_are_simple_expressions = true };
379  enum { rows = 1, cols = Cols };
380  typedef T Type;
381  typedef ST StorageTraits;
382  };
383  }
384 
385  template<typename T, int Rows, typename StorageTraits>
387 
388  namespace implementation
389  {
390  template<typename T, int Rows, typename ST>
391  struct MatrixInfo<math_colvector<T, Rows, ST> >
392  {
393  enum { is_matrix = true,
394  is_const = false,
395  is_math_object = true,
396  is_expression = false,
397  only_defined_for_matrices = 1,
398  can_move_from = true,
399  can_assign_to = true,
400  can_resize_rows = Rows < 0,
401  can_resize_cols = false,
402  use_temporary_on_evaluate = false,
403  coeffs_are_simple_expressions = true };
404  enum { rows = Rows, cols = 1 };
405  typedef T Type;
406  typedef ST StorageTraits;
407  };
408 
409  template<typename T, int Rows, typename ST>
410  struct MatrixInfo<const math_colvector<T, Rows, ST> >
411  {
412  enum { is_matrix = true,
413  is_const = true,
414  is_math_object = true,
415  is_expression = false,
416  only_defined_for_matrices = 1,
417  can_move_from = false,
418  can_assign_to = true,
419  can_resize_rows = false, // const matrices cannot be resized
420  can_resize_cols = false,
421  use_temporary_on_evaluate = false,
422  coeffs_are_simple_expressions = true };
423  enum { rows = Rows, cols = 1 };
424  typedef T Type;
425  typedef ST StorageTraits;
426  };
427  }
428 #endif
429 
430  namespace implementation
431  {
432  namespace expressions
433  {
434  template<template<typename DataType> class Operator, typename Data>
435  class expr;
436 
437  template<typename Data>
438  class identity_operation;
439 
440  template<typename MatrixType>
441  class MatrixWrapper;
442 
443  template<typename MatrixType>
444  class ConstMatrixWrapper;
445 
446  template<typename MatrixType>
447  inline MatrixWrapper<MatrixType> make_matrix_wrapper(MatrixType &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
448 
449  template<typename MatrixType>
450  inline ConstMatrixWrapper<MatrixType> make_matrix_wrapper(const MatrixType &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
451 
452  template<typename MatrixType>
453  inline expr<identity_operation, MatrixWrapper<MatrixType> > make_matrix_expression(MatrixType &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
454 
455  template<typename MatrixType>
456  inline expr<identity_operation, ConstMatrixWrapper<MatrixType> > make_matrix_expression(const MatrixType &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
457 
458  template<typename MatrixType>
459  class MatrixTemporaryWrapper;
460 
461  template<typename ScalarType>
462  class ScalarWrapper;
463 
464  template<typename ScalarType>
465  inline ScalarWrapper<ScalarType> make_scalar_wrapper(const ScalarType &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
466 
467  template<typename PairMatrices>
468  class matrix_matrix_multiplication;
469 
470  template<typename OpA, typename OpB>
471  class MSMul;
472 
473  template<typename OpA, typename OpB>
474  class SMMul;
475 
476  template<typename OpA, typename OpB>
477  class MSDiv;
478 
479  template<typename OpA, typename OpB>
480  class MSMod;
481 
482  template<template<typename OpA, typename OpB> class Operation>
483  class matrix_scalar_operation;
484 
485  template<typename OpA, typename OpB>
486  class CWAdd;
487 
488  template<typename OpA, typename OpB>
489  class CWSub;
490 
491  template<typename OpA, typename OpB>
492  class CWMul;
493 
494  template<typename OpA, typename OpB>
495  class CWDiv;
496 
497  template<typename OpA, typename OpB>
498  class CWMod;
499 
500  template<template<typename OpA, typename OpB> class Operation>
501  class componentwise_operation;
502 
503  template<typename MTIn>
504  class matrix_negation;
505 
506  template<int Rows, int Cols>
507  class sub
508  {
509  public:
510  template<typename MT>
511  class operation_generic;
512  };
513 
514  template<int Dim>
515  class sub_1d
516  {
517  public:
518  template<typename MT>
519  class operation_row;
520 
521  template<typename MT>
522  class operation_col;
523  };
524 
525  template<typename MT>
526  class transpose;
527  }
528 
529  template<template<typename DataType> class Operator, typename Data>
530  struct MatrixInfo<expressions::expr<Operator, Data> >
531  {
532  enum { is_matrix = MatrixInfo<typename Operator<Data>::ValueType>::is_matrix,
533  is_const = Operator<Data>::is_const,
534  is_math_object = MatrixInfo<typename Operator<Data>::ValueType>::is_math_object,
535  is_expression = true,
536  only_defined_for_matrices = 1,
537  can_move_from = Operator<Data>::can_move_from,
538  can_assign_to = Operator<Data>::can_assign_to,
539  can_resize_rows = Operator<Data>::can_resize_rows,
540  can_resize_cols = Operator<Data>::can_resize_cols,
541  use_temporary_on_evaluate = Operator<Data>::use_temporary_on_evaluate,
542  coeffs_are_simple_expressions = Operator<Data>::coeffs_are_simple_expressions };
544  typedef typename MatrixInfo<typename Operator<Data>::ValueType>::Type Type;
545  typedef typename MatrixInfo<typename Operator<Data>::ValueType>::StorageTraits StorageTraits;
546  };
547 
548  template<template<typename DataType> class Operator, typename Data>
549  struct MatrixInfo<const expressions::expr<Operator, Data> >
550  {
551  enum { is_matrix = MatrixInfo<typename Operator<Data>::ValueType>::is_matrix,
552  is_const = Operator<Data>::is_const,
553  is_math_object = MatrixInfo<typename Operator<Data>::ValueType>::is_math_object,
554  is_expression = true,
555  only_defined_for_matrices = 1,
556  can_move_from = Operator<Data>::can_move_from,
557  can_assign_to = Operator<Data>::can_assign_to,
558  can_resize_rows = Operator<Data>::can_resize_rows,
559  can_resize_cols = Operator<Data>::can_resize_cols,
560  use_temporary_on_evaluate = Operator<Data>::use_temporary_on_evaluate,
561  coeffs_are_simple_expressions = Operator<Data>::coeffs_are_simple_expressions };
563  typedef typename MatrixInfo<typename Operator<Data>::ValueType>::Type Type;
564  typedef typename MatrixInfo<typename Operator<Data>::ValueType>::StorageTraits StorageTraits;
565  };
566  }
567 
571 
572  template<typename T, int R, int C, typename ST, bool MO>
579  void swap(base_matrix<T, R, C, ST, MO> & A, base_matrix<T, R, C, ST, MO> & B) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
580  // We need this overload so that std::swap() won't be used in some obscure cases...
581 
582  template<typename T, int R1, int C1, int R2, int C2, typename ST, bool MO1, bool MO2>
589  void swap(base_matrix<T, R1, C1, ST, MO1> & A, base_matrix<T, R2, C2, ST, MO2> & B) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
590 
591  namespace implementation
592  {
593  using std::swap;
594 
595  template<template<typename AData> class AOp, typename AData, template<typename BData> class BOp, typename BData>
597  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(A.enumerate()) && noexcept(B.enumerate()) &&
598  noexcept(helper::make_type_lvalue<typename implementation::expressions::expr<AOp, AData>::Enumerator>().has_current()) &&
599  noexcept(helper::make_type_lvalue<typename implementation::expressions::expr<AOp, AData>::Enumerator>().next()) &&
600  noexcept(helper::make_type_lvalue<typename implementation::expressions::expr<BOp, BData>::Enumerator>().next()) &&
601  noexcept(swap(helper::make_type_lvalue<typename implementation::expressions::expr<AOp, AData>::Enumerator>().current(),
602  helper::make_type_lvalue<typename implementation::expressions::expr<BOp, BData>::Enumerator>().current())));
603  }
604 
605  template<template<typename AData> class AOp, typename AData, template<typename BData> class BOp, typename BData>
612  void swap(const implementation::expressions::expr<AOp, AData> & A, const implementation::expressions::expr<BOp, BData> & B)
613  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(implementation::do_swap(A, B)));
614 
615  template<template<typename AData> class AOp, typename AData,
616  typename BT, int BRows, int BCols, typename BST, bool BMO>
623  void swap(const implementation::expressions::expr<AOp, AData> & A, base_matrix<BT, BRows, BCols, BST, BMO> & B)
624  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(linalg::swap(A, implementation::expressions::make_matrix_expression(B))));
625 
626  template<typename AT, int ARows, int ACols, typename AST, bool AMO,
627  template<typename BData> class BOp, typename BData>
634  void swap(base_matrix<AT, ARows, ACols, AST, AMO> & A, const implementation::expressions::expr<BOp, BData> & B)
635  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(linalg::swap(implementation::expressions::make_matrix_expression(A), B)));
636 
637  template<typename T,
638  int ARows, int ACols, typename AST, bool AMO,
639  int BRows, int BCols, typename BST, bool BMO>
646  void swap(base_matrix<T, ARows, ACols, AST, AMO> & A, base_matrix<T, BRows, BCols, BST, BMO> & B)
647  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(linalg::swap(implementation::expressions::make_matrix_expression(A), implementation::expressions::make_matrix_expression(B))));
648 
652 
653  template<template<typename SourceData> class SourceOp, typename SourceData, template<typename DestData> class DestOp, typename DestData, bool move>
662  void assign(const implementation::expressions::expr<DestOp, DestData> & destination,
663  const implementation::expressions::expr<SourceOp, SourceData> & source, helper::BoolToType<move> ittm);
664 
665  template<template<typename SourceData> class SourceOp, typename SourceData, template<typename DestData> class DestOp, typename DestData>
672  inline void assign(const implementation::expressions::expr<DestOp, DestData> & destination,
673  const implementation::expressions::expr<SourceOp, SourceData> & source);
674 
675  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO, template<typename DestData> class DestOp, typename DestData>
682  inline void assign(const implementation::expressions::expr<DestOp, DestData> & destination,
683  const base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> & source);
684 
685  template<template<typename SourceData> class SourceOp, typename SourceData, typename DestT, int DestRows, int DestCols, typename DestST, bool DestMO>
692  inline void assign(base_matrix<DestT, DestRows, DestCols, DestST, DestMO> & destination,
693  const implementation::expressions::expr<SourceOp, SourceData> & source);
694 
695  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO,
696  typename DestT, int DestRows, int DestCols, typename DestST, bool DestMO>
703  inline void assign(base_matrix<DestT, DestRows, DestCols, DestST, DestMO> & destination,
704  const base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> & source);
705 
706 #if __cplusplus >= 201103L
707  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO, template<typename DestData> class DestOp, typename DestData>
714  inline void assign(const implementation::expressions::expr<DestOp, DestData> & destination,
715  base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> && source);
716 
717  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO,
718  typename DestT, int DestRows, int DestCols, typename DestST, bool DestMO>
725  inline void assign(base_matrix<DestT, DestRows, DestCols, DestST, DestMO> & destination,
726  base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> && source);
727 #endif
728 
732 
733  template<template<typename SourceData> class SourceOp, typename SourceData, template<typename DestData> class DestOp, typename DestData, bool move>
743  inline void transpose(const implementation::expressions::expr<DestOp, DestData> & destination,
744  const implementation::expressions::expr<SourceOp, SourceData> & source, helper::BoolToType<move> ittm);
745 
746  template<template<typename SourceData> class SourceOp, typename SourceData, template<typename DestData> class DestOp, typename DestData>
755  inline void transpose(const implementation::expressions::expr<DestOp, DestData> & destination,
756  const implementation::expressions::expr<SourceOp, SourceData> & source);
757 
758  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO, template<typename DestData> class DestOp, typename DestData>
767  inline void transpose(const implementation::expressions::expr<DestOp, DestData> & destination,
768  const base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> & source);
769 
770  template<template<typename SourceData> class SourceOp, typename SourceData, typename DestT, int DestRows, int DestCols, typename DestST, bool DestMO>
779  inline void transpose(base_matrix<DestT, DestRows, DestCols, DestST, DestMO> & destination,
780  const implementation::expressions::expr<SourceOp, SourceData> & source);
781 
782  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO,
783  typename DestT, int DestRows, int DestCols, typename DestST, bool DestMO>
792  inline void transpose(base_matrix<DestT, DestRows, DestCols, DestST, DestMO> & destination,
793  const base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> & source);
794 
795 #if __cplusplus >= 201103L
796  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO, template<typename DestData> class DestOp, typename DestData>
805  inline void transpose(const implementation::expressions::expr<DestOp, DestData> & destination,
806  base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> && source);
807 
808  template<typename SourceT, int SourceRows, int SourceCols, typename SourceST, bool SourceMO,
809  typename DestT, int DestRows, int DestCols, typename DestST, bool DestMO>
818  inline void transpose(base_matrix<DestT, DestRows, DestCols, DestST, DestMO> & destination,
819  base_matrix<SourceT, SourceRows, SourceCols, SourceST, SourceMO> && source);
820 #endif
821 
825 
826  namespace implementation
827  {
828  template<int Rows>
830  {
831  public:
832  inline row_count_storage() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
833  {
834  }
835 
836  inline row_count_storage(size_type) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
837  {
838  }
839 
840  template<int R>
841  inline row_count_storage(const row_count_storage<R> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
842  {
843  assert(r.rows() == Rows);
844  }
845 
846  static inline void set_rows(size_type r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
847  {
848  assert(r == Rows);
849  }
850 
851  static inline size_type rows() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
852  {
853  return Rows;
854  }
855 
856  template<int R>
857  static void swap(row_count_storage<R> & other) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
858  {
859  other.set_rows(Rows);
860  }
861  };
862 
863  template<>
865  {
866  protected:
867  size_type d_rows;
868 
869  public:
870  inline row_count_storage() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
871  : d_rows(0)
872  {
873  }
874 
875  inline row_count_storage(size_type rows) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
876  : d_rows(rows)
877  {
878  }
879 
880  template<int R>
881  inline row_count_storage(const row_count_storage<R> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
882  : d_rows(r.rows())
883  {
884  }
885 
886  inline void set_rows(size_type rows) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
887  {
888  d_rows = rows;
889  }
890 
891  inline size_type rows() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
892  {
893  return d_rows;
894  }
895 
896  template<int R>
897  void swap(row_count_storage<R> & other) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
898  {
899  unsigned r = other.rows();
900  other.set_rows(d_rows);
901  d_rows = r;
902  }
903  };
904 
905  template<int Cols>
907  {
908  public:
909  inline col_count_storage() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
910  {
911  }
912 
913  inline col_count_storage(size_type) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
914  {
915  }
916 
917  template<int C>
918  inline col_count_storage(const col_count_storage<C> & c) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
919  {
920  assert(c.cols() == Cols);
921  }
922 
923  static inline void set_cols(size_type c) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
924  {
925  assert(c == Cols);
926  }
927 
928  static inline size_type cols() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
929  {
930  return Cols;
931  }
932 
933  template<int C>
934  static void swap(col_count_storage<C> & other) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
935  {
936  other.set_cols(Cols);
937  }
938  };
939 
940  template<>
942  {
943  protected:
944  size_type d_cols;
945 
946  public:
947  inline col_count_storage() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
948  : d_cols(0)
949  {
950  }
951 
952  inline col_count_storage(size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
953  : d_cols(cols)
954  {
955  }
956 
957  template<int C>
958  inline col_count_storage(const col_count_storage<C> & c) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
959  : d_cols(c.cols())
960  {
961  }
962 
963  inline void set_cols(size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
964  {
965  d_cols = cols;
966  }
967 
968  inline size_type cols() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
969  {
970  return d_cols;
971  }
972 
973  template<int C>
974  void swap(col_count_storage<C> & other) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
975  {
976  unsigned r = other.cols();
977  other.set_cols(d_cols);
978  d_cols = r;
979  }
980  };
981  }
982 
986 
987  template<typename T, int Rows = Flexible, int Cols = Flexible, typename StorageTraits = storage_traits<T>, bool MathObject = false>
1019  {
1020  public:
1021  enum { has_direct_access = true };
1022 
1023 #ifdef PLLL_INTERNAL_NO_TEMPLATE_FRIENDS
1024  public:
1025 #else
1026  template<typename TT, int R, int C, typename ST, bool MO>
1027  friend void swap(base_matrix<TT, R, C, ST, MO> &, base_matrix<TT, R, C, ST, MO> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1028 
1029  template<typename TT, int R1, int C1, int R2, int C2, typename ST, bool MO1, bool MO2>
1030  friend void swap(base_matrix<TT, R1, C1, ST, MO1> &, base_matrix<TT, R2, C2, ST, MO2> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1031 
1032  template<typename TT, int RR, int CC, typename SSTT, bool MMOO>
1033  friend class base_matrix;
1034 
1035  private:
1036  inline static void set_zero(typename StorageTraits::ref_type e, helper::BoolToType<true>)
1037  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(setZero(e)))
1038  {
1039  setZero(e);
1040  }
1041 
1042  inline static void set_zero(typename StorageTraits::ref_type, helper::BoolToType<false>)
1043  PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1044  {
1045  }
1046 
1047  inline static void set_zero(typename StorageTraits::ref_type e)
1048  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(set_zero(e, helper::BoolToType<MathObject>())))
1049  {
1050  set_zero(e, helper::BoolToType<MathObject>());
1051  }
1052 
1053 #endif
1054  typename StorageTraits::pointer_type d_data;
1055 
1056  template<typename MatrixType>
1057  inline void create_from(const MatrixType & mat, helper::BoolToType<true>)
1058  {
1059  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::create_from(" << getAddress(*this) << "; " << getAddress(mat) << ") [1]");
1060  d_data = StorageTraits::clone(mat.data(), implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1061  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1062  }
1063 
1064  template<typename MatrixType>
1065  inline void create_from(const MatrixType & mat, helper::BoolToType<false>)
1066  {
1067  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::create_from(" << getAddress(*this) << "; " << getAddress(mat) << ") [2]");
1068  d_data = StorageTraits::alloc_dontconstruct(implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1069  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1070  if (mat.get_coeff_alwayszero())
1071  {
1072  size_type s = implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols();
1073  for (size_type index = 0; index < s; ++index)
1074  {
1075  StorageTraits::construct(d_data[index]);
1076  set_zero(d_data[index]);
1077  }
1078  }
1079  else
1080  {
1081  typename MatrixType::ConstEnumerator e = mat.enumerate();
1082  for (size_type index = 0; e.has_current(); e.next(), ++index)
1083  if (implementation::MatrixInfo<MatrixType>::coeffs_are_simple_expressions)
1084  StorageTraits::copy_construct(d_data[index], e.current());
1085  else
1086  {
1087  typename MatrixType::ConstEnumerator::GetCoeffSteps_Type coeff = e.get_current_steps();
1088  StorageTraits::copy_construct(d_data[index], coeff.step1());
1089  coeff.step2(d_data[index]);
1090  }
1091  }
1092  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1093  }
1094 
1095 #if __cplusplus >= 201103L
1096  template<typename MatrixType>
1097  inline void move_from(MatrixType && mat, helper::BoolToType<true>)
1098  {
1099  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::create_from(" << getAddress(*this) << "; " << getAddress(mat) << ") [1&&]");
1100  d_data = StorageTraits::clone_move(mat.data(), implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1101  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1102  }
1103 
1104  template<typename MatrixType>
1105  inline void move_from(MatrixType && mat, helper::BoolToType<false>)
1106  {
1107  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::create_from(" << getAddress(*this) << "; " << getAddress(mat) << ") [2&&]");
1108  d_data = StorageTraits::alloc_dontconstruct(implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1109  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1110  if (mat.get_coeff_alwayszero())
1111  {
1112  size_type s = implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols();
1113  for (size_type index = 0; index < s; ++index)
1114  {
1115  StorageTraits::construct(d_data[index]);
1116  set_zero(d_data[index]);
1117  }
1118  }
1119  else
1120  {
1121  typename MatrixType::ConstEnumerator e = mat.enumerate();
1122  for (size_type index = 0; e.has_current(); e.next(), ++index)
1123  if (implementation::MatrixInfo<MatrixType>::coeffs_are_simple_expressions)
1124  StorageTraits::move_construct(d_data[index], std::move(e.current()));
1125  else
1126  {
1127  typename MatrixType::ConstEnumerator::GetCoeffSteps_Type coeff = e.get_current_steps();
1128  StorageTraits::copy_construct(d_data[index], coeff.step1());
1129  coeff.step2(d_data[index]);
1130  }
1131  }
1132  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1133  }
1134 #endif
1135 
1136  public:
1140  typedef typename StorageTraits::constpointer_type data_pointer_type;
1144  typedef typename StorageTraits::constref_type data_ref_type;
1145 
1151  : d_data(StorageTraits::alloc(implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1152  {
1153  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << ")");
1155  }
1156 
1163  : implementation::row_count_storage<Rows>(mat), implementation::col_count_storage<Cols>(mat),
1164  d_data(StorageTraits::clone(mat.d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1165  {
1166  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [0]");
1168  }
1169 
1175  template<int Rs, int Cs, bool MO>
1177  : implementation::row_count_storage<Rows>(mat), implementation::col_count_storage<Cols>(mat),
1178  d_data(StorageTraits::clone(mat.d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1179  {
1180  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [1]");
1181  PLLL_INTERNAL_STATIC_CHECK((Rows < 0) || (Rs < 0) || (Rows == Rs), NotCompatible);
1182  PLLL_INTERNAL_STATIC_CHECK((Cols < 0) || (Cs < 0) || (Cols == Cs), NotCompatible);
1183  if (Rows >= 0) assert(static_cast<size_type>(Rows) == implementation::row_count_storage<Rows>::rows());
1184  if (Cols >= 0) assert(static_cast<size_type>(Cols) == implementation::col_count_storage<Cols>::cols());
1186  }
1187 
1188 #if __cplusplus >= 201103L
1189 
1194  template<bool MO>
1195  inline base_matrix(base_matrix<T, Rows, Cols, StorageTraits, MO> && mat) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1196  : implementation::row_count_storage<Rows>(mat), implementation::col_count_storage<Cols>(mat), d_data(mat.d_data)
1197  {
1198  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [1&&a]");
1199  mat.set_rows(0);
1200  mat.set_cols(0);
1201  mat.d_data = NULL;
1203  }
1204 
1210  template<int Rs, int Cs, bool MO>
1211  base_matrix(base_matrix<T, Rs, Cs, StorageTraits, MO> && mat) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1212  : implementation::row_count_storage<Rows>(mat), implementation::col_count_storage<Cols>(mat), d_data(mat.d_data)
1213  {
1214  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [1&&]");
1215  PLLL_INTERNAL_STATIC_CHECK((Rows < 0) || (Rs < 0) || (Rows == Rs), NotCompatible);
1216  PLLL_INTERNAL_STATIC_CHECK((Cols < 0) || (Cs < 0) || (Cols == Cs), NotCompatible);
1217  if (Rows >= 0) assert(static_cast<size_type>(Rows) == implementation::row_count_storage<Rows>::rows());
1218  if (Cols >= 0) assert(static_cast<size_type>(Cols) == implementation::col_count_storage<Cols>::cols());
1219  mat.set_rows(0);
1220  mat.set_cols(0);
1221  mat.d_data = NULL;
1222  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1223  }
1224 #endif
1225 
1231  template<typename S, int Rs, int Cs, typename ST, bool MO>
1233  : implementation::row_count_storage<Rows>(mat), implementation::col_count_storage<Cols>(mat),
1234  d_data(StorageTraits::clone(mat.d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1235  {
1236  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [2]");
1237  PLLL_INTERNAL_STATIC_CHECK((Rows < 0) || (Rs < 0) || (Rows == Rs), NotCompatible);
1238  PLLL_INTERNAL_STATIC_CHECK((Cols < 0) || (Cs < 0) || (Cols == Cs), NotCompatible);
1239  if (Rows >= 0) assert(static_cast<size_type>(Rows) == implementation::row_count_storage<Rows>::rows());
1240  if (Cols >= 0) assert(static_cast<size_type>(Cols) == implementation::col_count_storage<Cols>::cols());
1242  }
1243 
1244 #if __cplusplus >= 201103L
1245 
1250  template<typename S, int Rs, int Cs, typename ST, bool MO>
1252  : implementation::row_count_storage<Rows>(mat), implementation::col_count_storage<Cols>(mat),
1253  d_data(StorageTraits::clone_move(mat.d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1254  {
1255  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [2&&]");
1256  PLLL_INTERNAL_STATIC_CHECK((Rows < 0) || (Rs < 0) || (Rows == Rs), NotCompatible);
1257  PLLL_INTERNAL_STATIC_CHECK((Cols < 0) || (Cs < 0) || (Cols == Cs), NotCompatible);
1258  if (Rows >= 0) assert(static_cast<size_type>(Rows) == implementation::row_count_storage<Rows>::rows());
1259  if (Cols >= 0) assert(static_cast<size_type>(Cols) == implementation::col_count_storage<Cols>::cols());
1261  }
1262 #endif
1263 
1269  template<template<typename> class Op, typename Data>
1271  : implementation::row_count_storage<Rows>(mat.rows()), implementation::col_count_storage<Cols>(mat.cols()), d_data(NULL)
1272  {
1273  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [3]");
1275  (static_cast<size_type>(Rows) == static_cast<size_type>(implementation::MatrixInfo<implementation::expressions::expr<Op, Data> >::rows)), NotCompatible);
1277  (static_cast<size_type>(Cols) == static_cast<size_type>(implementation::MatrixInfo<implementation::expressions::expr<Op, Data> >::cols)), NotCompatible);
1278  if (Rows >= 0) assert(static_cast<size_type>(Rows) == implementation::row_count_storage<Rows>::rows());
1279  if (Cols >= 0) assert(static_cast<size_type>(Cols) == implementation::col_count_storage<Cols>::cols());
1282  }
1283 
1284 #if __cplusplus >= 201103L
1285 
1290  template<template<typename> class Op, typename Data>
1292  : implementation::row_count_storage<Rows>(mat.rows()), implementation::col_count_storage<Cols>(mat.cols()), d_data(NULL)
1293  {
1294  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [3&&]");
1296  (static_cast<size_type>(Rows) == static_cast<size_type>(implementation::MatrixInfo<implementation::expressions::expr<Op, Data> >::rows)), NotCompatible);
1298  (static_cast<size_type>(Cols) == static_cast<size_type>(implementation::MatrixInfo<implementation::expressions::expr<Op, Data> >::cols)), NotCompatible);
1299  if (Rows >= 0) assert(static_cast<size_type>(Rows) == implementation::row_count_storage<Rows>::rows());
1300  if (Cols >= 0) assert(static_cast<size_type>(Cols) == implementation::col_count_storage<Cols>::cols());
1303  else
1306  }
1307 #endif
1308 
1319  : implementation::row_count_storage<Rows>(entries), implementation::col_count_storage<Cols>(entries),
1320  d_data(StorageTraits::alloc(implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1321  {
1322  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << entries << ") [4]");
1323  PLLL_INTERNAL_STATIC_CHECK((Cols == 1) || (Rows == 1), ConstructorOnlyAvailableForVectors);
1325  }
1326 
1336  base_matrix(int entries)
1337  : implementation::row_count_storage<Rows>(entries), implementation::col_count_storage<Cols>(entries),
1338  d_data(StorageTraits::alloc(implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1339  {
1340  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << entries << ") [4b]");
1341  PLLL_INTERNAL_STATIC_CHECK((Cols == 1) || (Rows == 1), ConstructorOnlyAvailableForVectors);
1343  }
1344 
1355  template<typename S, bool def>
1357  : implementation::row_count_storage<Rows>(entries), implementation::col_count_storage<Cols>(entries),
1358  d_data(StorageTraits::alloc(i.ref(), implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1359  {
1360  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << entries << " " << getAddress(i.ref()) << ") [5]");
1361  PLLL_INTERNAL_STATIC_CHECK((Cols == 1) || (Rows == 1), ConstructorOnlyAvailableForVectors);
1363  }
1364 
1373  : implementation::row_count_storage<Rows>(rows), implementation::col_count_storage<Cols>(cols),
1374  d_data(StorageTraits::alloc(implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1375  {
1376  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << rows << " " << cols << ") [6]");
1377  if (Rows >= 0) assert(rows == static_cast<size_type>(Rows));
1378  if (Cols >= 0) assert(cols == static_cast<size_type>(Cols));
1380  }
1381 
1390  template<typename S, bool def>
1392  : implementation::row_count_storage<Rows>(rows), implementation::col_count_storage<Cols>(cols),
1393  d_data(StorageTraits::alloc(i.ref(), implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols()))
1394  {
1395  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::base_matrix(" << getAddress(*this) << "; " << rows << " " << cols << " " << getAddress(i.ref()) << ") [7]");
1396  if (Rows >= 0) assert(rows == static_cast<size_type>(Rows));
1397  if (Cols >= 0) assert(cols == static_cast<size_type>(Cols));
1399  }
1400 
1404  inline ~base_matrix() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1405  {
1407  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::~base_matrix(" << getAddress(*this) << ")");
1409  }
1410 
1417  {
1418  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator = (" << getAddress(*this) << "; " << getAddress(m) << ") [0]");
1420  assign(*this, m);
1422  return *this;
1423  }
1424 
1430  template<typename T_, int Rows_, int Cols_, typename StorageTraits_, bool MathObject_>
1432  {
1433  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator = (" << getAddress(*this) << "; " << getAddress(m) << ") [1]");
1435  assign(*this, m);
1437  return *this;
1438  }
1439 
1445  template<template<typename> class Op, typename Data>
1447  {
1448  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator = (" << getAddress(*this) << "; " << getAddress(m) << ") [2]");
1451  assign(*this, m);
1453  return *this;
1454  }
1455 
1456 #if __cplusplus >= 201103L
1457 
1463  PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1464  {
1465  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator = (" << getAddress(*this) << "; " << getAddress(m) << ") [0&&]");
1470  m.implementation::row_count_storage<Rows>::set_rows(0);
1471  m.implementation::col_count_storage<Cols>::set_cols(0);
1472  d_data = m.d_data;
1473  m.d_data = NULL;
1475  return *this;
1476  }
1477 
1483  template<typename T_, int Rows_, int Cols_, typename StorageTraits_, bool MathObject_>
1484  base_matrix<T, Rows, Cols, StorageTraits, MathObject> & operator = (base_matrix<T_, Rows_, Cols_, StorageTraits_, MathObject_> && m)
1485  {
1486  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator = (" << getAddress(*this) << "; " << getAddress(m) << ") [1&&]");
1487  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1488  assign(*this, std::move(m));
1489  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1490  return *this;
1491  }
1492 
1498  template<template<typename> class Op, typename Data>
1499  base_matrix<T, Rows, Cols, StorageTraits, MathObject> & operator = (implementation::expressions::expr<Op, Data> && m)
1500  {
1501  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator = (" << getAddress(*this) << "; " << getAddress(m) << ") [2&&]");
1502  PLLL_INTERNAL_STATIC_CHECK((implementation::MatrixInfo<implementation::expressions::expr<Op, Data> >::is_matrix), RequiresMatrixType);
1503  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1504  assign(*this, std::move(m));
1505  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
1506  return *this;
1507  }
1508 #endif
1509 
1517  template<typename ResultType>
1518  inline void get_coeff(ResultType & result, size_type i, size_type j) const
1519  PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result = d_data[i * implementation::col_count_storage<Cols>::cols() + j]))
1520  {
1521  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::get_coeff(" << getAddress(*this) << "; " << getAddress(result) << " " << i << " " << j << ") const");
1525  result = d_data[i * implementation::col_count_storage<Cols>::cols() + j];
1527  }
1528 
1534  inline bool get_coeff_alwayszero() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1535  {
1536  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::get_coeff_alwayszero(" << getAddress(*this) << ") const");
1538  return false;
1539  }
1540 
1545  {
1546  friend class base_matrix<T, Rows, Cols, StorageTraits, MathObject>;
1547 
1548  protected:
1549  typename StorageTraits::constref_type d_value;
1550 
1551  inline GetCoeffSteps_Type(typename StorageTraits::constref_type value) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1552  : d_value(value)
1553  {
1554  }
1555 
1556  public:
1558  typedef typename StorageTraits::constref_type Step1_Type;
1559 
1565  inline Step1_Type step1() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1566  {
1567  return d_value;
1568  }
1569 
1575  template<typename ResultType>
1576  inline void step2(ResultType & result) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1577  {
1578  }
1579  };
1580 
1592  inline GetCoeffSteps_Type get_coeff_steps(size_type i, size_type j) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1593  {
1594  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::get_coeff_steps(" << getAddress(*this) << "; " << i << " " << j << ") const");
1598  return GetCoeffSteps_Type(d_data[i * implementation::col_count_storage<Cols>::cols() + j]);
1599  }
1600 
1608  inline typename StorageTraits::constref_type operator () (size_type i, size_type j) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1609  {
1610  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator () (" << getAddress(*this) << "; " << i << " " << j << ") const");
1614  return d_data[i * implementation::col_count_storage<Cols>::cols() + j];
1615  }
1616 
1624  inline typename StorageTraits::ref_type operator () (size_type i, size_type j) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1625  {
1626  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator () (" << getAddress(*this) << "; " << i << " " << j << ")");
1630  return d_data[i * implementation::col_count_storage<Cols>::cols() + j];
1631  }
1632 
1642  inline typename StorageTraits::constref_type operator [] (size_type i) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1643  {
1644  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator [] (" << getAddress(*this) << "; " << i << ") const");
1645  PLLL_INTERNAL_STATIC_CHECK((Cols == 1) || (Rows == 1), OnlyDefinedForVectors);
1646  StorageTraits::check(d_data, (Cols == 1) ? implementation::row_count_storage<Rows>::rows() : implementation::col_count_storage<Cols>::cols());
1648  return d_data[i];
1649  }
1650 
1660  inline typename StorageTraits::ref_type operator [] (size_type i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1661  {
1662  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::operator [] (" << getAddress(*this) << "; " << i << ")");
1663  PLLL_INTERNAL_STATIC_CHECK((Cols == 1) || (Rows == 1), OnlyDefinedForVectors);
1664  StorageTraits::check(d_data, (Cols == 1) ? implementation::row_count_storage<Rows>::rows() : implementation::col_count_storage<Cols>::cols());
1666  return d_data[i];
1667  }
1668 
1674  inline typename StorageTraits::constpointer_type data() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1675  {
1676  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::data(" << getAddress(*this) << ") const");
1678  return d_data;
1679  }
1680 
1686  inline typename StorageTraits::pointer_type data() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1687  {
1688  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::data(" << getAddress(*this) << ")");
1690  return d_data;
1691  }
1692 
1699  inline typename StorageTraits::constref_type data(size_type i) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1700  {
1701  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::data(" << getAddress(*this) << "; " << i << ") const");
1703  return d_data[i];
1704  }
1705 
1712  inline typename StorageTraits::ref_type data(size_type i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1713  {
1714  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::data(" << getAddress(*this) << "; " << i << ")");
1716  return d_data[i];
1717  }
1718 
1724  inline size_type rows() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1725  {
1726  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::rows(" << getAddress(*this) << ") const");
1728  }
1729 
1735  inline size_type cols() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1736  {
1737  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::cols(" << getAddress(*this) << ") const");
1739  }
1740 
1746  inline size_type size() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1747  {
1748  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::size(" << getAddress(*this) << ") const");
1750  }
1751 
1761  template<unsigned SRows, unsigned SCols>
1764  block(size_type r_ofs, size_type c_ofs)
1765  {
1766  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::block<" << SRows << " " << SCols << ">(" << getAddress(*this) << "; " << r_ofs << " " << c_ofs << ")");
1769  (typename implementation::expressions::sub<SRows, SCols>::template operation_generic<implementation::expressions::MatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(SRows, SCols,
1770  r_ofs, c_ofs, *this),
1771  implementation::expressions::make_matrix_wrapper(*this));
1772  }
1773 
1785  template<unsigned SRows, unsigned SCols>
1788  block(size_type r_ofs, size_type c_ofs) const
1789  {
1790  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::block<" << SRows << " " << SCols << ">(" << getAddress(*this) << "; " << r_ofs << " " << c_ofs << ") const");
1793  (typename implementation::expressions::sub<SRows, SCols>::template operation_generic<implementation::expressions::ConstMatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(SRows, SCols,
1794  r_ofs, c_ofs, *this),
1795  implementation::expressions::make_matrix_wrapper(*this));
1796  }
1797 
1813  {
1814  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::block(" << getAddress(*this) << "; " << r_ofs << " " << c_ofs << " " << rows << " " << cols << ")");
1817  (typename implementation::expressions::sub<Flexible, Flexible>::template operation_generic<implementation::expressions::MatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(rows, cols,
1818  r_ofs, c_ofs, *this),
1819  implementation::expressions::make_matrix_wrapper(*this));
1820  }
1821 
1837  {
1838  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::block(" << getAddress(*this) << "; " << r_ofs << " " << c_ofs << " " << rows << " " << cols << ") const");
1841  (typename implementation::expressions::sub<Flexible, Flexible>::template operation_generic<implementation::expressions::ConstMatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(rows, cols,
1842  r_ofs, c_ofs, *this),
1843  implementation::expressions::make_matrix_wrapper(*this));
1844  }
1845 
1854  row(size_type row_index)
1855  {
1856  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::row(" << getAddress(*this) << "; " << row_index << ")");
1859  (typename implementation::expressions::sub_1d<Cols>::template operation_row<implementation::expressions::MatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(implementation::col_count_storage<Cols>::cols(),
1860  row_index, *this),
1861  implementation::expressions::make_matrix_wrapper(*this));
1862  }
1863 
1872  row(size_type row_index) const
1873  {
1874  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::row(" << getAddress(*this) << "; " << row_index << ") const");
1877  (typename implementation::expressions::sub_1d<Cols>::template operation_row<implementation::expressions::ConstMatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(implementation::col_count_storage<Cols>::cols(),
1878  row_index, *this),
1879  implementation::expressions::make_matrix_wrapper(*this));
1880  }
1881 
1890  col(size_type col_index)
1891  {
1892  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::col(" << getAddress(*this) << "; " << col_index << ")");
1895  (typename implementation::expressions::sub_1d<Rows>::template operation_col<implementation::expressions::MatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(implementation::row_count_storage<Rows>::rows(),
1896  col_index, *this),
1897  implementation::expressions::make_matrix_wrapper(*this));
1898  }
1899 
1908  col(size_type col_index) const
1909  {
1910  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::col(" << getAddress(*this) << "; " << col_index << ") const");
1913  (typename implementation::expressions::sub_1d<Rows>::template operation_col<implementation::expressions::ConstMatrixWrapper<base_matrix<T, Rows, Cols, StorageTraits, MathObject> > >(implementation::row_count_storage<Rows>::rows(),
1914  col_index, *this),
1915  implementation::expressions::make_matrix_wrapper(*this));
1916  }
1917 
1925  transpose() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1926  {
1927  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::transpose(" << getAddress(*this) << ")");
1930  (implementation::expressions::make_matrix_wrapper(*this));
1931  }
1932 
1940  transpose() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1941  {
1942  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::transpose(" << getAddress(*this) << ") const");
1945  (implementation::expressions::make_matrix_wrapper(*this));
1946  }
1947 
1957  void resize(size_type new_size)
1958  {
1959  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::resize(" << getAddress(*this) << "; " << new_size << ") [1]");
1960  // Check
1961  PLLL_INTERNAL_STATIC_CHECK((Cols == 1) || (Rows == 1), OnlyDefinedForVectors);
1962  assert(((Cols == 1) && ((Rows < 0) || (new_size == static_cast<size_type>(Rows)))) ||
1963  ((Rows == 1) && ((Cols < 0) || (new_size == static_cast<size_type>(Cols)))));
1964  if ((Cols == 1) ? (new_size == implementation::row_count_storage<Rows>::rows()) : (new_size == implementation::col_count_storage<Cols>::cols()))
1965  return;
1966  // Allocate new space (don't construct yet!)
1967  StorageTraits::check(d_data, (Cols == 1) ? implementation::row_count_storage<Rows>::rows() : implementation::col_count_storage<Cols>::cols());
1968 #if __cplusplus >= 201103L
1969  typename StorageTraits::pointer_type new_data = StorageTraits::clone_move(d_data, new_size,
1972 #else
1973  typename StorageTraits::pointer_type new_data = StorageTraits::clone(d_data, new_size,
1976 #endif
1977  // Copy over new data
1979  d_data = new_data;
1980  if (Cols == 1)
1982  else
1984  StorageTraits::check(d_data, (Cols == 1) ? implementation::row_count_storage<Rows>::rows() : implementation::col_count_storage<Cols>::cols());
1985  }
1986 
1997  template<typename S, bool def>
1999  {
2000  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::resize(" << getAddress(*this) << "; " << new_size << " " << getAddress(init.ref()) << ") [1]");
2001  // Check
2002  PLLL_INTERNAL_STATIC_CHECK((Cols == 1) || (Rows == 1), OnlyDefinedForVectors);
2003  assert(((Cols == 1) && ((Rows < 0) || (new_size == static_cast<size_type>(Rows)))) ||
2004  ((Rows == 1) && ((Cols < 0) || (new_size == static_cast<size_type>(Cols)))));
2005  if ((Cols == 1) ? (new_size == implementation::row_count_storage<Rows>::rows()) : (new_size == implementation::col_count_storage<Cols>::cols()))
2006  return;
2007  // Allocate new space (don't construct yet!)
2008  StorageTraits::check(d_data, (Cols == 1) ? implementation::row_count_storage<Rows>::rows() : implementation::col_count_storage<Cols>::cols());
2009 #if __cplusplus >= 201103L
2010  typename StorageTraits::pointer_type new_data = StorageTraits::clone_move(d_data, new_size,
2013 #else
2014  typename StorageTraits::pointer_type new_data = StorageTraits::clone(d_data, new_size,
2017 #endif
2018  // Copy over new data
2020  d_data = new_data;
2021  if (Cols == 1)
2023  else
2025  StorageTraits::check(d_data, (Cols == 1) ? implementation::row_count_storage<Rows>::rows() : implementation::col_count_storage<Cols>::cols());
2026  }
2027 
2036  void resize(size_type new_rows, size_type new_cols)
2037  {
2038  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::resize(" << getAddress(*this) << "; " << new_rows << " " << new_cols << ") [2]");
2039  // Check
2041  assert((Rows < 0) || (new_rows == static_cast<size_type>(Rows)));
2042  assert((Cols < 0) || (new_cols == static_cast<size_type>(Cols)));
2043  // Allocate new space (don't construct yet!)
2045  typename StorageTraits::pointer_type new_data = StorageTraits::alloc_dontconstruct(new_rows * new_cols);
2046  // Copy existing and construct the rest
2047  size_type min_cols = std::min(new_cols, implementation::col_count_storage<Cols>::cols());
2048  size_type source_index = 0, dest_index = 0;
2049  for (size_type i = (Rows < 0 ? std::min(new_rows, implementation::row_count_storage<Rows>::rows()) : Rows); i > 0; --i)
2050  {
2051  for (size_type j = (Cols < 0 ? min_cols : Cols); j > 0; --j, ++source_index, ++dest_index)
2052 #if __cplusplus >= 201103L
2053  StorageTraits::move_construct(new_data[dest_index], std::move(d_data[source_index]));
2054 #else
2055  StorageTraits::copy_construct(new_data[dest_index], d_data[source_index]);
2056 #endif
2058  {
2059  for (size_type j = new_cols - implementation::col_count_storage<Cols>::cols(); j > 0; --j, ++dest_index)
2060  StorageTraits::construct(new_data[dest_index]);
2061  }
2062  else
2063  source_index += implementation::col_count_storage<Cols>::cols() - new_cols;
2064  }
2065  // Construct the rest
2066  if ((Rows < 0) && (implementation::row_count_storage<Rows>::rows() < new_rows))
2067  {
2068  size_type s = (new_rows - implementation::row_count_storage<Rows>::rows()) * (Cols < 0 ? new_cols : Cols);
2069  for (; s > 0; --s, ++dest_index)
2070  StorageTraits::construct(new_data[dest_index]);
2071  }
2072  // Copy over new data
2075  d_data = new_data;
2079  }
2080 
2090  template<typename S, bool def>
2092  {
2093  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::resize(" << getAddress(*this) << "; " << new_rows << " " << new_cols << " " << getAddress(init.ref()) << ") [3]");
2094  // Check
2096  assert((Rows < 0) || (new_rows == static_cast<size_type>(Rows)));
2097  assert((Cols < 0) || (new_cols == static_cast<size_type>(Cols)));
2098  // Allocate new space (don't construct yet!)
2100  typename StorageTraits::pointer_type new_data = StorageTraits::alloc_dontconstruct(new_rows * new_cols);
2101  // Copy existing and construct the rest
2102  size_type min_cols = std::min(new_cols, implementation::col_count_storage<Cols>::cols());
2103  size_type source_index = 0, dest_index = 0;
2104  for (size_type i = (Rows < 0 ? std::min(new_rows, implementation::row_count_storage<Rows>::rows()) : Rows); i > 0; --i)
2105  {
2106  for (size_type j = (Cols < 0 ? min_cols : Cols); j > 0; --j, ++source_index, ++dest_index)
2107 #if __cplusplus >= 201103L
2108  StorageTraits::move_construct(new_data[dest_index], std::move(d_data[source_index]));
2109 #else
2110  StorageTraits::copy_construct(new_data[dest_index], d_data[source_index]);
2111 #endif
2113  {
2114  for (size_type j = new_cols - implementation::col_count_storage<Cols>::cols(); j > 0; --j, ++dest_index)
2115  StorageTraits::copy_construct(new_data[dest_index], init.ref());
2116  }
2117  else
2118  source_index += implementation::col_count_storage<Cols>::cols() - new_cols;
2119  }
2120  // Construct the rest
2121  if ((Rows < 0) && (implementation::row_count_storage<Rows>::rows() < new_rows))
2122  {
2123  size_type s = (new_rows - implementation::row_count_storage<Rows>::rows()) * (Cols < 0 ? new_cols : Cols);
2124  for (; s > 0; --s, ++dest_index)
2125  StorageTraits::copy_construct(new_data[dest_index], init.ref());
2126  }
2127  // Copy over new data
2130  d_data = new_data;
2134  }
2135 
2145  template<typename MatrixType>
2146  void assign_resize(const MatrixType & mat)
2147  {
2148  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::assign_resize(" << getAddress(*this) << "; " << getAddress(mat) << ")");
2149  // Check
2150  assert((Rows < 0) || (mat.rows() == static_cast<size_type>(Rows)));
2151  assert((Cols < 0) || (mat.cols() == static_cast<size_type>(Cols)));
2152  // Allocate new space (don't construct yet!)
2153  size_type new_rows = mat.rows(), new_cols = mat.cols();
2155  typename StorageTraits::pointer_type new_data = StorageTraits::alloc_dontconstruct(new_rows * new_cols);
2156  // Construct entries from old matrix
2157  if (mat.get_coeff_alwayszero())
2158  {
2160  for (size_type index = 0; index < s; ++index)
2161  {
2162  StorageTraits::construct(new_data[index]);
2163  set_zero(new_data[index]);
2164  }
2165  }
2166  else
2167  {
2168  typename MatrixType::ConstEnumerator e = mat.enumerate();
2169  for (size_type index = 0; e.has_current(); e.next(), ++index)
2171  StorageTraits::copy_construct(new_data[index], e.current());
2172  else
2173  {
2174  typename MatrixType::ConstEnumerator::GetCoeffSteps_Type coeff = e.get_current_steps();
2175  StorageTraits::copy_construct(new_data[index], coeff.step1());
2176  coeff.step2(new_data[index]);
2177  }
2178  }
2179  // Free old matrix
2182  // Copy over new data
2183  d_data = new_data;
2187  }
2188 
2189 #if __cplusplus >= 201103L
2190  template<bool MO>
2191  inline void move_resize(base_matrix<T, Rows, Cols, StorageTraits, MO> && mat) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2192  {
2193  *this = std::move(mat);
2194  }
2195 
2205  template<typename MatrixType>
2206  void move_resize(MatrixType && mat)
2207  {
2208  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::assign_resize(" << getAddress(*this) << "; " << getAddress(mat) << ")");
2209  PLLL_INTERNAL_STATIC_CHECK(implementation::MatrixInfo<MatrixType>::can_move_from, CannotMoveFromMatrix);
2210  // Check
2211  assert((Rows < 0) || (mat.rows() == static_cast<size_type>(Rows)));
2212  assert((Cols < 0) || (mat.cols() == static_cast<size_type>(Cols)));
2213  // Allocate new space (don't construct yet!)
2214  size_type new_rows = mat.rows(), new_cols = mat.cols();
2215  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
2216  typename StorageTraits::pointer_type new_data = StorageTraits::alloc_dontconstruct(new_rows * new_cols);
2217  // Construct entries from old matrix
2218  if (mat.get_coeff_alwayszero())
2219  {
2220  size_type s = implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols();
2221  for (size_type index = 0; index < s; ++index)
2222  {
2223  StorageTraits::construct(new_data[index]);
2224  set_zero(new_data[index]);
2225  }
2226  }
2227  else
2228  {
2229  typename MatrixType::ConstEnumerator e = mat.enumerate();
2230  for (size_type index = 0; e.has_current(); e.next(), ++index)
2231  if (implementation::MatrixInfo<MatrixType>::coeffs_are_simple_expressions)
2232  StorageTraits::move_construct(new_data[index], std::move(e.current()));
2233  else
2234  {
2235  typename MatrixType::ConstEnumerator::GetCoeffSteps_Type coeff = e.get_current_steps();
2236  StorageTraits::copy_construct(new_data[index], coeff.step1());
2237  coeff.step2(new_data[index]);
2238  }
2239  }
2240  // Free old matrix
2241  StorageTraits::check(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
2242  StorageTraits::free(d_data, implementation::row_count_storage<Rows>::rows() * implementation::col_count_storage<Cols>::cols());
2243  // Copy over new data
2244  d_data = new_data;
2245  implementation::row_count_storage<Rows>::set_rows(new_rows);
2246  implementation::col_count_storage<Cols>::set_cols(new_cols);
2247  }
2248 #else
2249 
2258  template<typename MatrixType>
2259  void move_resize(const MatrixType & mat)
2260  {
2261  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::assign_resize(" << getAddress(*this) << "; " << getAddress(mat) << ")");
2263  // Check
2264  assert((Rows < 0) || (mat.rows() == static_cast<size_type>(Rows)));
2265  assert((Cols < 0) || (mat.cols() == static_cast<size_type>(Cols)));
2266  // Allocate new space (don't construct yet!)
2267  size_type new_rows = mat.rows(), new_cols = mat.cols();
2268  typename StorageTraits::pointer_type new_data = StorageTraits::alloc_dontconstruct(new_rows * new_cols);
2269  // Construct entries from old matrix
2270  if (mat.get_coeff_alwayszero())
2271  {
2273  for (size_type index = 0; index < s; ++index)
2274  {
2275  StorageTraits::construct(new_data[index]);
2276  set_zero(new_data[index]);
2277  }
2278  }
2279  else
2280  {
2281  typename MatrixType::ConstEnumerator e = mat.enumerate();
2282  for (size_type index = 0; e.has_current(); e.next(), ++index)
2284  StorageTraits::copy_construct(new_data[index], e.current());
2285  else
2286  {
2287  typename MatrixType::ConstEnumerator::GetCoeffSteps_Type coeff = e.get_current_steps();
2288  StorageTraits::copy_construct(new_data[index], coeff.step1());
2289  coeff.step2(new_data[index]);
2290  }
2291  }
2292  // Free old matrix
2294  // Copy over new data
2295  d_data = new_data;
2299  }
2300 #endif
2301 
2307  template<typename MatrixType>
2308  inline void swap(MatrixType & B)
2309  {
2310  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::swap(" << getAddress(*this) << "; " << getAddress(B) << ")");
2312  linalg::swap(*this, B);
2314  }
2315 
2323  inline bool involves_this_matrix(const base_matrix<T, Rows, Cols, StorageTraits, MathObject> & A) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2324  {
2325  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::involves_this_matrix(" << getAddress(*this) << "; " << getAddress(A) << ") [1]");
2326  return &A == this;
2327  }
2328 
2337  template<typename MatrixType>
2338  inline bool involves_this_matrix(const MatrixType & A) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2339  {
2340  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::involves_this_matrix(" << getAddress(*this) << "; " << getAddress(A) << ") [2]");
2341  return false;
2342  }
2343 
2352  template<typename MatrixType>
2353  inline bool test_involvement(const MatrixType & A) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2354  {
2355  PLLL_DEBUG_OUTPUT_MESSAGE("base_matrix::test_involvement(" << getAddress(*this) << "; " << getAddress(A) << ")");
2356  return A.involves_this_matrix(*this);
2357  }
2358 
2359  class ConstEnumerator;
2360 
2369  {
2370  friend class ConstEnumerator;
2371 
2372  private:
2373  T * d_entry;
2374  size_type d_left;
2375 
2376  public:
2380  typedef T & Type;
2385 
2386  inline Enumerator(T * entry, size_type left) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2387  : d_entry(entry), d_left(left)
2388  {
2389  }
2390 
2396  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2397  {
2398  return *d_entry;
2399  }
2400 
2406  template<typename Result>
2407  inline void get_current(Result & result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result = *d_entry))
2408  {
2409  result = *d_entry;
2410  }
2411 
2417  inline GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2418  {
2419  return GetCoeffSteps_Type(*d_entry);
2420  }
2421 
2428  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2429  {
2430  return d_left > 0;
2431  }
2432 
2438  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2439  {
2440  --d_left;
2441  ++d_entry;
2442  }
2443  };
2444 
2453  {
2454  private:
2455  const T * d_entry;
2456  size_type d_left;
2457 
2458  public:
2462  typedef const T & Type;
2467 
2468  inline ConstEnumerator(const Enumerator & e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2469  : d_entry(e.d_entry), d_left(e.d_left)
2470  {
2471  }
2472 
2473 #if __cplusplus >= 201103L
2474  inline ConstEnumerator(Enumerator && e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2475  : d_entry(e.d_entry), d_left(e.d_left)
2476  {
2477  }
2478 #endif
2479 
2480  inline ConstEnumerator(const T * entry, size_type left) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2481  : d_entry(entry), d_left(left)
2482  {
2483  }
2484 
2490  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2491  {
2492  return *d_entry;
2493  }
2494 
2500  template<typename Result>
2501  inline void get_current(Result & result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result = *d_entry))
2502  {
2503  result = *d_entry;
2504  }
2505 
2511  inline GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2512  {
2513  return GetCoeffSteps_Type(*d_entry);
2514  }
2515 
2522  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2523  {
2524  return d_left > 0;
2525  }
2526 
2532  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2533  {
2534  --d_left;
2535  ++d_entry;
2536  }
2537  };
2538 
2539  typedef Enumerator DefaultEnumerator;
2540 
2541  typedef Enumerator RowEnumerator;
2542  typedef ConstEnumerator ConstRowEnumerator;
2543  typedef DefaultEnumerator DefaultRowEnumerator;
2544 
2545  class ConstColEnumerator;
2546 
2553  {
2554  friend class ConstColEnumerator;
2555 
2556  private:
2557  size_type d_left;
2558  T * d_entry;
2559 
2560  public:
2564  typedef T & Type;
2569 
2570  inline ColEnumerator(T * entry, size_type left, size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2571  : implementation::col_count_storage<Cols>(cols), d_left(left), d_entry(entry)
2572  {
2573  }
2574 
2580  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2581  {
2582  return *d_entry;
2583  }
2584 
2590  template<typename Result>
2591  inline void get_current(Result & result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result = *d_entry))
2592  {
2593  result = *d_entry;
2594  }
2595 
2601  inline GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2602  {
2603  return GetCoeffSteps_Type(*d_entry);
2604  }
2605 
2612  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2613  {
2614  return d_left > 0;
2615  }
2616 
2622  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2623  {
2624  --d_left;
2626  }
2627  };
2628 
2635  {
2636  private:
2637  size_type d_left;
2638  const T * d_entry;
2639 
2640  public:
2644  typedef const T & Type;
2649 
2650  inline ConstColEnumerator(const ColEnumerator & e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2651  : implementation::col_count_storage<Cols>(e), d_left(e.d_left), d_entry(e.d_entry)
2652  {
2653  }
2654 
2655 #if __cplusplus >= 201103L
2656  inline ConstColEnumerator(ColEnumerator && e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2657  : implementation::col_count_storage<Cols>(e), d_left(e.d_left), d_entry(e.d_entry)
2658  {
2659  }
2660 #endif
2661 
2662  inline ConstColEnumerator(const T * entry, size_type left, size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2663  : implementation::col_count_storage<Cols>(cols), d_left(left), d_entry(entry)
2664  {
2665  }
2666 
2672  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2673  {
2674  return *d_entry;
2675  }
2676 
2682  template<typename Result>
2683  inline void get_current(Result & result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result = *d_entry))
2684  {
2685  result = *d_entry;
2686  }
2687 
2693  inline GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2694  {
2695  return GetCoeffSteps_Type(*d_entry);
2696  }
2697 
2704  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2705  {
2706  return d_left > 0;
2707  }
2708 
2714  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2715  {
2716  --d_left;
2718  }
2719  };
2720 
2721  typedef ColEnumerator DefaultColEnumerator;
2722 
2728  inline Enumerator enumerate() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2729  {
2730  return Enumerator(d_data, size());
2731  }
2732 
2738  inline ConstEnumerator enumerate() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2739  {
2740  return ConstEnumerator(d_data, size());
2741  }
2742 
2749  inline RowEnumerator enumerate_row(size_type row) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2750  {
2752  return RowEnumerator(d_data + row * cols(), cols());
2753  }
2754 
2761  inline ConstRowEnumerator enumerate_row(size_type row) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2762  {
2764  return ConstRowEnumerator(d_data + row * cols(), cols());
2765  }
2766 
2773  inline ColEnumerator enumerate_col(size_type col) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2774  {
2776  return ColEnumerator(d_data + col, rows(), cols());
2777  }
2778 
2785  inline ConstColEnumerator enumerate_col(size_type col) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2786  {
2788  return ConstColEnumerator(d_data + col, rows(), cols());
2789  }
2790 
2791  class ConstRowsEnumerator;
2792 
2798  {
2799  friend class ConstRowsEnumerator;
2800 
2801  private:
2802  size_type d_left;
2803  T * d_entry;
2804 
2805  public:
2810 
2811  inline RowsEnumerator(T * entry, size_type rows, size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2812  : implementation::col_count_storage<Cols>(cols), d_left(rows), d_entry(entry)
2813  {
2814  }
2815 
2821  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2822  {
2824  }
2825 
2832  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2833  {
2834  return d_left > 0;
2835  }
2836 
2842  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2843  {
2844  --d_left;
2846  }
2847  };
2848 
2855  {
2856  private:
2857  size_type d_left;
2858  const T * d_entry;
2859 
2860  public:
2865 
2866  inline ConstRowsEnumerator(const RowsEnumerator & e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2867  : implementation::col_count_storage<Cols>(e), d_left(e.d_left), d_entry(e.d_entry)
2868  {
2869  }
2870 
2871 #if __cplusplus >= 201103L
2872  inline ConstRowsEnumerator(RowsEnumerator && e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2873  : implementation::col_count_storage<Cols>(e), d_left(e.d_left), d_entry(e.d_entry)
2874  {
2875  }
2876 #endif
2877 
2878  inline ConstRowsEnumerator(const T * entry, size_type rows, size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2879  : implementation::col_count_storage<Cols>(cols), d_left(rows), d_entry(entry)
2880  {
2881  }
2882 
2888  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2889  {
2891  }
2892 
2899  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2900  {
2901  return d_left > 0;
2902  }
2903 
2909  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2910  {
2911  --d_left;
2913  }
2914  };
2915 
2916  class ConstColsEnumerator;
2917 
2924  {
2925  friend class ConstColsEnumerator;
2926 
2927  private:
2928  size_type d_left;
2929  T * d_entry;
2930 
2931  public:
2936 
2937  inline ColsEnumerator(T * entry, size_type rows, size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2938  : implementation::row_count_storage<Rows>(rows), implementation::col_count_storage<Cols>(cols), d_left(cols), d_entry(entry)
2939  {
2940  }
2941 
2947  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2948  {
2950  }
2951 
2958  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2959  {
2960  return d_left > 0;
2961  }
2962 
2968  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2969  {
2970  --d_left;
2971  ++d_entry;
2972  }
2973  };
2974 
2981  {
2982  private:
2983  size_type d_left;
2984  const T * d_entry;
2985 
2986  public:
2991 
2992  inline ConstColsEnumerator(const ColsEnumerator & e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2993  : implementation::row_count_storage<Rows>(e), d_left(e.d_left), d_entry(e.d_entry)
2994  {
2995  }
2996 
2997 #if __cplusplus >= 201103L
2998  inline ConstColsEnumerator(ColsEnumerator && e) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2999  : implementation::row_count_storage<Rows>(e), d_left(e.d_left), d_entry(e.d_entry)
3000  {
3001  }
3002 #endif
3003 
3004  inline ConstColsEnumerator(const T * entry, size_type rows, size_type cols) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3005  : implementation::row_count_storage<Rows>(rows), implementation::col_count_storage<Cols>(cols), d_left(cols), d_entry(entry)
3006  {
3007  }
3008 
3014  inline Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3015  {
3017  }
3018 
3025  inline bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3026  {
3027  return d_left > 0;
3028  }
3029 
3035  inline void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3036  {
3037  --d_left;
3038  ++d_entry;
3039  }
3040  };
3041 
3042  typedef RowsEnumerator DefaultRowsEnumerator;
3043  typedef ColsEnumerator DefaultColsEnumerator;
3044 
3050  inline RowsEnumerator enumerate_rows() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3051  {
3052  return RowsEnumerator(d_data, rows(), cols());
3053  }
3054 
3060  inline ConstRowsEnumerator enumerate_rows() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3061  {
3062  return ConstRowsEnumerator(d_data, rows(), cols());
3063  }
3064 
3070  inline ColsEnumerator enumerate_cols() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3071  {
3072  return ColsEnumerator(d_data, rows(), cols());
3073  }
3074 
3080  inline ConstColsEnumerator enumerate_cols() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3081  {
3082  return ConstColsEnumerator(d_data, rows(), cols());
3083  }
3084  };
3085 
3086 #if __cplusplus >= 201103L
3087  template<typename T, int Rows = Flexible, int Cols = Flexible, typename StorageTraits = storage_traits<T> >
3110  using math_matrix = base_matrix<T, Rows, Cols, StorageTraits, true>;
3111 
3112  template<typename T, int Cols = Flexible, typename StorageTraits = storage_traits<T>, bool MathObject = false>
3131  using base_rowvector = base_matrix<T, 1, Cols, StorageTraits, MathObject>;
3132 
3133  template<typename T, int Rows = Flexible, typename StorageTraits = storage_traits<T>, bool MathObject = false>
3152  using base_colvector = base_matrix<T, Rows, 1, StorageTraits, MathObject>;
3153 
3154  template<typename T, int Cols = Flexible, typename StorageTraits = storage_traits<T> >
3169  using math_rowvector = base_rowvector<T, Cols, StorageTraits, true>;
3170 
3171  template<typename T, int Rows = Flexible, typename StorageTraits = storage_traits<T> >
3186  using math_colvector = base_colvector<T, Rows, StorageTraits, true>;
3187 #else
3188 
3192  template<typename T, int Rows = Flexible, int Cols = Flexible, typename StorageTraits = storage_traits<T> >
3215  class math_matrix : public base_matrix<T, Rows, Cols, StorageTraits, true>
3216  {
3217  public:
3218  enum { has_direct_access = base_matrix<T, Rows, Cols, StorageTraits, true>::has_direct_access };
3219 
3225  {
3226  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << ") [1]");
3227  }
3228 
3234  template<bool MO>
3236  : base_matrix<T, Rows, Cols, StorageTraits, true>(mat)
3237  {
3238  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [2]");
3239  }
3240 
3247  : base_matrix<T, Rows, Cols, StorageTraits, true>(mat)
3248  {
3249  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [3]");
3250  }
3251 
3258  : base_matrix<T, Rows, Cols, StorageTraits, true>(mat)
3259  {
3260  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [3.b]");
3261  }
3262 
3268  template<typename S, int Rs, int Cs, typename ST, bool MO>
3270  : base_matrix<T, Rows, Cols, StorageTraits, true>(mat)
3271  {
3272  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [4]");
3273  }
3274 
3280  template<typename MatrixType>
3281  math_matrix(const MatrixType & mat)
3282  : base_matrix<T, Rows, Cols, StorageTraits, true>(mat)
3283  {
3284  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << getAddress(mat) << ") [5]");
3285  }
3286 
3297  : base_matrix<T, Rows, Cols, StorageTraits, true>(entries)
3298  {
3299  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << entries << ") [6]");
3300  }
3301 
3311  math_matrix(int entries)
3312  : base_matrix<T, Rows, Cols, StorageTraits, true>(entries)
3313  {
3314  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << entries << ") [6b]");
3315  }
3316 
3327  template<typename S, bool def>
3329  : base_matrix<T, Rows, Cols, StorageTraits, true>(entries, i)
3330  {
3331  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << entries << " " << getAddress(i.ref()) << ") [7]");
3332  }
3333 
3342  : base_matrix<T, Rows, Cols, StorageTraits, true>(rows, cols)
3343  {
3344  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << rows << " " << cols << ") [8]");
3345  }
3346 
3355  template<typename S, bool def>
3357  : base_matrix<T, Rows, Cols, StorageTraits, true>(rows, cols, i)
3358  {
3359  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::math_matrix(" << getAddress(*this) << "; " << rows << " " << cols << " " << getAddress(i.ref()) << ") [9]");
3360  }
3361 
3365  ~math_matrix() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3366  {
3367  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::~math_matrix(" << getAddress(*this) << ")");
3368  }
3369 
3375  template<typename MatrixType>
3377  {
3378  PLLL_DEBUG_OUTPUT_MESSAGE("math_matrix::operator = (" << getAddress(*this) << "; " << getAddress(m) << ")");
3380  return *this;
3381  }
3382  };
3383 
3387 
3406  template<typename T, int Cols = Flexible, typename StorageTraits = storage_traits<T>, bool MathObject = false>
3407  class base_rowvector : public base_matrix<T, 1, Cols, StorageTraits, MathObject>
3408  {
3409  public:
3410  enum { has_direct_access = base_matrix<T, 1, Cols, StorageTraits, MathObject>::has_direct_access };
3411 
3417  {
3418  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << ") [1]");
3419  }
3420 
3426  template<bool MO>
3428  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(mat)
3429  {
3430  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [2]");
3431  }
3432 
3439  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(mat)
3440  {
3441  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [3]");
3442  }
3443 
3449  template<typename S, int Rs, int Cs, typename ST, bool MO>
3451  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(mat)
3452  {
3453  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [4]");
3454  }
3455 
3461  template<typename MatrixType>
3462  base_rowvector(const MatrixType & mat)
3463  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(mat)
3464  {
3465  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [5]");
3466  }
3467 
3475  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(entries)
3476  {
3477  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << entries << ") [6]");
3478  }
3479 
3486  base_rowvector(int entries)
3487  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(entries)
3488  {
3489  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << entries << ") [6b]");
3490  }
3491 
3499  template<typename S, bool def>
3501  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(entries, i)
3502  {
3503  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << entries << " " << getAddress(i.ref()) << ") [7]");
3504  }
3505 
3514  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(rows, cols)
3515  {
3516  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << rows << " " << cols << ") [8]");
3517  }
3518 
3527  template<typename S, bool def>
3529  : base_matrix<T, 1, Cols, StorageTraits, MathObject>(rows, cols, i)
3530  {
3531  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::base_rowvector(" << getAddress(*this) << "; " << rows << " " << cols << " " << getAddress(i.ref()) << ") [9]");
3532  }
3533 
3537  ~base_rowvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3538  {
3539  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::~base_rowvector(" << getAddress(*this) << ")");
3540  }
3541 
3547  template<typename MatrixType>
3549  {
3550  PLLL_DEBUG_OUTPUT_MESSAGE("base_rowvector::operator = (" << getAddress(*this) << "; " << getAddress(m) << ")");
3552  return *this;
3553  }
3554  };
3555 
3559 
3578  template<typename T, int Rows = Flexible, typename StorageTraits = storage_traits<T>, bool MathObject = false>
3579  class base_colvector : public base_matrix<T, Rows, 1, StorageTraits, MathObject>
3580  {
3581  public:
3582  enum { has_direct_access = base_matrix<T, Rows, 1, StorageTraits, MathObject>::has_direct_access };
3583 
3589  {
3590  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << ") [1]");
3591  }
3592 
3598  template<bool MO>
3600  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(mat)
3601  {
3602  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [2]");
3603  }
3604 
3611  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(mat)
3612  {
3613  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [3]");
3614  }
3615 
3621  template<typename S, int Rs, int Cs, typename ST, bool MO>
3623  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(mat)
3624  {
3625  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [4]");
3626  }
3627 
3633  template<typename MatrixType>
3634  base_colvector(const MatrixType & mat)
3635  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(mat)
3636  {
3637  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [5]");
3638  }
3639 
3647  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(entries)
3648  {
3649  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << entries << ") [6]");
3650  }
3651 
3658  base_colvector(int entries)
3659  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(entries)
3660  {
3661  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << entries << ") [6b]");
3662  }
3663 
3671  template<typename S, bool def>
3673  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(entries, i)
3674  {
3675  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << entries << " " << getAddress(i.ref()) << ") [7]");
3676  }
3677 
3686  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(rows, cols)
3687  {
3688  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << rows << " " << cols << ") [8]");
3689  }
3690 
3699  template<typename S, bool def>
3701  : base_matrix<T, Rows, 1, StorageTraits, MathObject>(rows, cols, i)
3702  {
3703  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::base_colvector(" << getAddress(*this) << "; " << rows << " " << cols << " " << getAddress(i.ref()) << ") [9]");
3704  }
3705 
3709  ~base_colvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3710  {
3711  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::~base_colvector(" << getAddress(*this) << ")");
3712  }
3713 
3719  template<typename MatrixType>
3721  {
3722  PLLL_DEBUG_OUTPUT_MESSAGE("base_colvector::operator = (" << getAddress(*this) << "; " << getAddress(m) << ")");
3724  return *this;
3725  }
3726  };
3727 
3731 
3746  template<typename T, int Cols = Flexible, typename StorageTraits = storage_traits<T> >
3747  class math_rowvector : public base_rowvector<T, Cols, StorageTraits, true>
3748  {
3749  public:
3750  enum { has_direct_access = base_rowvector<T, Cols, StorageTraits, true>::has_direct_access };
3751 
3757  {
3758  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << ") [1]");
3759  }
3760 
3766  template<bool MO>
3768  : base_rowvector<T, Cols, StorageTraits, true>(mat)
3769  {
3770  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [2]");
3771  }
3772 
3779  : base_rowvector<T, Cols, StorageTraits, true>(mat)
3780  {
3781  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [3]");
3782  }
3783 
3789  template<typename S, int Rs, int Cs, typename ST, bool MO>
3791  : base_rowvector<T, Cols, StorageTraits, true>(mat)
3792  {
3793  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [4]");
3794  }
3795 
3801  template<typename MatrixType>
3802  math_rowvector(const MatrixType & mat)
3803  : base_rowvector<T, Cols, StorageTraits, true>(mat)
3804  {
3805  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [5]");
3806  }
3807 
3815  : base_rowvector<T, Cols, StorageTraits, true>(entries)
3816  {
3817  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << entries << ") [6]");
3818  }
3819 
3826  math_rowvector(int entries)
3827  : base_rowvector<T, Cols, StorageTraits, true>(entries)
3828  {
3829  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << entries << ") [6b]");
3830  }
3831 
3839  template<typename S, bool def>
3841  : base_rowvector<T, Cols, StorageTraits, true>(entries, i)
3842  {
3843  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << entries << " " << getAddress(i.ref()) << ") [7]");
3844  }
3845 
3854  : base_rowvector<T, Cols, StorageTraits, true>(rows, cols)
3855  {
3856  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << rows << " " << cols << ") [8]");
3857  }
3858 
3867  template<typename S, bool def>
3869  : base_rowvector<T, Cols, StorageTraits, true>(rows, cols, i)
3870  {
3871  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::math_rowvector(" << getAddress(*this) << "; " << rows << " " << cols << " " << getAddress(i.ref()) << ") [9]");
3872  }
3873 
3877  ~math_rowvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3878  {
3879  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::~math_rowvector(" << getAddress(*this) << ")");
3880  }
3881 
3887  template<typename MatrixType>
3889  {
3890  PLLL_DEBUG_OUTPUT_MESSAGE("math_rowvector::operator = (" << getAddress(*this) << "; " << getAddress(m) << ")");
3892  return *this;
3893  }
3894  };
3895 
3899 
3914  template<typename T, int Rows = Flexible, typename StorageTraits = storage_traits<T> >
3915  class math_colvector : public base_colvector<T, Rows, StorageTraits, true>
3916  {
3917  public:
3918  enum { has_direct_access = base_colvector<T, Rows, StorageTraits, true>::has_direct_access };
3919 
3925  {
3926  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << ") [1]");
3927  }
3928 
3934  template<bool MO>
3936  : base_colvector<T, Rows, StorageTraits, true>(mat)
3937  {
3938  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [2]");
3939  }
3940 
3947  : base_colvector<T, Rows, StorageTraits, true>(mat)
3948  {
3949  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [3]");
3950  }
3951 
3957  template<typename S, int Rs, int Cs, typename ST, bool MO>
3959  : base_colvector<T, Rows, StorageTraits, true>(mat)
3960  {
3961  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [4]");
3962  }
3963 
3969  template<typename MatrixType>
3970  math_colvector(const MatrixType & mat)
3971  : base_colvector<T, Rows, StorageTraits, true>(mat)
3972  {
3973  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << getAddress(mat) << ") [5]");
3974  }
3975 
3983  : base_colvector<T, Rows, StorageTraits, true>(entries)
3984  {
3985  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << entries << ") [6]");
3986  }
3987 
3994  math_colvector(int entries)
3995  : base_colvector<T, Rows, StorageTraits, true>(entries)
3996  {
3997  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << entries << ") [6b]");
3998  }
3999 
4007  template<typename S, bool def>
4009  : base_colvector<T, Rows, StorageTraits, true>(entries, i)
4010  {
4011  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << entries << " " << getAddress(i.ref()) << ") [7]");
4012  }
4013 
4022  : base_colvector<T, Rows, StorageTraits, true>(rows, cols)
4023  {
4024  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << rows << " " << cols << ") [8]");
4025  }
4026 
4035  template<typename S, bool def>
4037  : base_colvector<T, Rows, StorageTraits, true>(rows, cols, i)
4038  {
4039  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::math_colvector(" << getAddress(*this) << "; " << rows << " " << cols << " " << getAddress(i.ref()) << ") [9]");
4040  }
4041 
4045  ~math_colvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
4046  {
4047  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::~math_colvector(" << getAddress(*this) << ")");
4048  }
4049 
4055  template<typename MatrixType>
4057  {
4058  PLLL_DEBUG_OUTPUT_MESSAGE("math_colvector::operator = (" << getAddress(*this) << "; " << getAddress(m) << ")");
4060  return *this;
4061  }
4062  };
4063 #endif
4064 
4068 
4072  namespace implementation
4073  {
4074  template<typename MatrixType, int Rows, int Cols, bool forceGeneric>
4076  {
4077  public:
4078  static void print(std::ostream & s, const MatrixType & mat)
4079  {
4080  PLLL_DEBUG_OUTPUT_MESSAGE("MatrixPrinter::operator () (" << getAddress(s) << " " << getAddress(mat) << ") [0]");
4081  s << "mat<" << mat.rows() << "," << mat.cols() << ">[";
4082  bool rfirst = true;
4083  for (typename MatrixType::ConstRowsEnumerator re = mat.enumerate_rows(); re.has_current(); re.next())
4084  {
4085  if (rfirst)
4086  rfirst = false;
4087  else
4088  s << ", ";
4089  s << "[";
4090  bool first = true;
4091  for (typename MatrixType::ConstRowsEnumerator::Type e = re.current(); e.has_current(); e.next())
4092  {
4093  if (first)
4094  first = false;
4095  else
4096  s << ", ";
4097  s << e.current();
4098  }
4099  s << "]";
4100  }
4101  s << "]";
4102  }
4103  };
4104 
4105  template<typename MatrixType, int Rows>
4106  class MatrixPrinter<MatrixType, Rows, 1, false>
4107  {
4108  public:
4109  static void print(std::ostream & s, const MatrixType & mat)
4110  {
4111  PLLL_DEBUG_OUTPUT_MESSAGE("MatrixPrinter::operator () (" << getAddress(s) << " " << getAddress(mat) << ") [1]");
4112  s << "vec<" << mat.rows() << ">[";
4113  bool first = true;
4114  for (typename MatrixType::ConstEnumerator e = mat.enumerate(); e.has_current(); e.next())
4115  {
4116  if (first)
4117  first = false;
4118  else
4119  s << ", ";
4120  s << e.current();
4121  }
4122  s << "]";
4123  }
4124  };
4125  }
4126 
4137  template<typename MatrixType, bool forceGeneric>
4138  inline void print_matrix(std::ostream & s, const MatrixType & mat)
4139  {
4140  PLLL_DEBUG_OUTPUT_MESSAGE("print_matrix(" << getAddress(s) << " " << getAddress(mat) << ")");
4143  }
4144 
4156  template<typename MatrixType>
4157  inline void print_matrix(std::ostream & s, const MatrixType & mat, bool forceGeneric = false)
4158  {
4159  PLLL_DEBUG_OUTPUT_MESSAGE("print_matrix(" << getAddress(s) << " " << getAddress(mat) << " " << forceGeneric << ")");
4160  if (forceGeneric)
4161  print_matrix<MatrixType, true>(s, mat);
4162  else
4163  print_matrix<MatrixType, false>(s, mat);
4164  }
4165 
4174  template<typename T, int Rows, int Cols, typename ST, bool MO>
4175  inline std::ostream & operator << (std::ostream & s, const base_matrix<T, Rows, Cols, ST, MO> & mat)
4176  {
4177  PLLL_DEBUG_OUTPUT_MESSAGE("operator << (" << getAddress(s) << " " << getAddress(mat) << ") [1]");
4178  print_matrix(s, mat, false);
4179  return s;
4180  }
4181 
4190  template<template<typename DataType> class Operator, typename Data>
4191  inline std::ostream & operator << (std::ostream & s, const implementation::expressions::expr<Operator, Data> & mat)
4192  {
4193  PLLL_DEBUG_OUTPUT_MESSAGE("operator << (" << getAddress(s) << " " << getAddress(mat) << ") [4]");
4194  print_matrix(s, mat, false);
4195  return s;
4196  }
4197 
4201 
4202  namespace implementation
4203  {
4204  template<typename MatrixType, int Rows, int Cols>
4206  {
4207  public:
4208  template<typename S>
4209  static inline bool scan(std::istream & s, MatrixType & mat, const S & DefaultObject)
4210  {
4211  PLLL_DEBUG_OUTPUT_MESSAGE("MatrixScanner::operator () (" << getAddress(s) << " " << getAddress(mat) << ") [0]");
4212  if (!s) return false;
4213  // Skip whitespace
4214  char c = s.get();
4215  while (std::isspace(c) && s)
4216  c = s.get();
4217  if (!s) return false;
4218  // Parse matrix/vector
4219  bool is_vector = false;
4220  int mrows = -1, mcols = -1;
4221  if (c == 'm')
4222  {
4223  // Scan "mat<"
4224  c = s.get();
4225  if (c != 'a')
4226  return false;
4227  c = s.get();
4228  if (c != 't')
4229  return false;
4230  c = s.get();
4231  if (c != '<')
4232  return false;
4233  c = s.get();
4234  while (std::isspace(c) && s)
4235  c = s.get();
4236  if (!isdigit(c))
4237  return false;
4238  // Read number of rows
4239  s.unget();
4240  s >> mrows;
4241  if (!s || (mrows < 0))
4242  return false;
4243  if ((Rows >= 0) && (mrows != Rows))
4244  return false;
4245  if (!implementation::MatrixInfo<MatrixType>::can_resize_rows && (mat.rows() != static_cast<size_type>(mrows)))
4246  return false;
4247  // Skip "," with surrounding whitespaces
4248  c = s.get();
4249  while (std::isspace(c) && s)
4250  c = s.get();
4251  if (c != ',')
4252  return false;
4253  c = s.get();
4254  while (std::isspace(c) && s)
4255  c = s.get();
4256  // Read number of columns
4257  s.unget();
4258  s >> mcols;
4259  if (!s || (mcols < 0))
4260  return false;
4261  if ((Cols >= 0) && (mcols != Cols))
4262  return false;
4263  if (!implementation::MatrixInfo<MatrixType>::can_resize_cols && (mat.cols() != static_cast<size_type>(mcols)))
4264  return false;
4265  // Read ">"
4266  c = s.get();
4267  while (std::isspace(c) && s)
4268  c = s.get();
4269  if (c != '>')
4270  return false;
4271  c = s.get();
4272  }
4273  else if (c == 'v')
4274  {
4275  is_vector = true;
4276  // Is the given matrix object possibly a vector?
4277  mcols = 1;
4278  if ((Cols >= 0) && (mcols != Cols))
4279  return false;
4280  if (!implementation::MatrixInfo<MatrixType>::can_resize_cols && (mat.cols() != static_cast<size_type>(mcols)))
4281  return false;
4282  // Scan "vec<"
4283  c = s.get();
4284  if (c != 'e')
4285  return false;
4286  c = s.get();
4287  if (c != 'c')
4288  return false;
4289  c = s.get();
4290  if (c != '<')
4291  return false;
4292  c = s.get();
4293  while (std::isspace(c) && s)
4294  c = s.get();
4295  // Scan number of elements
4296  s.unget();
4297  s >> mrows;
4298  if (!s || (mrows < 0))
4299  return false;
4300  if ((Rows >= 0) && (mrows != Rows))
4301  return false;
4302  if (!implementation::MatrixInfo<MatrixType>::can_resize_rows && (mat.rows() != static_cast<size_type>(mrows)))
4303  return false;
4304  // Read ">"
4305  c = s.get();
4306  while (std::isspace(c) && s)
4307  c = s.get();
4308  if (c != '>')
4309  return false;
4310  c = s.get();
4311  }
4312  // We now scan (size-agnosticly) the matrix from the given input. We later compare
4313  // the findings with the information extracted above.
4314  size_type rows = 0, cols = 0;
4315  // Now proceed with '['
4316  while (std::isspace(c) && s)
4317  c = s.get();
4318  if ((c != '[') || !s)
4319  return false;
4320  c = s.get(); // remove "["
4321  std::list<typename implementation::MatrixInfo<MatrixType>::Type> vals;
4322  // Scan matrix elements
4323  while (s)
4324  {
4325  // Find something non-trivial (or stop when finding ']')
4326  while (std::isspace(c) && s)
4327  c = s.get();
4328  if (!s)
4329  return false;
4330  if (c == ']')
4331  // last line?
4332  break;
4333  // Skip "," if avaiable
4334  if (c == ',')
4335  c = s.get();
4336  while (std::isspace(c) && s)
4337  c = s.get();
4338  // Remove '[' (if not a vector!)
4339  if (!is_vector)
4340  {
4341  if (c != '[')
4342  return false;
4343  c = s.get();
4344  }
4345  // remove numbers
4346  unsigned i = 0;
4347  ++rows;
4348  while (s)
4349  {
4350  // Skip whitespace
4351  while (std::isspace(c) && s)
4352  c = s.get();
4353  if (!s)
4354  return false;
4355  // Are we done? (if not a vector!)
4356  if (!is_vector)
4357  if ((c == ']') && (i == cols))
4358  {
4359  c = s.get();
4360  break;
4361  }
4362  // Read value
4363  s.unget();
4364  vals.push_back(DefaultObject);
4365  s >> vals.back();
4366  if (!s)
4367  return false;
4368  c = s.get();
4369  // Increase position/size
4370  ++i;
4371  if (rows == 1)
4372  ++cols;
4373  // Continue with next entry (if not a vector!)
4374  if (is_vector)
4375  break;
4376  else
4377  {
4378  // Skip whitespace
4379  while (std::isspace(c) && s)
4380  c = s.get();
4381  // Scan "," if available
4382  if (c == ',')
4383  c = s.get();
4384  // Skip more whitespace
4385  while (std::isspace(c) && s)
4386  c = s.get();
4387  // Error?
4388  if (!s)
4389  return false;
4390  }
4391  }
4392  // Error?
4393  if (!s)
4394  return false;
4395  }
4396  // Error?
4397  if (!s)
4398  return false;
4399  // Compare whether scanned data is consistent with known data
4400  if (mrows >= 0)
4401  if ((static_cast<size_type>(mrows) != rows) || (static_cast<size_type>(mcols) != cols))
4402  return false;
4403  if (!implementation::MatrixInfo<MatrixType>::can_resize_rows && (mat.rows() != rows))
4404  return false;
4405  if (!implementation::MatrixInfo<MatrixType>::can_resize_cols && (mat.cols() != cols))
4406  return false;
4407  // Assign matrix
4408  typename std::list<typename implementation::MatrixInfo<MatrixType>::Type>::iterator it = vals.begin();
4409  if ((mat.rows() != rows) || (mat.cols() != cols))
4410  mat.resize(rows, cols, Initialize(DefaultObject));
4411  for (typename MatrixType::Enumerator e = mat.enumerate(); e.has_current(); e.next(), ++it)
4412 #if __cplusplus >= 201103L
4413  e.current() = std::move(*it);
4414 #else
4415  e.current() = *it;
4416 #endif
4417  return true;
4418  }
4419 
4420  static inline bool scan(std::istream & s, MatrixType & mat)
4421  {
4422  typename implementation::MatrixInfo<MatrixType>::Type def;
4423  return scan(s, mat, def);
4424  }
4425  };
4426  }
4427 
4438  template<typename MatrixType>
4439  inline bool scan_matrix(std::istream & s, MatrixType & mat)
4440  {
4441  PLLL_DEBUG_OUTPUT_MESSAGE("scan_matrix(" << getAddress(s) << " " << getAddress(mat) << ")");
4445  }
4446 
4457  template<typename MatrixType>
4458  inline bool scan_matrix(std::istream & s, const MatrixType & mat)
4459  {
4460  PLLL_DEBUG_OUTPUT_MESSAGE("scan_matrix(" << getAddress(s) << " " << getAddress(mat) << ")");
4464  }
4465 
4478  template<typename MatrixType, typename T>
4479  inline bool scan_matrix(std::istream & s, MatrixType & mat, const T & default_object)
4480  {
4481  PLLL_DEBUG_OUTPUT_MESSAGE("scan_matrix(" << getAddress(s) << " " << getAddress(mat) << " " << getAddress(default_object) << ")");
4485  }
4486 
4499  template<typename MatrixType, typename T>
4500  inline bool scan_matrix(std::istream & s, const MatrixType & mat, const T & default_object)
4501  {
4502  PLLL_DEBUG_OUTPUT_MESSAGE("scan_matrix(" << getAddress(s) << " " << getAddress(mat) << " " << getAddress(default_object) << ")");
4506  }
4507 
4518  template<typename T, int Rows, int Cols, typename ST, bool MO>
4519  inline std::istream & operator >> (std::istream & s, base_matrix<T, Rows, Cols, ST, MO> & mat)
4520  {
4521  PLLL_DEBUG_OUTPUT_MESSAGE("operator >> (" << getAddress(s) << " " << getAddress(mat) << ") [1]");
4522  if (!scan_matrix(s, mat))
4523  s.setstate(std::ios_base::failbit);
4524  return s;
4525  }
4526 
4537  template<template<typename DataType> class Op, typename Data>
4538  inline std::istream & operator >> (std::istream & s, const implementation::expressions::expr<Op, Data> & mat)
4539  {
4540  PLLL_DEBUG_OUTPUT_MESSAGE("operator >> (" << getAddress(s) << " " << getAddress(mat) << ") [2]");
4542  if (!scan_matrix(s, mat))
4543  s.setstate(std::ios_base::failbit);
4544  return s;
4545  }
4547  }
4548 }
4549 
4550 #include "matrix-ops.hpp"
4551 #include "matrix-ops2.hpp"
4552 
4553 #endif
base_rowvector(size_type entries)
Creates a row vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3474
math_rowvector(int entries)
Creates a row vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3826
~math_matrix() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory allocated for the matrix.
Definition: matrix.hpp:3365
base_colvector()
Creates a new column vector. The dimensions are set to zero if no compile-time dimensions were specif...
Definition: matrix.hpp:3588
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current element exists and can be queried by the current(), get_current() and get_c...
Definition: matrix.hpp:2612
void assign(const implementation::expressions::expr< DestOp, DestData > &destination, const implementation::expressions::expr< SourceOp, SourceData > &source, helper::BoolToType< move > ittm)
Assigns the content of matrix source to matrix destination. Allows to force move. ...
math_colvector(size_type rows, size_type cols, const implementation::Initialize_Impl< S, def > &i)
Creates a column vector with cols entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:4036
math_colvector(const MatrixType &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3970
const T & Type
The final type of the coefficients.
Definition: matrix.hpp:2462
ColEnumerator enumerate_col(size_type col) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all entries of the given column.
Definition: matrix.hpp:2773
T & make_type_lvalue() PLLL_INTERNAL_NOTHROW_POSTFIX_ENFORCE
This is a pseudo-template which should only be used in expressions which are never evaluated...
Memory management for matrix and vector operations.
Allows to retrieve a coefficient of the matrix in two steps.
Definition: matrix.hpp:1544
ConstRowEnumerator enumerate_row(size_type row) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all entries of the given row.
Definition: matrix.hpp:2761
base_matrix(size_type entries, const implementation::Initialize_Impl< S, def > &i)
Creates a vector with entries entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:1356
base_rowvector< T, Cols, StorageTraits, MathObject > & operator=(const MatrixType &m)
Copies the contents of the row vector m into *this.
Definition: matrix.hpp:3548
math_matrix(const math_matrix< T, Rows, Cols, StorageTraits > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:3246
RowEnumerator enumerate_row(size_type row) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all entries of the given row.
Definition: matrix.hpp:2749
math_matrix(size_type entries, const implementation::Initialize_Impl< S, def > &i)
Creates a vector with entries entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3328
An enumerator for a matrix' column.
Definition: matrix.hpp:2634
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the current matrix entry.
Definition: matrix.hpp:2672
StorageTraits::constref_type data(size_type i) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a (raw) reference to the i-th entry.
Definition: matrix.hpp:1699
const T & Type
The final type of the coefficients.
Definition: matrix.hpp:2644
Enumerates over all rows. For every row, a RowsEnumerator::RowEnumerator object is returned which all...
Definition: matrix.hpp:2797
math_rowvector()
Creates a new row vector. The dimensions are set to zero if no compile-time dimensions were specified...
Definition: matrix.hpp:3756
void resize(size_type new_rows, size_type new_cols, const implementation::Initialize_Impl< S, def > &init)
Resizes the matrix to new_rows times new_cols entries. If the new matrix has entries which cannot be ...
Definition: matrix.hpp:2091
std::istream & operator>>(std::istream &s, base_matrix< T, Rows, Cols, ST, MO > &mat)
Reads a matrix from the input stream s and stores it in mat.
Definition: matrix.hpp:4519
size_type rows() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the number of rows of the matrix.
Definition: matrix.hpp:1724
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current row exists and can be queried by the current() method.
Definition: matrix.hpp:2899
void get_current(Result &result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result=*d_entry))
Creates a copy of the current matrix entry in result.
Definition: matrix.hpp:2501
void resize(size_type new_size)
Resizes the vector to new_size entries. If new_size exceeds the current size, new elements are defaul...
Definition: matrix.hpp:1957
base_matrix(const base_matrix< T, Rs, Cs, StorageTraits, MO > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:1176
size_type size() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the number of entries of the matrix. This equals rows() * cols().
Definition: matrix.hpp:1746
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:2438
Enumerates over all columns. For every column, a ColsEnumerator::ColEnumerator object is returned whi...
Definition: matrix.hpp:2923
~base_matrix() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory allocated for the matrix.
Definition: matrix.hpp:1404
Operator instantiations for matrices and vectors.
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the current matrix entry.
Definition: matrix.hpp:2490
base_colvector(const base_matrix< T, Rows, 1, StorageTraits, MO > &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3599
~math_colvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory allocated for the column vector.
Definition: matrix.hpp:4045
base_colvector(size_type rows, size_type cols)
Creates a column vector with cols entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3685
math_rowvector(size_type rows, size_type cols)
Creates a row vector with cols entries. Its coefficients are default-constructed. ...
Definition: matrix.hpp:3853
void swap(base_matrix< T, R, C, ST, MO > &A, base_matrix< T, R, C, ST, MO > &B) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Swaps matrices A and B efficiently.
Definition: matrix-ops2.hpp:49
#define PLLL_INTERNAL_STATIC_CHECK(condition, IdentifierWhichIsAMessage)
Definition: helper.hpp:83
implementation::expressions::expr< implementation::expressions::sub< SRows, SCols >::template operation_generic, implementation::expressions::ConstMatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > block(size_type r_ofs, size_type c_ofs) const
Returns a submatrix of SRows rows and SCols columns starting at (r_ofs, c_ofs).
Definition: matrix.hpp:1788
math_matrix(const base_matrix< T, Rows, Cols, StorageTraits, MO > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:3235
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:2842
Operator definitions for matrices and vectors.
void step2(ResultType &result) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Modifies the result returned by step1() to contain the full coefficient.
Definition: matrix.hpp:1576
base_rowvector(const base_matrix< T, 1, Cols, StorageTraits, MO > &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3427
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current column exists and can be queried by the current() method.
Definition: matrix.hpp:3025
math_colvector(const base_matrix< T, Rows, 1, StorageTraits, MO > &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3935
base_matrix(int entries)
Creates a vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:1336
void get_current(Result &result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result=*d_entry))
Creates a copy of the current matrix entry in result.
Definition: matrix.hpp:2591
math_rowvector(size_type entries, const implementation::Initialize_Impl< S, def > &i)
Creates a row vector with entries entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3840
base_rowvector(size_type rows, size_type cols, const implementation::Initialize_Impl< S, def > &i)
Creates a row vector with cols entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3528
implementation::expressions::expr< implementation::expressions::sub_1d< Rows >::template operation_col, implementation::expressions::MatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > col(size_type col_index)
Returns the col_index-th column of this matrix.
Definition: matrix.hpp:1890
base_rowvector()
Creates a new row vector. The dimensions are set to zero if no compile-time dimensions were specified...
Definition: matrix.hpp:3416
math_colvector(int entries)
Creates a column vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3994
Represents a matrix with coefficients in T.
Definition: matrix.hpp:165
math_rowvector< T, Cols, StorageTraits > & operator=(const MatrixType &m)
Copies the contents of the row vector m into *this.
Definition: matrix.hpp:3888
base_matrix(size_type rows, size_type cols, const implementation::Initialize_Impl< S, def > &i)
Creates a matrix with rows times cols entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:1391
Represents a row vector with coefficients in T.
Definition: matrix.hpp:254
implementation::Initialize_Impl< S, false > Initialize(const S &ref) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates an initializer object to initialize with the given reference.
Definition: matrix.hpp:123
bool test_involvement(const MatrixType &A) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
For the underlying matrices U of the current expression, calls A.involves_this_matrix(U). Returns true if any of these returns true.
Definition: matrix.hpp:2353
math_rowvector(const math_rowvector< T, Cols, StorageTraits > &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3778
math_colvector(size_type rows, size_type cols)
Creates a column vector with cols entries. Its coefficients are default-constructed.
Definition: matrix.hpp:4021
GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a GetCoeffSteps_Type object for the current entry.
Definition: matrix.hpp:2511
math_matrix(const base_matrix< T, Rows, Cols, StorageTraits, false > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:3257
base_colvector(size_type rows, size_type cols, const implementation::Initialize_Impl< S, def > &i)
Creates a column vector with cols entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3700
implementation::expressions::expr< implementation::expressions::sub_1d< Rows >::template operation_col, implementation::expressions::ConstMatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > col(size_type col_index) const
Returns the col_index-th column of this matrix.
Definition: matrix.hpp:1908
math_matrix(size_type rows, size_type cols, const implementation::Initialize_Impl< S, def > &i)
Creates a matrix with rows times cols entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3356
math_matrix(int entries)
Creates a vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3311
GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a GetCoeffSteps_Type object for the current entry.
Definition: matrix.hpp:2417
math_matrix()
Creates a new matrix. The dimensions are set to zero if no compile-time dimensions were specified...
Definition: matrix.hpp:3224
base_colvector(const base_matrix< S, Rs, Cs, ST, MO > &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3622
base_matrix< T, Rows, Cols, StorageTraits, MathObject > & operator=(const base_matrix< T, Rows, Cols, StorageTraits, MathObject > &m)
Copies the contents of the matrix m into *this.
Definition: matrix.hpp:1416
RowsEnumerator enumerate_rows() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all rows. For each row, a row enumerator is given.
Definition: matrix.hpp:3050
void get_current(Result &result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result=*d_entry))
Creates a copy of the current matrix entry in result.
Definition: matrix.hpp:2407
RowEnumerator Type
The row enumerator type.
Definition: matrix.hpp:2809
size_type cols() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the number of columns of the matrix.
Definition: matrix.hpp:1735
implementation::expressions::expr< implementation::expressions::sub< Flexible, Flexible >::template operation_generic, implementation::expressions::MatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > block(size_type r_ofs, size_type c_ofs, size_type rows, size_type cols)
Returns a submatrix of rows rows and cols columns starting at (r_ofs, c_ofs).
Definition: matrix.hpp:1812
void get_coeff(ResultType &result, size_type i, size_type j) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result=d_data[i *implementation::col_count_storage< Cols >::cols()+j]))
Retrieves the coefficient (i, j) and stores its value into result.
Definition: matrix.hpp:1518
void setZero(Integer &)
Sets the given integer to zero.
GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a GetCoeffSteps_Type object for the current entry.
Definition: matrix.hpp:2601
math_colvector(size_type entries)
Creates a column vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3982
ConstRowsEnumerator enumerate_rows() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all rows. For each row, a row enumerator is given.
Definition: matrix.hpp:3060
void print_matrix(std::ostream &s, const MatrixType &mat)
Prints the given matrix mat to the output stream s.
Definition: matrix.hpp:4138
ConstColsEnumerator enumerate_cols() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all columns. For each column, a column enumerator is given.
Definition: matrix.hpp:3080
StorageTraits::constpointer_type data_pointer_type
Return type for the method data() const.
Definition: matrix.hpp:1140
ColEnumerator Type
The row enumerator type.
Definition: matrix.hpp:2935
Enumerates over all columns. For every column, a ConstColsEnumerator::ColEnumerator object is returne...
Definition: matrix.hpp:2980
base_colvector< T, Rows, StorageTraits, MathObject > & operator=(const MatrixType &m)
Copies the contents of the column vector m into *this.
Definition: matrix.hpp:3720
math_rowvector(size_type entries)
Creates a row vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3814
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current column exists and can be queried by the current() method.
Definition: matrix.hpp:2958
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:2968
math_rowvector(const base_matrix< T, 1, Cols, StorageTraits, MO > &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3767
T & Type
The final type of the coefficients.
Definition: matrix.hpp:2380
~base_colvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory allocated for the column vector.
Definition: matrix.hpp:3709
math_matrix< T, Rows, Cols, StorageTraits > & operator=(const MatrixType &m)
Copies the contents of the matrix m into *this.
Definition: matrix.hpp:3376
base_colvector(const MatrixType &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3634
ConstColEnumerator enumerate_col(size_type col) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all entries of the given column.
Definition: matrix.hpp:2785
StorageTraits::constref_type operator[](size_type i) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Retrieves and returns the i-th entry of the vector.
Definition: matrix.hpp:1642
StorageTraits::pointer_type data() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a pointer to the raw data of the matrix.
Definition: matrix.hpp:1686
bool involves_this_matrix(const base_matrix< T, Rows, Cols, StorageTraits, MathObject > &A) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests whether this matrix (or expression) involves A.
Definition: matrix.hpp:2323
base_matrix< T, Rows, Cols, StorageTraits, MathObject >::GetCoeffSteps_Type GetCoeffSteps_Type
The intermediate type of the coefficients, which is returned by current().
Definition: matrix.hpp:2466
implementation::expressions::expr< implementation::expressions::transpose, implementation::expressions::MatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > transpose() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the transpose of this matrix.
Definition: matrix.hpp:1925
math_rowvector(size_type rows, size_type cols, const implementation::Initialize_Impl< S, def > &i)
Creates a row vector with cols entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3868
bool involves_this_matrix(const MatrixType &A) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests whether this matrix (or expression) involves A.
Definition: matrix.hpp:2338
void resize(size_type new_size, const implementation::Initialize_Impl< S, def > &init)
Resizes the vector to new_size entries. If new_size exceeds the current size, new elements are copy-c...
Definition: matrix.hpp:1998
~base_rowvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory allocated for the row vector.
Definition: matrix.hpp:3537
base_matrix< T, Rows, Cols, StorageTraits, MathObject >::GetCoeffSteps_Type GetCoeffSteps_Type
The intermediate type of the coefficients, which is returned by current().
Definition: matrix.hpp:2648
base_matrix(const base_matrix< S, Rs, Cs, ST, MO > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:1232
base_rowvector(const base_rowvector< T, Cols, StorageTraits > &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3438
StorageTraits::constref_type data_ref_type
Return type for the method data(size_type) const.
Definition: matrix.hpp:1144
math_rowvector(const MatrixType &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3802
implementation::expressions::expr< implementation::expressions::sub< Flexible, Flexible >::template operation_generic, implementation::expressions::ConstMatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > block(size_type r_ofs, size_type c_ofs, size_type rows, size_type cols) const
Returns a submatrix of rows rows and cols columns starting at (r_ofs, c_ofs).
Definition: matrix.hpp:1836
Enumerates over all rows. For every row, a ConstRowsEnumerator::RowEnumerator object is returned whic...
Definition: matrix.hpp:2854
ConstColEnumerator Type
The row enumerator type.
Definition: matrix.hpp:2990
Conversion from compile-time known bools to types.
Definition: helper.hpp:220
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the current matrix entry.
Definition: matrix.hpp:2396
StorageTraits::constref_type operator()(size_type i, size_type j) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Retrieves and returns the coefficient (i, j).
Definition: matrix.hpp:1608
base_colvector(size_type entries)
Creates a column vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3646
void transpose(const implementation::expressions::expr< DestOp, DestData > &destination, const implementation::expressions::expr< SourceOp, SourceData > &source, helper::BoolToType< move > ittm)
Transposes the content of matrix source and stores the result in the matrix destination. Allows to force move.
base_matrix< T, Rows, Cols, StorageTraits, MathObject >::GetCoeffSteps_Type GetCoeffSteps_Type
The intermediate type of the coefficients, which is returned by current().
Definition: matrix.hpp:2384
base_matrix(size_type rows, size_type cols)
Creates a matrix with rows times cols entries. Its coefficients are default-constructed.
Definition: matrix.hpp:1372
bool get_coeff_alwayszero() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Queries whether all coefficients are definitely zero.
Definition: matrix.hpp:1534
math_colvector(const base_matrix< S, Rs, Cs, ST, MO > &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3958
Represents a math row vector with coefficients in T.
Definition: matrix.hpp:342
void swap(plll::arithmetic::Integer &, plll::arithmetic::Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Swaps two plll::arithmetic::Integer objects.
base_rowvector(const MatrixType &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3462
An enumerator for a matrix' column.
Definition: matrix.hpp:2552
math_matrix(size_type entries)
Creates a vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3296
math_colvector< T, Rows, StorageTraits > & operator=(const MatrixType &m)
Copies the contents of the column vector m into *this.
Definition: matrix.hpp:4056
base_rowvector(size_type rows, size_type cols)
Creates a row vector with cols entries. Its coefficients are default-constructed. ...
Definition: matrix.hpp:3513
GetCoeffSteps_Type get_current_steps() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a GetCoeffSteps_Type object for the current entry.
Definition: matrix.hpp:2693
void move_resize(const MatrixType &mat)
Resizes the matrix to fit the format of mat and moves the contents of mat to the matrix.
Definition: matrix.hpp:2259
void assign_resize(const MatrixType &mat)
Resizes the matrix to fit the format of mat and assigns the contents of mat to the matrix...
Definition: matrix.hpp:2146
unsigned int size_type
Definition: matrix.hpp:141
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current element exists and can be queried by the current(), get_current() and get_c...
Definition: matrix.hpp:2704
bool scan_matrix(std::istream &s, MatrixType &mat)
Reads a matrix from the input stream s and stores it in mat.
Definition: matrix.hpp:4439
T & Type
The final type of the coefficients.
Definition: matrix.hpp:2564
base_colvector(size_type entries, const implementation::Initialize_Impl< S, def > &i)
Creates a column vector with entries entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3672
base_matrix(const implementation::expressions::expr< Op, Data > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:1270
base_rowvector(const base_matrix< S, Rs, Cs, ST, MO > &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3450
StorageTraits::constref_type Step1_Type
The return type for step1().
Definition: matrix.hpp:1558
Represents a math column vector with coefficients in T.
Definition: matrix.hpp:386
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:2532
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a current row's enumerator.
Definition: matrix.hpp:2888
Helper templates.
base_matrix< T, Rows, Cols, StorageTraits, MathObject >::GetCoeffSteps_Type GetCoeffSteps_Type
The intermediate type of the coefficients, which is returned by current().
Definition: matrix.hpp:2568
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:2622
math_colvector(const math_colvector< T, Rows, StorageTraits > &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3946
StorageTraits::ref_type data(size_type i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a (raw) reference to the i-th entry.
Definition: matrix.hpp:1712
base_colvector(const base_colvector< T, Rows, StorageTraits > &mat)
Creates a copy of the column vector mat.
Definition: matrix.hpp:3610
base_rowvector(int entries)
Creates a row vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3486
implementation::expressions::expr< implementation::expressions::sub< SRows, SCols >::template operation_generic, implementation::expressions::MatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > block(size_type r_ofs, size_type c_ofs)
Returns a submatrix of SRows rows and SCols columns starting at (r_ofs, c_ofs).
Definition: matrix.hpp:1764
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the current matrix entry.
Definition: matrix.hpp:2580
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a current row's enumerator.
Definition: matrix.hpp:2821
implementation::expressions::expr< implementation::expressions::sub_1d< Cols >::template operation_row, implementation::expressions::MatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > row(size_type row_index)
Returns the row_index-th row of this matrix.
Definition: matrix.hpp:1854
ColsEnumerator enumerate_cols() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all columns. For each column, a column enumerator is given.
Definition: matrix.hpp:3070
math_matrix(const MatrixType &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:3281
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:2909
math_matrix(const base_matrix< S, Rs, Cs, ST, MO > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:3269
math_colvector(size_type entries, const implementation::Initialize_Impl< S, def > &i)
Creates a column vector with entries entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:4008
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:3035
base_matrix(const base_matrix< T, Rows, Cols, StorageTraits, MathObject > &mat)
Creates a copy of the matrix mat.
Definition: matrix.hpp:1162
StorageTraits::constpointer_type data() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a pointer to the raw data of the matrix.
Definition: matrix.hpp:1674
void resize(size_type new_rows, size_type new_cols)
Resizes the matrix to new_rows times new_cols entries. If the new matrix has entries which cannot be ...
Definition: matrix.hpp:2036
ConstRowEnumerator Type
The row enumerator type.
Definition: matrix.hpp:2864
base_rowvector(size_type entries, const implementation::Initialize_Impl< S, def > &i)
Creates a row vector with entries entries. Its coefficients are copy-constructed from i...
Definition: matrix.hpp:3500
base_matrix()
Creates a new matrix. The dimensions are set to zero if no compile-time dimensions were specified...
Definition: matrix.hpp:1150
void swap(MatrixType &B)
Swaps the contents of this matrix with the matrix B.
Definition: matrix.hpp:2308
math_rowvector(const base_matrix< S, Rs, Cs, ST, MO > &mat)
Creates a copy of the row vector mat.
Definition: matrix.hpp:3790
void get_current(Result &result) const PLLL_INTERNAL_NOTHROW_POSTFIX_CONDITIONAL(noexcept(result=*d_entry))
Creates a copy of the current matrix entry in result.
Definition: matrix.hpp:2683
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a current column's enumerator.
Definition: matrix.hpp:2947
base_colvector(int entries)
Creates a column vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3658
Type current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a current column's enumerator.
Definition: matrix.hpp:3014
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current element exists and can be queried by the current(), get_current() and get_c...
Definition: matrix.hpp:2522
implementation::expressions::expr< implementation::expressions::sub_1d< Cols >::template operation_row, implementation::expressions::ConstMatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > row(size_type row_index) const
Returns the row_index-th row of this matrix.
Definition: matrix.hpp:1872
An enumerator for matrix elements.
Definition: matrix.hpp:2452
implementation::expressions::expr< implementation::expressions::transpose, implementation::expressions::ConstMatrixWrapper< base_matrix< T, Rows, Cols, StorageTraits, MathObject > > > transpose() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the transpose of this matrix.
Definition: matrix.hpp:1940
base_matrix(size_type entries)
Creates a vector with entries entries. Its coefficients are default-constructed.
Definition: matrix.hpp:1318
math_colvector()
Creates a new column vector. The dimensions are set to zero if no compile-time dimensions were specif...
Definition: matrix.hpp:3924
Represents a column vector with coefficients in T.
Definition: matrix.hpp:298
Represents a math matrix with coefficients in T.
Definition: matrix.hpp:210
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current row exists and can be queried by the current() method.
Definition: matrix.hpp:2832
An enumerator for matrix elements.
Definition: matrix.hpp:2368
void next() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Goes to the next element.
Definition: matrix.hpp:2714
bool has_current() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns true if a current element exists and can be queried by the current(), get_current() and get_c...
Definition: matrix.hpp:2428
Step1_Type step1() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Retrieves the coefficient as a simple expression. The result should be stored in a variable of the fi...
Definition: matrix.hpp:1565
Enumerator enumerate() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all entries of the current matrix.
Definition: matrix.hpp:2728
~math_rowvector() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory allocated for the row vector.
Definition: matrix.hpp:3877
math_matrix(size_type rows, size_type cols)
Creates a matrix with rows times cols entries. Its coefficients are default-constructed.
Definition: matrix.hpp:3341
ConstEnumerator enumerate() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Enumerates all entries of the current matrix.
Definition: matrix.hpp:2738
GetCoeffSteps_Type get_coeff_steps(size_type i, size_type j) const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns a object of type GetCoeffSteps_Type which constructs the coefficient at (i, j).
Definition: matrix.hpp:1592