2019-05-25 18:21:48 +00:00
|
|
|
//
|
|
|
|
// php-armadillo/resizable_matrix.cc
|
|
|
|
//
|
|
|
|
// @Author CismonX
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "resizable_matrix.hh"
|
2019-06-06 15:56:10 +00:00
|
|
|
#include "resizable.hh"
|
|
|
|
#include "matrix.hh"
|
2019-05-25 18:21:48 +00:00
|
|
|
#include "mat.hh"
|
|
|
|
|
2019-06-02 15:04:39 +00:00
|
|
|
#include <armadillo>
|
|
|
|
|
2019-05-25 18:21:48 +00:00
|
|
|
namespace php_arma
|
|
|
|
{
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, reshape, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long n_rows, n_cols;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(2, 2)
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(n_rows)
|
|
|
|
Z_PARAM_LONG(n_cols)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->reshape(n_rows, n_cols);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, resize, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long n_rows, n_cols;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(2, 2)
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(n_rows)
|
|
|
|
Z_PARAM_LONG(n_cols)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->resize(n_rows, n_cols);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, setSize, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long n_rows, n_cols;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(2, 2)
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(n_rows)
|
|
|
|
Z_PARAM_LONG(n_cols)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->set_size(n_rows, n_cols);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, zeros, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long n_rows = 0;
|
|
|
|
zend_long n_cols = 0;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(0, 2)
|
|
|
|
Z_PARAM_OPTIONAL
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(n_rows)
|
|
|
|
Z_PARAM_LONG(n_cols)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->zeros(n_rows, n_cols);
|
2019-06-12 03:11:27 +00:00
|
|
|
RETVAL_THIS();
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, eye, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long n_rows = 0;
|
|
|
|
zend_long n_cols = 0;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(0, 2)
|
|
|
|
Z_PARAM_OPTIONAL
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(n_rows)
|
|
|
|
Z_PARAM_LONG(n_cols)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->eye(n_rows, n_cols);
|
2019-06-12 03:11:27 +00:00
|
|
|
RETVAL_THIS();
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, shedRow, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long row_idx;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(row_idx)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->shed_row(row_idx);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, shedCol, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long col_idx;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(col_idx)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->shed_col(col_idx);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, shedRows, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long first_row, last_row;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(2, 2)
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(first_row)
|
|
|
|
Z_PARAM_LONG(last_row)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->shed_rows(first_row, last_row);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_METHOD(resizable_matrix, shedCols, T, T1)
|
|
|
|
{
|
2019-06-02 15:04:39 +00:00
|
|
|
zend_long first_col, last_col;
|
|
|
|
ZEND_PARSE_PARAMETERS_START(2, 2)
|
2019-06-07 16:07:11 +00:00
|
|
|
Z_PARAM_LONG(first_col)
|
|
|
|
Z_PARAM_LONG(last_col)
|
2019-06-02 15:04:39 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
|
|
|
|
|
|
|
auto native = THIS_NATIVE;
|
|
|
|
native->shed_rows(first_col, last_col);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename T1>
|
|
|
|
PHP_ARMA_START_ME(resizable_matrix, T, T1)
|
|
|
|
PHP_ARMA_ME(reshape, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(resize, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(setSize, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(zeros, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(eye, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(shedRow, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(shedCol, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(shedRows, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_ME(shedCols, ZEND_ACC_PUBLIC)
|
|
|
|
PHP_ARMA_END_ME();
|
|
|
|
|
|
|
|
void resizable_matrix_init()
|
|
|
|
{
|
2019-06-06 15:56:10 +00:00
|
|
|
resizable_matrix_ce = interface_register<resizable_matrix_php_name>(resizable_ce, matrix_ce);
|
2019-05-25 18:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PHP_ARMA_INSTANTIATE(resizable_matrix, mat);
|
|
|
|
}
|