Skip to content

Commit

Permalink
CHG: Consistently use pragma once over include guards
Browse files Browse the repository at this point in the history
  • Loading branch information
RUrlus committed Oct 8, 2023
1 parent 5f3e7fc commit 2c58bde
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
7 changes: 2 additions & 5 deletions include/carma.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* carma/carma: Bidirectional coverter of Numpy arrays and Armadillo objects
* Copyright (c) 2022 Ralph Urlus <[email protected]>
* Copyright (c) 2023 Ralph Urlus <[email protected]>
* 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
Expand Down Expand Up @@ -97,5 +96,3 @@ static carma_config_debug_message carma_config_debug_message_print;
#endif // CARMA_EXTRA_DEBUG

} // namespace carma

#endif // INCLUDE_CARMA_
4 changes: 1 addition & 3 deletions include/carma_bits/array_view.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -193,4 +192,3 @@ class ArrayView {

} // namespace internal
} // namespace carma
#endif // INCLUDE_CARMA_BITS_ARRAY_VIEW_HPP_
4 changes: 1 addition & 3 deletions include/carma_bits/converters.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef INCLUDE_CARMA_BITS_CONVERTERS_HPP_
#define INCLUDE_CARMA_BITS_CONVERTERS_HPP_
#pragma once

#include <armadillo>
#include <carma_bits/array_view.hpp>
Expand Down Expand Up @@ -335,4 +334,3 @@ auto arr_to_cube(numpyT arr) {
}

} // namespace carma
#endif // INCLUDE_CARMA_BITS_CONVERTERS_HPP_
6 changes: 2 additions & 4 deletions include/carma_bits/numpy_alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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_
16 changes: 11 additions & 5 deletions include/carma_bits/numpy_api.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef INCLUDE_CARMA_BITS_NUMPY_API_HPP_
#define INCLUDE_CARMA_BITS_NUMPY_API_HPP_
#pragma once

#include <Python.h>
#include <pybind11/numpy.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -81,4 +88,3 @@ struct npy_api {

} // namespace internal
} // namespace carma
#endif // INCLUDE_CARMA_BITS_NUMPY_API_HPP_
4 changes: 1 addition & 3 deletions include/carma_bits/to_arma.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef INCLUDE_CARMA_BITS_TO_ARMA_HPP_
#define INCLUDE_CARMA_BITS_TO_ARMA_HPP_
#pragma once

#include <armadillo>
#include <carma_bits/array_view.hpp>
Expand Down Expand Up @@ -836,4 +835,3 @@ struct toArma {
} // namespace internal

} // namespace carma
#endif // INCLUDE_CARMA_BITS_TO_ARMA_HPP_
15 changes: 12 additions & 3 deletions include/carma_bits/to_numpy.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef INCLUDE_CARMA_BITS_TO_NUMPY_HPP_
#define INCLUDE_CARMA_BITS_TO_NUMPY_HPP_
#pragma once

#include <armadillo>
#include <carma_bits/common.hpp>
Expand All @@ -10,6 +9,17 @@ namespace carma {

namespace internal {

// https://github.com/pybind/pybind11/issues/1042#issuecomment-642215028
// template <typename armaT>
// inline py::array_t<typename armaT::value_type> as_pyarray(armaT &&seq) {
// auto size = seq.size();
// auto data = seq.data();
// std::unique_ptr<armaT> seq_ptr = std::make_unique<armaT>(std::move(seq));
// auto capsule = py::capsule(seq_ptr.get(), [](void *p) { std::unique_ptr<armaT>(reinterpret_cast<armaT*>(p)); });
// seq_ptr.release();
// return py::array(size, data, capsule);
// }

template <typename armaT>
inline py::capsule create_capsule(armaT data) {
return py::capsule(data, [](void* f) {
Expand Down Expand Up @@ -89,4 +99,3 @@ py::array_t<eT> create_reference_array(const ArmaView& src);

} // namespace internal
} // namespace carma
#endif // INCLUDE_CARMA_BITS_TO_NUMPY_HPP_

0 comments on commit 2c58bde

Please sign in to comment.