Fix subview comparison bug
This commit is contained in:
parent
359f8dbc5e
commit
10913b6f7d
36
src/dense.hh
36
src/dense.hh
|
@ -23,6 +23,7 @@
|
|||
#define PHP_ARMA_DENSE_OPERATOR(func) \
|
||||
PHP_ARMA_OPERATOR_BEGIN(dense_ce) \
|
||||
PHP_ARMA_DENSE_OPERATOR_EX(mat, func) \
|
||||
PHP_ARMA_DENSE_OPERATOR_EX(subview_mat, func) \
|
||||
PHP_ARMA_OPERATOR_END()
|
||||
|
||||
namespace php_arma
|
||||
|
@ -38,21 +39,44 @@ namespace php_arma
|
|||
zend_always_inline
|
||||
static bool compare_op(zval *zv1, zval *zv2, zval *return_value, F&& func)
|
||||
{
|
||||
if (UNEXPECTED(Z_TYPE_P(zv1) != IS_OBJECT) ||
|
||||
UNEXPECTED(Z_TYPE_P(zv2) != IS_OBJECT) ||
|
||||
UNEXPECTED(Z_OBJCE_P(zv1) != Z_OBJCE_P(zv2))) {
|
||||
throw_exception_ex(zend_ce_type_error, "bad comparison, object types should be the same");
|
||||
if (UNEXPECTED(Z_TYPE_P(zv1) != IS_OBJECT) || UNEXPECTED(Z_TYPE_P(zv2) != IS_OBJECT)) {
|
||||
throw_exception_ex(zend_ce_type_error, "bad comparison, cannot compare to non-object");
|
||||
return false;
|
||||
}
|
||||
|
||||
if constexpr (!IsEq && std::is_same_v<T, cx_double>) {
|
||||
throw_error("no such comparation for complex elements");
|
||||
throw_error("no such comparison for complex elements");
|
||||
return false;
|
||||
} else {
|
||||
using n_orig_t = typename ChildT::orig_t::native_t;
|
||||
using n_subview_t = typename ChildT::subview_t::native_t;
|
||||
using dest_t = typename ChildT::with_int_elem_t::orig_t;
|
||||
using dest_native_t = typename dest_t::native_t;
|
||||
try {
|
||||
auto ret = func(Z_NATIVE_OBJ_P(zv1), Z_NATIVE_OBJ_P(zv2)).eval();
|
||||
arma::umat ret;
|
||||
auto o1 = Z_OBJ_P(zv1);
|
||||
auto o2 = Z_OBJ_P(zv2);
|
||||
if (Z_OBJCE_P(zv1) == ChildT::orig_t::ce) {
|
||||
if (Z_OBJCE_P(zv2) == ChildT::orig_t::ce) {
|
||||
ret = func(to_native_object<n_orig_t>(o1), to_native_object<n_orig_t>(o2)).eval();
|
||||
} else if (EXPECTED(Z_OBJCE_P(zv2) == ChildT::subview_t::ce)) {
|
||||
ret = func(to_native_object<n_orig_t>(o1), to_native_object<n_subview_t>(o2)).eval();
|
||||
} else {
|
||||
goto not_orig_or_subview;
|
||||
}
|
||||
} else if (EXPECTED(Z_OBJCE_P(zv1) == ChildT::subview_t::ce)) {
|
||||
if (Z_OBJCE_P(zv2) == ChildT::orig_t::ce) {
|
||||
ret = func(to_native_object<n_subview_t>(o1), to_native_object<n_orig_t>(o2)).eval();
|
||||
} else if (EXPECTED(Z_OBJCE_P(zv2) == ChildT::subview_t::ce)) {
|
||||
ret = func(to_native_object<n_subview_t>(o1), to_native_object<n_subview_t>(o2)).eval();
|
||||
} else {
|
||||
goto not_orig_or_subview;
|
||||
}
|
||||
} else {
|
||||
not_orig_or_subview:
|
||||
throw_exception_ex(zend_ce_type_error, "bad comparison, object types should be the same");
|
||||
return false;
|
||||
}
|
||||
RETVAL_OBJ(dest_t::create(std::move(arma::conv_to<dest_native_t>::from(ret))));
|
||||
return true;
|
||||
} catch (const std::logic_error& err) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "complex.hh"
|
||||
#include "dense.hh"
|
||||
#include "mat.hh"
|
||||
#include "subview_mat.hh"
|
||||
#include "mapval.hh"
|
||||
|
||||
#include <armadillo>
|
||||
|
|
Reference in New Issue