diff --git a/src/base.cc b/src/base.cc index 9d3df0a..d10bdef 100644 --- a/src/base.cc +++ b/src/base.cc @@ -77,49 +77,57 @@ namespace php_arma template PHP_ARMA_METHOD(base, min, T, T1) { - + auto native = THIS_NATIVE; + zval_set_scalar(return_value, native->min()); } template PHP_ARMA_METHOD(base, max, T, T1) { - + auto native = THIS_NATIVE; + zval_set_scalar(return_value, native->max()); } template PHP_ARMA_METHOD(base, indexMin, T, T1) { - + auto native = THIS_NATIVE; + RETVAL_LONG(native->index_min()); } template PHP_ARMA_METHOD(base, indexMax, T, T1) { - + auto native = THIS_NATIVE; + RETVAL_LONG(native->index_max()); } template PHP_ARMA_METHOD(base, isEmpty, T, T1) { - + auto native = THIS_NATIVE; + RETVAL_BOOL(native->is_empty()); } template PHP_ARMA_METHOD(base, isFinite, T, T1) { - + auto native = THIS_NATIVE; + RETVAL_BOOL(native->is_finite()); } template PHP_ARMA_METHOD(base, hasInf, T, T1) { - + auto native = THIS_NATIVE; + RETVAL_BOOL(native->has_inf()); } template PHP_ARMA_METHOD(base, hasNan, T, T1) { - + auto native = THIS_NATIVE; + RETVAL_BOOL(native->has_nan()); } template diff --git a/src/constants.cc b/src/constants.cc index fdf74a8..7bd6140 100644 --- a/src/constants.cc +++ b/src/constants.cc @@ -10,32 +10,6 @@ namespace php_arma { - arma::file_type file_type::native(zend_long val) - { - switch (val) { - case file_type::auto_detect: - return arma::file_type::auto_detect; - case file_type::arma_binary: - return arma::file_type::arma_binary; - case file_type::arma_ascii: - return arma::file_type::arma_ascii; - case file_type::raw_binary: - return arma::file_type::raw_binary; - case file_type::csv_ascii: - return arma::file_type::csv_ascii; - case file_type::coord_ascii: - return arma::file_type::coord_ascii; - case file_type::pgm_binary: - return arma::file_type::pgm_binary; -#ifdef ARMA_USE_HDF5 - case file_type::hdf5_binary: - return arma::file_type::hdf5_binary; -#endif // ARMA_USE_HDF5 - default: - return arma::file_type::file_type_unknown; - } - } - template zend_always_inline void const_declare(zend_class_entry *ce, Ts&&... constants) diff --git a/src/constants.hh b/src/constants.hh index 8095767..df64abb 100644 --- a/src/constants.hh +++ b/src/constants.hh @@ -21,6 +21,33 @@ namespace php_arma static constexpr auto eye = 3; static constexpr auto randu = 4; static constexpr auto randn = 5; + + template + zend_always_inline + static void invoke(T *obj, zend_long val) + { + switch (val) { + case fill::none: + break; + case fill::zeros: + obj->zeros(); + break; + case fill::ones: + obj->ones(); + break; + case fill::eye: + obj->eye(); + break; + case fill::randu: + obj->randu(); + break; + case fill::randn: + obj->randn(); + break; + default: + zend_throw_exception(zend_ce_error, "bad fill type", 0); + } + } }; constexpr const char fill_php_name[] = "Fill"; @@ -38,7 +65,32 @@ namespace php_arma static constexpr auto pgm_binary = 7; static constexpr auto hdf5_binary = 8; - static arma::file_type native(zend_long); + zend_always_inline + static arma::file_type native(zend_long val) + { + switch (val) { + case file_type::auto_detect: + return arma::file_type::auto_detect; + case file_type::arma_binary: + return arma::file_type::arma_binary; + case file_type::arma_ascii: + return arma::file_type::arma_ascii; + case file_type::raw_binary: + return arma::file_type::raw_binary; + case file_type::csv_ascii: + return arma::file_type::csv_ascii; + case file_type::coord_ascii: + return arma::file_type::coord_ascii; + case file_type::pgm_binary: + return arma::file_type::pgm_binary; +#ifdef ARMA_USE_HDF5 + case file_type::hdf5_binary: + return arma::file_type::hdf5_binary; +#endif // ARMA_USE_HDF5 + default: + return arma::file_type::file_type_unknown; + } + } }; constexpr const char file_type_php_name[] = "FileType"; diff --git a/src/mat.cc b/src/mat.cc index 2db8dd5..eddaba2 100644 --- a/src/mat.cc +++ b/src/mat.cc @@ -5,6 +5,7 @@ // #include "mat.hh" +#include "constants.hh" #include "base.hh" #include "dense.hh" #include "matrix.hh" @@ -20,7 +21,19 @@ namespace php_arma template PHP_ARMA_METHOD(mat, init, T) { - + zend_long n_rows = 0; + zend_long n_cols = 0; + zend_long fill = fill::none; + ZEND_PARSE_PARAMETERS_START(0, 3) + Z_PARAM_OPTIONAL + Z_PARAM_LONG_DEREF(n_rows) + Z_PARAM_LONG_DEREF(n_cols) + Z_PARAM_LONG_DEREF(fill) + ZEND_PARSE_PARAMETERS_END(); + + auto zobj = create(n_rows, n_cols); + fill::invoke(ZOBJ_NATIVE(zobj), fill); + RETVAL_OBJ(zobj); } template diff --git a/src/resizable.cc b/src/resizable.cc index 3567a0e..02b17b4 100644 --- a/src/resizable.cc +++ b/src/resizable.cc @@ -70,7 +70,8 @@ namespace php_arma template PHP_ARMA_METHOD(resizable, reset, T, T1) { - + auto native = THIS_NATIVE; + native->reset(); } template