Implement `equals()` and `notEquals()`.

This commit is contained in:
CismonX 2019-05-30 12:55:33 +08:00
parent 92e15f3e5f
commit 37da00eb75
3 changed files with 39 additions and 8 deletions

View File

@ -5,21 +5,48 @@
//
#include "dense.hh"
#include "mat.hh"
#include <armadillo>
namespace php_arma
{
template <typename T, typename T1>
PHP_ARMA_METHOD(dense, equals, T, T1)
template <typename T, typename ChildT>
PHP_ARMA_METHOD(dense, equals, T, ChildT)
{
zval *other;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT_DEREF(other)
ZEND_PARSE_PARAMETERS_END();
if (Z_OBJCE_P(other) != ChildT::ce) {
ex_bad_type(zval_get_type_name(getThis()), zval_get_type_name(other));
RETURN_NULL();
}
using dest_t = typename ChildT::with_int_elem_t;
using dest_native_t = typename dest_t::native_t;
auto eq = (*Z_NATIVE_OBJ_P(getThis()) == *Z_NATIVE_OBJ_P(other)).eval();
RETVAL_OBJ(dest_t::create(std::move(arma::conv_to<dest_native_t>::from(eq))));
}
template <typename T, typename T1>
PHP_ARMA_METHOD(dense, notEquals, T, T1)
template <typename T, typename ChildT>
PHP_ARMA_METHOD(dense, notEquals, T, ChildT)
{
zval *other;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT_DEREF(other)
ZEND_PARSE_PARAMETERS_END();
if (Z_OBJCE_P(other) != ChildT::ce) {
ex_bad_type(zval_get_type_name(getThis()), zval_get_type_name(other));
RETURN_NULL();
}
using dest_t = typename ChildT::with_int_elem_t;
using dest_native_t = typename dest_t::native_t;
auto eq = (*Z_NATIVE_OBJ_P(getThis()) != *Z_NATIVE_OBJ_P(other)).eval();
RETVAL_OBJ(dest_t::create(std::move(arma::conv_to<dest_native_t>::from(eq))));
}
template <typename T, typename T1>

View File

@ -22,7 +22,8 @@ namespace php_arma
template <typename T>
struct mat
{
using native_t = arma::Mat<T>;
using native_t = arma::Mat<T>;
using with_int_elem_t = mat<zend_long>;
friend void mat_init();

View File

@ -82,12 +82,15 @@
Z_PARAM_STR_EX2(dest, 0, 1, 0)
#define Z_PARAM_ARRAY_DEREF(dest) \
Z_PARAM_ARRAY_EX2(dest, 0, 1, 0)
#define Z_PARAM_OBJECT_DEREF(dest) \
Z_PARAM_OBJECT_EX2(dest, 0, 1, 0)
#else
// Before PHP 7.2, parameter is dereferenced by default here.
#define Z_PARAM_DOUBLE_DEREF Z_PARAM_DOUBLE
#define Z_PARAM_LONG_DEREF Z_PARAM_LONG
#define Z_PARAM_STR_DEREF Z_PARAM_STR
#define Z_PARAM_ARRAY_DEREF Z_PARAM_ARRAY
#define Z_PARAM_OBJECT_DEREF Z_PARAM_OBJECT
#endif
#ifdef PHP_ARMA_OPERATORS