Implement `SvMat`, add test cases.
This commit is contained in:
parent
1de7c70361
commit
ca2409769d
|
@ -107,34 +107,22 @@ namespace php_arma
|
|||
RETVAL_OBJ(zobj);
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
PHP_ARMA_METHOD(dense_matrix, submat, T, T1)
|
||||
template <typename T, typename ChildT>
|
||||
PHP_ARMA_METHOD(dense_matrix, submat, T, ChildT)
|
||||
{
|
||||
|
||||
}
|
||||
zend_long first_row, first_col, last_row, last_col;
|
||||
ZEND_PARSE_PARAMETERS_START(4, 4)
|
||||
Z_PARAM_LONG(first_row)
|
||||
Z_PARAM_LONG(first_col)
|
||||
Z_PARAM_LONG(last_row)
|
||||
Z_PARAM_LONG(last_col)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
template <typename T, typename T1>
|
||||
PHP_ARMA_METHOD(dense_matrix, headCols, T, T1)
|
||||
{
|
||||
|
||||
}
|
||||
using ret_t = typename ChildT::subview_t;
|
||||
|
||||
template <typename T, typename T1>
|
||||
PHP_ARMA_METHOD(dense_matrix, headRows, T, T1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
PHP_ARMA_METHOD(dense_matrix, tailCols, T, T1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
PHP_ARMA_METHOD(dense_matrix, tailRows, T, T1)
|
||||
{
|
||||
|
||||
auto native = THIS_NATIVE;
|
||||
auto zobj = ret_t::create(std::move(native->submat(first_row, first_col, last_row, last_col)));
|
||||
RETVAL_OBJ(zobj);
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
|
@ -228,10 +216,6 @@ namespace php_arma
|
|||
PHP_ARMA_ME(cols, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(rows, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(submat, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(headCols, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(headRows, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(tailCols, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(tailRows, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(diag, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(eachRow, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(eachCol, ZEND_ACC_PUBLIC)
|
||||
|
|
|
@ -26,10 +26,6 @@ namespace php_arma
|
|||
static PHP_FUNCTION(cols);
|
||||
static PHP_FUNCTION(rows);
|
||||
static PHP_FUNCTION(submat);
|
||||
static PHP_FUNCTION(headCols);
|
||||
static PHP_FUNCTION(headRows);
|
||||
static PHP_FUNCTION(tailCols);
|
||||
static PHP_FUNCTION(tailRows);
|
||||
static PHP_FUNCTION(diag);
|
||||
static PHP_FUNCTION(eachRow);
|
||||
static PHP_FUNCTION(eachCol);
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
#include "dense_matrix.hh"
|
||||
#include "resizable_matrix.hh"
|
||||
#include "mat.hh"
|
||||
#include "subview_mat.hh"
|
||||
|
||||
#include <armadillo>
|
||||
|
||||
namespace php_arma
|
||||
{
|
||||
|
@ -105,6 +108,66 @@ namespace php_arma
|
|||
RETVAL_BOOL(native->is_sorted(sort_direction::native(sort_direction), dim));
|
||||
}
|
||||
|
||||
template <typename T, typename ChildT>
|
||||
PHP_ARMA_METHOD(dense_resizable_matrix, headCols, T, ChildT)
|
||||
{
|
||||
zend_long n_cols;
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_LONG(n_cols)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
using ret_t = typename ChildT::subview_t;
|
||||
|
||||
auto native = THIS_NATIVE;
|
||||
auto zobj = ret_t::create(std::move(native->head_cols(n_cols)));
|
||||
RETVAL_OBJ(zobj);
|
||||
}
|
||||
|
||||
template <typename T, typename ChildT>
|
||||
PHP_ARMA_METHOD(dense_resizable_matrix, headRows, T, ChildT)
|
||||
{
|
||||
zend_long n_rows;
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_LONG(n_rows)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
using ret_t = typename ChildT::subview_t;
|
||||
|
||||
auto native = THIS_NATIVE;
|
||||
auto zobj = ret_t::create(std::move(native->head_rows(n_rows)));
|
||||
RETVAL_OBJ(zobj);
|
||||
}
|
||||
|
||||
template <typename T, typename ChildT>
|
||||
PHP_ARMA_METHOD(dense_resizable_matrix, tailCols, T, ChildT)
|
||||
{
|
||||
zend_long n_cols;
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_LONG(n_cols)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
using ret_t = typename ChildT::subview_t;
|
||||
|
||||
auto native = THIS_NATIVE;
|
||||
auto zobj = ret_t::create(std::move(native->tail_cols(n_cols)));
|
||||
RETVAL_OBJ(zobj);
|
||||
}
|
||||
|
||||
template <typename T, typename ChildT>
|
||||
PHP_ARMA_METHOD(dense_resizable_matrix, tailRows, T, ChildT)
|
||||
{
|
||||
zend_long n_rows;
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_LONG(n_rows)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
using ret_t = typename ChildT::subview_t;
|
||||
|
||||
auto native = THIS_NATIVE;
|
||||
auto zobj = ret_t::create(std::move(native->tail_rows(n_rows)));
|
||||
RETVAL_OBJ(zobj);
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
PHP_ARMA_START_ME(dense_resizable_matrix, T, T1)
|
||||
PHP_ARMA_ME(ones, ZEND_ACC_PUBLIC)
|
||||
|
@ -114,6 +177,10 @@ namespace php_arma
|
|||
PHP_ARMA_ME(insertCols, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(swap, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(isSorted, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(headCols, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(headRows, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(tailCols, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(tailRows, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_END_ME();
|
||||
|
||||
void dense_resizable_matrix_init()
|
||||
|
|
|
@ -26,6 +26,10 @@ namespace php_arma
|
|||
static PHP_FUNCTION(insertCols);
|
||||
static PHP_FUNCTION(swap);
|
||||
static PHP_FUNCTION(isSorted);
|
||||
static PHP_FUNCTION(headCols);
|
||||
static PHP_FUNCTION(headRows);
|
||||
static PHP_FUNCTION(tailCols);
|
||||
static PHP_FUNCTION(tailRows);
|
||||
};
|
||||
|
||||
void dense_resizable_matrix_init();
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace php_arma
|
|||
object_handlers_init(&handlers);
|
||||
handlers.offset = sizeof(native_t);
|
||||
handlers.clone_obj = nullptr;
|
||||
handlers.dtor_obj = object_destroy<native_t>;
|
||||
handlers.count_elements = base<T, subview_mat>::count_elements;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,38 +80,6 @@ interface DenseMatrix extends Dense, Matrix
|
|||
*/
|
||||
function submat($first_row, $first_col, $last_row, $last_col);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_cols
|
||||
* @return SvMat
|
||||
*/
|
||||
function headCols($n_cols);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_rows
|
||||
* @return SvMat
|
||||
*/
|
||||
function headRows($n_rows);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_cols
|
||||
* @return SvMat
|
||||
*/
|
||||
function tailCols($n_cols);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_rows
|
||||
* @return SvMat
|
||||
*/
|
||||
function tailRows($n_rows);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Arma\Internal;
|
||||
|
||||
use Arma\SortDirection;
|
||||
use Arma\SvMat;
|
||||
|
||||
/**
|
||||
* Interface for resizable (non-subview) dense matrices.
|
||||
|
@ -92,4 +93,38 @@ interface DenseResizableMatrix extends DenseMatrix, ResizableMatrix
|
|||
* @return bool
|
||||
*/
|
||||
function isSorted($sort_direction = SortDirection::ASCEND, $dim = 0);
|
||||
|
||||
// Subview
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_cols
|
||||
* @return SvMat
|
||||
*/
|
||||
function headCols($n_cols);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_rows
|
||||
* @return SvMat
|
||||
*/
|
||||
function headRows($n_rows);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_cols
|
||||
* @return SvMat
|
||||
*/
|
||||
function tailCols($n_cols);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $n_rows
|
||||
* @return SvMat
|
||||
*/
|
||||
function tailRows($n_rows);
|
||||
}
|
||||
|
|
|
@ -43,4 +43,4 @@ interface ResizableVector extends Resizable, Vector
|
|||
* @return bool
|
||||
*/
|
||||
function inRange($idx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
--TEST--
|
||||
Test for `SvMat`.
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once 'includes/loaded.php';
|
||||
is_php_arma_loaded();
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'includes/assert.php';
|
||||
|
||||
$mat = Arma\IMat::init(3, 3, Arma\Fill::RANDN);
|
||||
$sub_cols = $mat->cols(1, 2);
|
||||
$sub_rows = $mat->rows(1, 2);
|
||||
$submat = $mat->submat(1, 1, 2, 2);
|
||||
$sub_cols->at(0, 1)->setTo(PHP_INT_MAX);
|
||||
$sub_rows->at(0, 1)->setTo(PHP_INT_MAX);
|
||||
$submat->at(0, 1)->setTo(PHP_INT_MAX);
|
||||
|
||||
batch_assert('`SvMat`',
|
||||
[$mat->at(0, 1)->val(), $sub_cols->at(0, 0)->val()],
|
||||
[$mat->at(1, 0)->val(), $sub_rows->at(0, 0)->val()],
|
||||
[$mat->at(2, 2)->val(), $submat->at(1, 1)->val()],
|
||||
[PHP_INT_MAX, $mat->at(0, 2)->val()],
|
||||
[PHP_INT_MAX, $mat->at(1, 1)->val()],
|
||||
[PHP_INT_MAX, $mat->at(1, 2)->val()]
|
||||
);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
Reference in New Issue