Skip to content

Commit

Permalink
FIX: Support fixed-size matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx authored and RUrlus committed Nov 9, 2022
1 parent 2fcf122 commit efbe052
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions include/carma_bits/converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,31 @@ inline py::array_t<T> to_numpy(armaT* src, int copy = 0) {
return details::construct_array<T>(data);
} /* to_numpy */

template <typename armaT, typename T = typename armaT::elem_type, is_Mat_fixed_only<armaT> = 4>
inline py::array_t<T> to_numpy(armaT& src, int copy = 0) {
// if not copy we steal
armaT* data;
if (!copy) {
data = new armaT(std::move(src));
} else {
data = new armaT(src.memptr());
}
return details::construct_array<T>(data);
} /* to_numpy */

template <typename armaT, typename T = typename armaT::elem_type, is_Mat_fixed_only<armaT> = 4>
inline py::array_t<T> to_numpy(armaT* src, int copy = 0) {
// if not copy we steal
armaT* data;
if (!copy) {
data = new armaT(std::move(*src));
} else {
data = new armaT(src->memptr());
}
return details::construct_array<T>(data);
} /* to_numpy */


/* ---------------------------------- to_numpy_view ---------------------------------- */
template <typename armaT, typename T = typename armaT::elem_type>
inline py::array_t<T> to_numpy_view(const armaT& src) {
Expand Down
5 changes: 4 additions & 1 deletion include/carma_bits/typecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ using is_Vec = std::enable_if_t<p_is_Vec<armaT>::value, int>;
template <typename armaT>
using is_Mat = std::enable_if_t<arma::is_Mat<armaT>::value, int>;
template <typename armaT>
using is_Mat_only = std::enable_if_t<arma::is_Mat_only<armaT>::value, int>;
using is_Mat_only = std::enable_if_t< arma::is_Mat_only<armaT>::value &&
!arma::is_Mat_fixed_only<armaT>::value, int>;
template <typename armaT>
using is_Mat_fixed_only = std::enable_if_t<arma::is_Mat_fixed_only<armaT>::value, int>;

template <typename T>
struct is_mat : std::false_type {};
Expand Down

0 comments on commit efbe052

Please sign in to comment.