MyraMath
ActionBase.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_ITERATIVE_ACTIONBASE_H
7 #define MYRAMATH_ITERATIVE_ACTIONBASE_H
8 
14 #include <myramath/MYRAMATH_EXPORT.h>
16 
17 #include <utility>
18 
19 namespace myra {
20 
21 // Forward declarations.
22 template<class Number> class Matrix;
23 template<class Number> class CMatrixRange;
24 template<class Number> class MatrixRange;
25 template<class Number> class Action;
26 
27 namespace detail {
28 
29 // Implementation detail. Base class for all Action's.
30 template<class Number> class MYRAMATH_EXPORT ActionBase
31  {
32  protected:
33 
34  // Useful typedefs.
35  typedef CMatrixRange<Number> X;
36  typedef MatrixRange<Number> B;
37 
38  // Size inspector.
39  virtual std::pair<int,int> size() const = 0;
40 
41  // Subclasses must implement at least one of these two multiply()
42  // methods. Choose whichever signature is most natural/efficient.
43  // Whichever one you choose, the *other* one will just delegate.
44  // (if you implement neither, infinite delegation/recursion ensues)
45 
46  // Assigns B = alpha*A*X + beta*B
47  virtual void multiply(const X& x, const B& b, Number alpha, Number beta) const;
48 
49  // Assigns B = A*X
50  virtual void multiply(const X& x, const B& b) const;
51 
52  // Virtual destructor, so subtypes can release resources.
53  virtual ~ActionBase();
54 
55  // Virtual copy constructor.
56  virtual ActionBase<Number>* clone() const = 0;
57 
58  // Friendship for encapsulating Action, so it can clone()/copy.
59  friend class ::myra::Action<Number>;
60 
61  };
62 
63 // Default constructed value of an Action, does nothing.
64 template<class Number> class NullAction : public ActionBase<Number>
65  {
66  public:
67 
68  // Useful typedefs.
69  typedef CMatrixRange<Number> X;
70  typedef MatrixRange<Number> B;
71 
72  // Default constructor.
73  NullAction()
74  { }
75 
76  protected:
77 
78  // Size inspector.
79  virtual std::pair<int,int> size() const
80  { return std::pair<int,int>(0,0); }
81 
82  // Does nothing.
83  virtual void multiply(const X& x, const B& b, Number alpha, Number beta) const
84  { }
85 
86  // Does nothing.
87  virtual void multiply(const X& x, const B& b) const
88  { }
89 
90  // Virtual copy constructor.
91  virtual ActionBase<Number>* clone() const
92  { return new NullAction(); }
93 
94  };
95 
96 } // namespace detail
97 
98 } // namespace
99 
100 #endif
Definition: Action.h:28
Definition: syntax.dox:1
Represents a const MatrixRange.
Definition: bothcat.h:22
Definition: ActionBase.h:64
Definition: random.cpp:45
Various utility functions/classes related to scalar Number types.
Represents a mutable MatrixRange.
Definition: conjugate.h:26