lsst.astshim  14.0-20-gf4f7515
MatrixMap.h
1 /*
2  * LSST Data Management System
3  * Copyright 2017 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #ifndef ASTSHIM_MATRIXMAP_H
23 #define ASTSHIM_MATRIXMAP_H
24 
25 #include <memory>
26 #include <vector>
27 
28 #include "ndarray.h"
29 
30 #include "astshim/base.h"
31 #include "astshim/Mapping.h"
32 
33 namespace ast {
34 
42 class MatrixMap : public Mapping {
43  friend class Object;
44 
45 public:
56  explicit MatrixMap(ConstArray2D const &matrix, std::string const &options = "")
57  : Mapping(reinterpret_cast<AstMapping *>(
58  // form 0 = full matrix, 1 = diagonal elements only
59  astMatrixMap(matrix.getSize<1>(), matrix.getSize<0>(), 0, matrix.getData(), "%s",
60  options.c_str()))) {}
61 
71  explicit MatrixMap(std::vector<double> const &diag, std::string const &options = "")
72  : Mapping(reinterpret_cast<AstMapping *>(
73  // form 0 = full matrix, 1 = diagonal elements only
74  astMatrixMap(diag.size(), diag.size(), 1, diag.data(), "%s", options.c_str()))) {}
75 
76  virtual ~MatrixMap() {}
77 
79  MatrixMap(MatrixMap const &) = default;
80  MatrixMap(MatrixMap &&) = default;
81  MatrixMap &operator=(MatrixMap const &) = delete;
82  MatrixMap &operator=(MatrixMap &&) = default;
83 
85  std::shared_ptr<MatrixMap> copy() const { return std::static_pointer_cast<MatrixMap>(copyPolymorphic()); }
86 
87 protected:
88  virtual std::shared_ptr<Object> copyPolymorphic() const override {
89  return copyImpl<MatrixMap, AstMatrixMap>();
90  }
91 
93  explicit MatrixMap(AstMatrixMap *rawptr) : Mapping(reinterpret_cast<AstMapping *>(rawptr)) {
94  if (!astIsAMatrixMap(getRawPtr())) {
95  std::ostringstream os;
96  os << "this is a " << getClassName() << ", which is not a MatrixMap";
97  throw std::invalid_argument(os.str());
98  }
99  }
100 };
101 
102 } // namespace ast
103 
104 #endif
ndarray::Array< const double, 2, 2 > ConstArray2D
Definition: base.h:46
AstObject const * getRawPtr() const
Definition: Object.h:291
Definition: MatrixMap.h:42
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
std::string getClassName() const
Definition: Object.h:138
virtual std::shared_ptr< Object > copyPolymorphic() const override
Definition: MatrixMap.h:88
MatrixMap(AstMatrixMap *rawptr)
Construct a MatrixMap from a raw AST pointer.
Definition: MatrixMap.h:93
Definition: Mapping.h:59
std::shared_ptr< MatrixMap > copy() const
Return a deep copy of this object.
Definition: MatrixMap.h:85
Definition: Object.h:51
MatrixMap(std::vector< double > const &diag, std::string const &options="")
Definition: MatrixMap.h:71
MatrixMap(ConstArray2D const &matrix, std::string const &options="")
Definition: MatrixMap.h:56