Skip to content

Commit

Permalink
CHG: Add debug statements and use consistent container naming
Browse files Browse the repository at this point in the history
  • Loading branch information
RUrlus committed Oct 23, 2023
1 parent b5f0bcf commit 858bd53
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
23 changes: 16 additions & 7 deletions include/carma_bits/base/numpy_converters.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#include <armadillo>
#include <carma_bits/base/config.hpp>
#include <carma_bits/base/converter_types.hpp>
#include <carma_bits/base/numpy_converters.hpp>
#include <carma_bits/converter_types.hpp>
#include <carma_bits/internal/common.hpp>
#include <carma_bits/internal/numpy_container.hpp>
#include <carma_bits/internal/numpy_converters.hpp>
Expand All @@ -27,13 +28,21 @@ struct NumpyConverter {
"|carma| `memory_order_policy` must be one of: ColumnOrder, "
"TransposedRowOrder."
);
NumpyContainer view(src);
FitsArmaType().check<armaT>(view);
memory_order_policy().template check<armaT>(view);
if (CARMA_UNLIKELY(src.ill_conditioned || src.order_copy)) {
return CopyIntoConverter().get<armaT>(src);
NumpyContainer container(src);
FitsArmaType().check<armaT>(container);
memory_order_policy().template check<armaT>(container);
if (CARMA_UNLIKELY(container.ill_conditioned || container.order_copy)) {
carma_debug_print(
"Using CopyIntoConverter, array ",
container.arr,
" does not meet the required conditions and must be copied into the Arma object using Numpy."
);
return CopyIntoConverter().get<armaT>(container);
}
return CopyInConverter().get<armaT>(src);
carma_debug_print(
"Using CopyInConverter, array ", container.arr, " will be copied in by Arma object's constructor."
);
return CopyInConverter().get<armaT>(container);
}
};

Expand Down
10 changes: 5 additions & 5 deletions include/carma_bits/extension/numpy_converters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ struct NumpyConverter {
"references"
);
#endif
NumpyContainer view(src);
NumpyContainer container(src);
#ifdef CARMA_EXTRA_DEBUG
NumpyConverterInfo<armaT, numpyT, converter, resolution_policy, memory_order_policy>()(view);
NumpyConverterInfo<armaT, numpyT, converter, resolution_policy, memory_order_policy>()(container);
#endif // CARMA_EXTRA_DEBUG
FitsArmaType().check<armaT>(view);
memory_order_policy().template check<armaT>(view);
return resolution_policy().template resolve<armaT, converter>(view);
FitsArmaType().check<armaT>(container);
memory_order_policy().template check<armaT>(container);
return resolution_policy().template resolve<armaT, converter>(container);
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/carma_bits/internal/numpy_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class NumpyContainer {
template <typename armaT, iff_Arma<armaT> = 0>
inline void copy_into(armaT& dest) {
using eT = typename armaT::elem_type;
carma_debug_print("Copying data of array ", obj, " to ", dest.memptr(), " using Numpy.");
carma_extra_debug_print("Copying data of array ", obj, " to ", dest.memptr(), " using Numpy.");
auto api = npy_api::get();
// make the temporary array writeable and mark the memory as aligned and give the order of the arma object
int flags
Expand All @@ -100,7 +100,7 @@ class NumpyContainer {
} // copy_into

inline void make_arma_compatible() {
carma_debug_print("Copying array ", obj, " to Arma compatible layout using Numpy.");
carma_extra_debug_print("Copying array ", obj, " to Arma compatible layout using Numpy.");
auto api = npy_api::get();
PyObject* dest_obj = api.PyArray_NewLikeArray_(arr, NPY_FORTRANORDER, nullptr, 0);
auto dest_arr = reinterpret_cast<PyArrayObject*>(dest_obj);
Expand Down

0 comments on commit 858bd53

Please sign in to comment.