From 665145a40e6ef4a13923538f804cfadaf4b20bb4 Mon Sep 17 00:00:00 2001 From: CismonX Date: Tue, 8 Oct 2019 23:44:28 +0800 Subject: [PATCH] Add `toMat()`. Update tests. --- src/subview_mat.cc | 9 +++++++++ src/subview_mat.hh | 2 ++ stubs/SvMat.php | 6 +++++- tests/005-print.phpt | 2 -- tests/013-foreach-transform-replace.phpt | 2 -- tests/016-debug-info.phpt | 2 -- tests/017-set-real-imag.phpt | 2 -- tests/018-diagview.phpt | 2 -- tests/020-copy-size.phpt | 2 +- tests/021-to-mat.phpt | 24 ++++++++++++++++++++++++ 10 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 tests/021-to-mat.phpt diff --git a/src/subview_mat.cc b/src/subview_mat.cc index 953cdd7..90508c6 100644 --- a/src/subview_mat.cc +++ b/src/subview_mat.cc @@ -6,6 +6,7 @@ #include "subview_mat.hh" #include "subview.hh" +#include "mat.hh" #include "base.hh" #include "dense.hh" #include "matrix.hh" @@ -16,8 +17,16 @@ namespace php_arma { + template + PHP_ARMA_METHOD(subview_mat, toMat, T) + { + auto native = THIS_NATIVE; + RETVAL_OBJ(mat::create(*native)); + } + template PHP_ARMA_START_ME(subview_mat, T) + PHP_ARMA_ME(toMat, ZEND_ACC_PUBLIC) PHP_ARMA_END_ME(); template diff --git a/src/subview_mat.hh b/src/subview_mat.hh index eb8bb74..ecab4f5 100644 --- a/src/subview_mat.hh +++ b/src/subview_mat.hh @@ -31,6 +31,8 @@ namespace php_arma private: PHP_ARMA_COMMON_DECLARE(); + static PHP_FUNCTION(toMat); + static void ce_init(zend_class_entry*); }; diff --git a/stubs/SvMat.php b/stubs/SvMat.php index 56bd127..eab913b 100644 --- a/stubs/SvMat.php +++ b/stubs/SvMat.php @@ -9,5 +9,9 @@ namespace Arma; */ abstract class SvMat implements Internal\DenseNonResizableMatrix, Internal\Subview { - + /** + * Create a new matrix with elements copied from this matrix subview. + * @return Mat + */ + function toMat() {} } diff --git a/tests/005-print.phpt b/tests/005-print.phpt index dd67621..b152a30 100644 --- a/tests/005-print.phpt +++ b/tests/005-print.phpt @@ -8,8 +8,6 @@ is_php_arma_loaded(); --FILE-- print(); $mat->rawPrint(); diff --git a/tests/013-foreach-transform-replace.phpt b/tests/013-foreach-transform-replace.phpt index 8f6e11a..3bdfc48 100644 --- a/tests/013-foreach-transform-replace.phpt +++ b/tests/013-foreach-transform-replace.phpt @@ -8,8 +8,6 @@ is_php_arma_loaded(); --FILE-- rawPrint(); $mat->forEach(function (Arma\MapVal $elem) { diff --git a/tests/016-debug-info.phpt b/tests/016-debug-info.phpt index 96dcb3f..bcb52b9 100644 --- a/tests/016-debug-info.phpt +++ b/tests/016-debug-info.phpt @@ -8,8 +8,6 @@ is_php_arma_loaded(); --FILE-- setImag($dmat); diff --git a/tests/018-diagview.phpt b/tests/018-diagview.phpt index fcb40a3..85f2634 100644 --- a/tests/018-diagview.phpt +++ b/tests/018-diagview.phpt @@ -8,8 +8,6 @@ is_php_arma_loaded(); --FILE-- diag(); diff --git a/tests/020-copy-size.phpt b/tests/020-copy-size.phpt index 836df3c..89e257e 100644 --- a/tests/020-copy-size.phpt +++ b/tests/020-copy-size.phpt @@ -1,5 +1,5 @@ --TEST-- -Test for method `copySize()` +Test for method `copySize()`. --SKIPIF-- +--FILE-- +submat(1, 1, 2, 2); +$mat1 = $submat->toMat(); +$mat1->at(0, 0)->setTo(1); +$mat->rawPrint(); +$mat1->rawPrint(); + +?> +--EXPECT-- +0 0 0 +0 0 0 +0 0 0 +1 0 +0 0