COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
sparse_obj.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // This file is part of COMPASS <https://anr-compass.github.io/compass/>
3 //
4 // Copyright (C) 2011-2019 COMPASS Team <https://github.com/ANR-COMPASS>
5 // All rights reserved.
6 // Distributed under GNU - LGPL
7 //
8 // COMPASS is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser
9 // General Public License as published by the Free Software Foundation, either version 3 of the License,
10 // or any later version.
11 //
12 // COMPASS: End-to-end AO simulation tool using GPU acceleration
13 // The COMPASS platform was designed to meet the need of high-performance for the simulation of AO systems.
14 //
15 // The final product includes a software package for simulating all the critical subcomponents of AO,
16 // particularly in the context of the ELT and a real-time core based on several control approaches,
17 // with performances consistent with its integration into an instrument. Taking advantage of the specific
18 // hardware architecture of the GPU, the COMPASS tool allows to achieve adequate execution speeds to
19 // conduct large simulation campaigns called to the ELT.
20 //
21 // The COMPASS platform can be used to carry a wide variety of simulations to both testspecific components
22 // of AO of the E-ELT (such as wavefront analysis device with a pyramid or elongated Laser star), and
23 // various systems configurations such as multi-conjugate AO.
24 //
25 // COMPASS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
26 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 // See the GNU Lesser General Public License for more details.
28 //
29 // You should have received a copy of the GNU Lesser General Public License along with COMPASS.
30 // If not, see <https://www.gnu.org/licenses/lgpl-3.0.txt>.
31 // -----------------------------------------------------------------------------
32 
40 
41 #ifndef _WRAP_SPARSE_OBJ_H_
42 #define _WRAP_SPARSE_OBJ_H_
43 
44 #include "declare_name.hpp"
45 
46 #include <carma.h>
47 
48 #include <wyrm>
49 
50 #include <carma_sparse_obj.h>
51 
52 #include <type_list.hpp>
53 
54 namespace py = pybind11;
55 
57  template <typename T> static void call(py::module &mod) {
58  auto name = appendName<T>("sparse_obj_");
59  using Class = CarmaSparseObj<T>;
60 
61  py::class_<Class>(mod, name.data(), py::buffer_protocol())
62  .def("get_csr",[](Class &frame){
63  py::object CSR = py::module::import("scipy.sparse").attr("csr_matrix");
64  int dim1 = frame.get_dims(1);
65  int dim2 = frame.get_dims(2);
66  int nnz = frame.nz_elem;
67 
68  std::vector<int> rowind = std::vector<int>(dim1 + 1);
69  std::vector<int> colind = std::vector<int>(nnz);
70  std::vector<T> data = std::vector<T>(nnz);
71 
72  frame.sparse_to_host(rowind.data(), colind.data(), data.data());
73  py::tuple csrMat = py::make_tuple(py::array(data.size(),data.data()), py::array(colind.size(),colind.data()),py::array(rowind.size(), rowind.data()));
74  py::tuple shape = py::make_tuple(dim1,dim2);
75 
76 
77  return CSR(csrMat,py::arg("shape")=shape);
78  });
79 }
80 };
81 #endif
CarmaSparseObjInterfacer::call
static void call(py::module &mod)
Definition: sparse_obj.hpp:57
declare_name.hpp
this file provides pybind wrapper for libcarma
CarmaSparseObj
this class provides wrappers to the generic carma sparse object
Definition: carma_sparse_host_obj.h:48
CarmaSparseObjInterfacer
Definition: sparse_obj.hpp:56
carma_sparse_obj.h