63 lines
1.3 KiB
C++
63 lines
1.3 KiB
C++
//
|
|
// php-armadillo/functions.cc
|
|
//
|
|
// @Author CismonX
|
|
//
|
|
|
|
#include "functions.hh"
|
|
#include "complex.hh"
|
|
|
|
#include <armadillo>
|
|
|
|
#define PHP_ARMA_FE(func) \
|
|
ZEND_RAW_FENTRY("Arma\\" #func, ZEND_FN(func), nullptr, 0)
|
|
|
|
namespace php_arma
|
|
{
|
|
PHP_FUNCTION(cx_double)
|
|
{
|
|
double real = 0.;
|
|
double imag = 0.;
|
|
ZEND_PARSE_PARAMETERS_START(0, 2)
|
|
Z_PARAM_OPTIONAL
|
|
Z_PARAM_DOUBLE(real)
|
|
Z_PARAM_DOUBLE(imag)
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
zval_set_scalar(return_value, std::complex<double>(real, imag));
|
|
}
|
|
|
|
PHP_FUNCTION(j)
|
|
{
|
|
double imag = 0.;
|
|
ZEND_PARSE_PARAMETERS_START(0, 1)
|
|
Z_PARAM_OPTIONAL
|
|
Z_PARAM_DOUBLE(imag)
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
zval_set_scalar(return_value, std::complex<double>(0., imag));
|
|
}
|
|
|
|
PHP_FUNCTION(srand)
|
|
{
|
|
zend_long seed;
|
|
ZEND_PARSE_PARAMETERS_START(0, 1)
|
|
Z_PARAM_OPTIONAL
|
|
Z_PARAM_LONG(seed)
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
if (EX_NUM_ARGS() == 0) {
|
|
arma::arma_rng::set_seed_random();
|
|
} else {
|
|
arma::arma_rng::set_seed(seed);
|
|
}
|
|
}
|
|
|
|
const zend_function_entry functions[] = {
|
|
PHP_ARMA_FE(cx_double)
|
|
PHP_ARMA_FE(j)
|
|
PHP_ARMA_FE(srand)
|
|
PHP_FE_END
|
|
};
|
|
}
|