lsst.astshim  master-gd0c6fad5f5+1
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
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:
57  explicit MatrixMap(ndarray::Array<double, 2, 2> const &matrix, std::string const &options = "")
58  : Mapping(reinterpret_cast<AstMapping *>(
59  // form 0 = full matrix, 1 = diagonal elements only
60  astMatrixMap(matrix.getSize<1>(), matrix.getSize<0>(), 0, matrix.getData(), "%s",
61  options.c_str()))) {}
62 
73  explicit MatrixMap(std::vector<double> const &diag, std::string const &options = "")
74  : Mapping(reinterpret_cast<AstMapping *>(
75  // form 0 = full matrix, 1 = diagonal elements only
76  astMatrixMap(diag.size(), diag.size(), 1, diag.data(), "%s", options.c_str()))) {}
77 
78  virtual ~MatrixMap() {}
79 
80  MatrixMap(MatrixMap const &) = delete;
81  MatrixMap(MatrixMap &&) = default;
82  MatrixMap &operator=(MatrixMap const &) = delete;
83  MatrixMap &operator=(MatrixMap &&) = default;
84 
86  std::shared_ptr<MatrixMap> copy() const {
87  return std::static_pointer_cast<MatrixMap>(copyPolymorphic());
88  }
89 
90 protected:
91  virtual std::shared_ptr<Object> copyPolymorphic() const override {
92  return copyImpl<MatrixMap, AstMatrixMap>();
93  }
94 
96  explicit MatrixMap(AstMatrixMap *rawptr) : Mapping(reinterpret_cast<AstMapping *>(rawptr)) {
97  if (!astIsAMatrixMap(getRawPtr())) {
98  std::ostringstream os;
99  os << "this is a " << getClassName() << ", which is not a MatrixMap";
100  throw std::invalid_argument(os.str());
101  }
102  }
103 };
104 
105 } // namespace ast
106 
107 #endif
Definition: MatrixMap.h:42
Definition: Mapping.h:59
Definition: Object.h:49
std::shared_ptr< MatrixMap > copy() const
Return a deep copy of this object.
Definition: MatrixMap.h:86
MatrixMap(AstMatrixMap *rawptr)
Construct a MatrixMap from a raw AST pointer.
Definition: MatrixMap.h:96
virtual std::shared_ptr< Object > copyPolymorphic() const override
Definition: MatrixMap.h:91
MatrixMap(ndarray::Array< double, 2, 2 > const &matrix, std::string const &options="")
Definition: MatrixMap.h:57
MatrixMap(std::vector< double > const &diag, std::string const &options="")
Definition: MatrixMap.h:73
std::string getClassName() const
Definition: Object.h:118
AstObject const * getRawPtr() const
Definition: Object.h:270