lsst.astshim  master-gd1207e8857
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
MatrixMap.h
1 /*
2  * LSST Data Management System
3  * Copyright 2016 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 public:
56  explicit MatrixMap(ndarray::Array<double, 2, 2> const & matrix, std::string const & options="")
57  :
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(), options.c_str())))
61  {}
62 
73  explicit MatrixMap(std::vector<double> const & diag, std::string const & options="")
74  :
75  Mapping(reinterpret_cast<AstMapping *>(
76  // form 0 = full matrix, 1 = diagonal elements only
77  astMatrixMap(diag.size(), diag.size(), 1, diag.data(), options.c_str())))
78  {}
79 
80  virtual ~MatrixMap() {}
81 
82  MatrixMap(MatrixMap const &) = delete;
83  MatrixMap(MatrixMap &&) = default;
84  MatrixMap & operator=(MatrixMap const &) = delete;
85  MatrixMap & operator=(MatrixMap &&) = default;
86 
88  std::shared_ptr<MatrixMap> copy() const {
89  return std::static_pointer_cast<MatrixMap>(_copyPolymorphic());
90  }
91 
92 protected:
93  virtual std::shared_ptr<Object> _copyPolymorphic() const override {
94  return _copyImpl<MatrixMap, AstMatrixMap>();
95  }
96 
98  explicit MatrixMap(AstMatrixMap * rawptr) :
99  Mapping(reinterpret_cast<AstMapping *>(rawptr))
100  {
101  if (!astIsAMatrixMap(getRawPtr())) {
102  std::ostringstream os;
103  os << "this is a " << getClass() << ", which is not a MatrixMap";
104  throw std::invalid_argument(os.str());
105  }
106  }
107 };
108 
109 } // namespace ast
110 
111 #endif
Definition: MatrixMap.h:42
std::string getClass() const
Definition: Object.h:117
Definition: Mapping.h:59
Definition: Object.h:49
std::shared_ptr< MatrixMap > copy() const
Return a deep copy of this object.
Definition: MatrixMap.h:88
virtual std::shared_ptr< Object > _copyPolymorphic() const override
Definition: MatrixMap.h:93
MatrixMap(AstMatrixMap *rawptr)
Construct a MatrixMap from a raw AST pointer.
Definition: MatrixMap.h:98
MatrixMap(ndarray::Array< double, 2, 2 > const &matrix, std::string const &options="")
Definition: MatrixMap.h:56
MatrixMap(std::vector< double > const &diag, std::string const &options="")
Definition: MatrixMap.h:73
AstObject const * getRawPtr() const
Definition: Object.h:260