diff --git a/include/carma.hpp b/include/carma.hpp index 162f51e..5c66d6f 100644 --- a/include/carma.hpp +++ b/include/carma.hpp @@ -1,10 +1,9 @@ /* carma/carma: Bidirectional coverter of Numpy arrays and Armadillo objects - * Copyright (c) 2022 Ralph Urlus + * Copyright (c) 2023 Ralph Urlus * All rights reserved. Use of this source code is governed by a * Apache-2.0 license that can be found in the LICENSE file. */ -#ifndef INCLUDE_CARMA_ -#define INCLUDE_CARMA_ +#pragma once /* If the Numpy allocator/deallocator have not been set through * the carma_armadillo target ARMA_ALIEN_MEM_ALLOC_FUNCTION and @@ -97,5 +96,3 @@ static carma_config_debug_message carma_config_debug_message_print; #endif // CARMA_EXTRA_DEBUG } // namespace carma - -#endif // INCLUDE_CARMA_ diff --git a/include/carma_bits/array_view.hpp b/include/carma_bits/array_view.hpp index 7123101..b466334 100644 --- a/include/carma_bits/array_view.hpp +++ b/include/carma_bits/array_view.hpp @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CARMA_BITS_ARRAY_VIEW_HPP_ -#define INCLUDE_CARMA_BITS_ARRAY_VIEW_HPP_ +#pragma once // pybind11 include required even if not explicitly used // to prevent link with pythonXX_d.lib on Win32 @@ -193,4 +192,3 @@ class ArrayView { } // namespace internal } // namespace carma -#endif // INCLUDE_CARMA_BITS_ARRAY_VIEW_HPP_ diff --git a/include/carma_bits/converters.hpp b/include/carma_bits/converters.hpp index 3f97d4e..b7155ce 100644 --- a/include/carma_bits/converters.hpp +++ b/include/carma_bits/converters.hpp @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CARMA_BITS_CONVERTERS_HPP_ -#define INCLUDE_CARMA_BITS_CONVERTERS_HPP_ +#pragma once #include #include @@ -335,4 +334,3 @@ auto arr_to_cube(numpyT arr) { } } // namespace carma -#endif // INCLUDE_CARMA_BITS_CONVERTERS_HPP_ diff --git a/include/carma_bits/numpy_alloc.hpp b/include/carma_bits/numpy_alloc.hpp index 60ba4f5..adb1c9c 100644 --- a/include/carma_bits/numpy_alloc.hpp +++ b/include/carma_bits/numpy_alloc.hpp @@ -3,8 +3,7 @@ * All rights reserved. Use of this source code is governed by a * Apache-2.0 license that can be found in the LICENSE file. */ -#ifndef INCLUDE_CARMA_BITS_NUMPY_ALLOC_HPP_ -#define INCLUDE_CARMA_BITS_NUMPY_ALLOC_HPP_ +#pragma once // pybind11 include required even if not explicitly used // to prevent link with pythonXX_d.lib on Win32 @@ -36,7 +35,7 @@ inline void npy_free(void* ptr) { const auto& api = internal::npy_api::get(); #ifdef CARMA_EXTRA_DEBUG std::cout << "|carma| freeing " << ptr << "\n"; -#endif // ARMA_EXTRA_DEBUG +#endif // CARMA_EXTRA_DEBUG api.PyDataMem_FREE_(ptr); } // npy_free @@ -51,4 +50,3 @@ inline void npy_free(void* ptr) { #ifndef CARMA_ARMA_ALIEN_MEM_FUNCTIONS_SET #define CARMA_ARMA_ALIEN_MEM_FUNCTIONS_SET true #endif -#endif // INCLUDE_CARMA_BITS_NUMPY_ALLOC_HPP_ diff --git a/include/carma_bits/numpy_api.hpp b/include/carma_bits/numpy_api.hpp index da9a0b4..cce0702 100644 --- a/include/carma_bits/numpy_api.hpp +++ b/include/carma_bits/numpy_api.hpp @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CARMA_BITS_NUMPY_API_HPP_ -#define INCLUDE_CARMA_BITS_NUMPY_API_HPP_ +#pragma once #include #include @@ -39,8 +38,16 @@ struct npy_api { int (*PyArray_Size_)(PyObject *src); int (*PyArray_CopyInto_)(PyArrayObject *dest, PyArrayObject *src); PyObject *(*PyArray_NewCopy_)(PyArrayObject *, int); - PyObject *(*PyArray_NewFromDescr_)(PyTypeObject *subtype, PyArray_Descr *descr, int nd, npy_intp const *dims, - npy_intp const *strides, void *data, int flags, PyObject *obj); + PyObject *(*PyArray_NewFromDescr_)( + PyTypeObject *subtype, + PyArray_Descr *descr, + int nd, + npy_intp const *dims, + npy_intp const *strides, + void *data, + int flags, + PyObject *obj + ); void (*PyArray_Free_)(PyArrayObject *, void *ptr); PyObject *(*PyArray_NewLikeArray_)(PyArrayObject *prototype, NPY_ORDER order, PyArray_Descr *descr, int subok); void *(*PyDataMem_NEW_)(size_t nbytes); @@ -81,4 +88,3 @@ struct npy_api { } // namespace internal } // namespace carma -#endif // INCLUDE_CARMA_BITS_NUMPY_API_HPP_ diff --git a/include/carma_bits/to_arma.hpp b/include/carma_bits/to_arma.hpp index 57e248f..f80e5b7 100644 --- a/include/carma_bits/to_arma.hpp +++ b/include/carma_bits/to_arma.hpp @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CARMA_BITS_TO_ARMA_HPP_ -#define INCLUDE_CARMA_BITS_TO_ARMA_HPP_ +#pragma once #include #include @@ -836,4 +835,3 @@ struct toArma { } // namespace internal } // namespace carma -#endif // INCLUDE_CARMA_BITS_TO_ARMA_HPP_ diff --git a/include/carma_bits/to_numpy.hpp b/include/carma_bits/to_numpy.hpp index 435aa01..e19ea52 100644 --- a/include/carma_bits/to_numpy.hpp +++ b/include/carma_bits/to_numpy.hpp @@ -1,5 +1,4 @@ -#ifndef INCLUDE_CARMA_BITS_TO_NUMPY_HPP_ -#define INCLUDE_CARMA_BITS_TO_NUMPY_HPP_ +#pragma once #include #include @@ -10,6 +9,17 @@ namespace carma { namespace internal { +// https://github.com/pybind/pybind11/issues/1042#issuecomment-642215028 +// template +// inline py::array_t as_pyarray(armaT &&seq) { +// auto size = seq.size(); +// auto data = seq.data(); +// std::unique_ptr seq_ptr = std::make_unique(std::move(seq)); +// auto capsule = py::capsule(seq_ptr.get(), [](void *p) { std::unique_ptr(reinterpret_cast(p)); }); +// seq_ptr.release(); +// return py::array(size, data, capsule); +// } + template inline py::capsule create_capsule(armaT data) { return py::capsule(data, [](void* f) { @@ -89,4 +99,3 @@ py::array_t create_reference_array(const ArmaView& src); } // namespace internal } // namespace carma -#endif // INCLUDE_CARMA_BITS_TO_NUMPY_HPP_