From c3c900db48b7c683899266f058d029e4873f2628 Mon Sep 17 00:00:00 2001 From: CismonX Date: Thu, 4 Apr 2019 16:07:37 +0800 Subject: [PATCH] update --- src/constants.cc | 10 ++++-- src/constants.hh | 10 ++++++ src/php_arma.hh | 4 +-- stubs/FileType.php | 12 ++++++++ stubs/HDF5Opts.php | 28 +++++++++++++++++ stubs/internal/Base.php | 10 +++--- stubs/internal/Dense.php | 17 ++++++----- stubs/internal/DenseMatrix.php | 34 ++++++++++++--------- stubs/internal/DenseResizableMatrix.php | 4 ++- stubs/internal/DenseResizableVector.php | 4 ++- stubs/internal/DenseVector.php | 6 ++-- stubs/internal/Resizable.php | 14 +++++---- stubs/internal/Scalar.php | 6 ++-- stubs/internal/SparseMatrix.php | 23 ++++++++------ stubs/internal/SparseNonResizableMatrix.php | 6 ++-- stubs/internal/SparseResizableMatrix.php | 11 +++++-- stubs/internal/SparseVector.php | 6 ++-- tests/000-constants.phpt | 32 +++++++++++-------- tests/001-complex.phpt | 6 ++++ 19 files changed, 173 insertions(+), 70 deletions(-) create mode 100644 stubs/HDF5Opts.php diff --git a/src/constants.cc b/src/constants.cc index 5961316..fd06641 100644 --- a/src/constants.cc +++ b/src/constants.cc @@ -15,7 +15,7 @@ namespace php_arma zend_always_inline void const_declare(zend_class_entry *ce, Ts... constants) { - for (auto &&[name, val] : { constants... }) { + for (auto [name, val] : { constants... }) { zend_declare_class_constant_long(ce, name, strlen(name), val); } } @@ -38,7 +38,8 @@ namespace php_arma std::tuple("RAW_ASCII", file_type::raw_ascii), std::tuple("CSV_ASCII", file_type::csv_ascii), std::tuple("COORD_ASCII", file_type::coord_ascii), - std::tuple("PGM_BINARY", file_type::pgm_binary) + std::tuple("PGM_BINARY", file_type::pgm_binary), + std::tuple("HDF5_BINARY", file_type::hdf5_binary) ); const_declare(sort_direction_ce = abstract_class_register(), std::tuple("ASCEND", sort_direction::ascend), @@ -46,5 +47,10 @@ namespace php_arma std::tuple("STRICT_ASCEND", sort_direction::strict_ascend), std::tuple("STRICT_DESCEND", sort_direction::strict_descend) ); + const_declare(hdf5_opts_ce = abstract_class_register(), + std::tuple("TRANS", hdf5_opts::trans), + std::tuple("APPEND", hdf5_opts::append), + std::tuple("REPLACE", hdf5_opts::replace) + ); } } diff --git a/src/constants.hh b/src/constants.hh index 3271666..faa125e 100644 --- a/src/constants.hh +++ b/src/constants.hh @@ -31,6 +31,7 @@ namespace php_arma static constexpr auto csv_ascii = 5; static constexpr auto coord_ascii = 6; static constexpr auto pgm_binary = 7; + static constexpr auto hdf5_binary = 8; }; struct sort_direction @@ -41,15 +42,24 @@ namespace php_arma static constexpr auto strict_descend = 3; }; + struct hdf5_opts + { + static constexpr auto trans = 1u << 0; + static constexpr auto append = 1u << 1; + static constexpr auto replace = 1u << 2; + }; + void constants_init(); constexpr const char fill_php_name[] = "Fill"; constexpr const char file_type_php_name[] = "FileType"; constexpr const char sort_direction_php_name[] = "SortDirection"; + constexpr const char hdf5_opts_php_name[] = "HDF5Opts"; inline zend_class_entry *fill_ce; inline zend_class_entry *file_type_ce; inline zend_class_entry *sort_direction_ce; + inline zend_class_entry *hdf5_opts_ce; } #endif //!PHP_ARMA_CONSTANTS_HH diff --git a/src/php_arma.hh b/src/php_arma.hh index 994bb86..16422a1 100644 --- a/src/php_arma.hh +++ b/src/php_arma.hh @@ -148,8 +148,8 @@ namespace php_arma zend_always_inline zend_class_entry *class_register(zend_class_entry *parent, const zend_function_entry *methods) { - using std::placeholders::_1; - return ce_init(methods, std::bind(zend_register_internal_class_ex, _1, parent)); + auto init_func = std::bind(zend_register_internal_class_ex, std::placeholders::_1, parent); + return ce_init(methods, init_func); } template diff --git a/stubs/FileType.php b/stubs/FileType.php index 40080f5..91da654 100644 --- a/stubs/FileType.php +++ b/stubs/FileType.php @@ -68,4 +68,16 @@ abstract class FileType * in the [0,255] interval, otherwise the resulting image may not display correctly. */ const PGM_BINARY = 7; + + /** + * Numerical data stored in portable HDF5 binary format. + * + * For saving, the default dataset name within the HDF5 file is "dataset". For loading, the order of + * operations is: (1) try loading a dataset named "dataset", (2) try loading a dataset named "value", + * (3) try loading the first available dataset. + * + * To explicitly control the dataset name, specify it by passing an array with the following format to the + * first argument: ['filename' => string, 'dataset' => string(default='dataset'), 'settings' => int(default=0)] + */ + const HDF5_BINARY = 8; } diff --git a/stubs/HDF5Opts.php b/stubs/HDF5Opts.php new file mode 100644 index 0000000..5e09442 --- /dev/null +++ b/stubs/HDF5Opts.php @@ -0,0 +1,28 @@ + void + * @param callable $action (SvRow) -> void * @return void */ function eachRow($action); @@ -127,7 +133,7 @@ interface DenseMatrix extends Dense, Matrix /** * Apply a callback function to each column of the matrix. * - * @param callable $action (\Arma\SvCol) -> void + * @param callable $action (SvCol) -> void * @return void */ function eachCol($action); diff --git a/stubs/internal/DenseResizableMatrix.php b/stubs/internal/DenseResizableMatrix.php index af91c93..d98ce62 100644 --- a/stubs/internal/DenseResizableMatrix.php +++ b/stubs/internal/DenseResizableMatrix.php @@ -2,6 +2,8 @@ namespace Arma\Internal; +use Arma\SortDirection; + /** * Interface for resizable (non-subview) dense matrices. * @@ -89,5 +91,5 @@ interface DenseResizableMatrix extends DenseMatrix, ResizableMatrix * @param int $dim[optional] * @return bool */ - function isSorted($sort_direction = \Arma\SortDirection::ASCEND, $dim = 0); + function isSorted($sort_direction = SortDirection::ASCEND, $dim = 0); } diff --git a/stubs/internal/DenseResizableVector.php b/stubs/internal/DenseResizableVector.php index 4adc28b..724d9c2 100644 --- a/stubs/internal/DenseResizableVector.php +++ b/stubs/internal/DenseResizableVector.php @@ -2,6 +2,8 @@ namespace Arma\Internal; +use Arma\SortDirection; + /** * Interface for resizable (non-subview) dense vectors. * @@ -59,5 +61,5 @@ interface DenseResizableVector extends DenseVector, ResizableVector * @param int $sort_direction[optional] * @return bool */ - function isSorted($sort_direction = \Arma\SortDirection::ASCEND); + function isSorted($sort_direction = SortDirection::ASCEND); } diff --git a/stubs/internal/DenseVector.php b/stubs/internal/DenseVector.php index 45975c4..7503ea0 100644 --- a/stubs/internal/DenseVector.php +++ b/stubs/internal/DenseVector.php @@ -2,6 +2,8 @@ namespace Arma\Internal; +use Arma\MapVal; + /** * Interface for vectors with a Dense Layout (Row and Col). * @@ -15,7 +17,7 @@ interface DenseVector extends Dense, Vector * {@inheritdoc} * * @param int $idx - * @return \Arma\MapVal + * @return MapVal */ function __invoke($idx); @@ -23,7 +25,7 @@ interface DenseVector extends Dense, Vector * {@inheritdoc} * * @param int $idx - * @return \Arma\MapVal + * @return MapVal */ function at($idx); } diff --git a/stubs/internal/Resizable.php b/stubs/internal/Resizable.php index 56a5806..ce164e9 100644 --- a/stubs/internal/Resizable.php +++ b/stubs/internal/Resizable.php @@ -2,6 +2,8 @@ namespace Arma\Internal; +use Arma\FileType; + /** * Interface for resizable objects (non-subview objects) * @@ -55,20 +57,20 @@ interface Resizable /** * Store data in a file or stream (the stream must be opened in binary mode). * - * @param resource|string $dest - * @param int $file_type[optional] + * @param resource|string|array $dest + * @param int $file_type[optional] * @return bool */ - function save($dest, $file_type = \Arma\FileType::ARMA_BINARY); + function save($dest, $file_type = FileType::ARMA_BINARY); /** * Retrieve data from a file or stream (the stream must be opened in binary mode). * * On failure, the object is reset so that it has no elements. * - * @param resource|string $from - * @param int $file_type[optional] + * @param resource|string|array $from + * @param int $file_type[optional] * @return bool */ - function load($from, $file_type = \Arma\FileType::AUTO_DETECT); + function load($from, $file_type = FileType::AUTO_DETECT); } diff --git a/stubs/internal/Scalar.php b/stubs/internal/Scalar.php index 11264ee..333f8cd 100644 --- a/stubs/internal/Scalar.php +++ b/stubs/internal/Scalar.php @@ -2,6 +2,8 @@ namespace Arma\Internal; +use Arma\Complex; + /** * Interface for objects which wraps a single scalar value. * @@ -12,14 +14,14 @@ interface Scalar /** * Return a copy of the representing scalar value of this object. * - * @return number|\Arma\Complex + * @return number|Complex */ function val(); /** * Set the representing value to the specified new value. * - * @param number|\Arma\Complex $value + * @param number|Complex $value * @return void */ function setTo($value); diff --git a/stubs/internal/SparseMatrix.php b/stubs/internal/SparseMatrix.php index 1b4d11d..1824bfb 100644 --- a/stubs/internal/SparseMatrix.php +++ b/stubs/internal/SparseMatrix.php @@ -2,6 +2,9 @@ namespace Arma\Internal; +use Arma\SpSvMat; +use Arma\SpDiagView; + /** * Interface for sparse matrices. * @@ -15,7 +18,7 @@ interface SparseMatrix extends Sparse, Matrix * {@inheritdoc} * * @param int $col_number - * @return \Arma\SpSvMat + * @return SpSvMat */ function col($col_number); @@ -23,7 +26,7 @@ interface SparseMatrix extends Sparse, Matrix * {@inheritdoc} * * @param int $row_number - * @return \Arma\SpSvMat + * @return SpSvMat */ function row($row_number); @@ -32,7 +35,7 @@ interface SparseMatrix extends Sparse, Matrix * * @param int $first_col * @param int $last_col - * @return \Arma\SpSvMat + * @return SpSvMat */ function cols($first_col, $last_col); @@ -41,7 +44,7 @@ interface SparseMatrix extends Sparse, Matrix * * @param int $first_row * @param int $last_row - * @return \Arma\SpSvMat + * @return SpSvMat */ function rows($first_row, $last_row); @@ -52,7 +55,7 @@ interface SparseMatrix extends Sparse, Matrix * @param int $first_col * @param int $last_row * @param int $last_col - * @return \Arma\SpSvMat + * @return SpSvMat */ function submat($first_row, $first_col, $last_row, $last_col); @@ -60,7 +63,7 @@ interface SparseMatrix extends Sparse, Matrix * {@inheritdoc} * * @param int $n_cols - * @return \Arma\SpSvMat + * @return SpSvMat */ function head_cols($n_cols); @@ -68,7 +71,7 @@ interface SparseMatrix extends Sparse, Matrix * {@inheritdoc} * * @param int $n_rows - * @return \Arma\SpSvMat + * @return SpSvMat */ function head_rows($n_rows); @@ -76,7 +79,7 @@ interface SparseMatrix extends Sparse, Matrix * {@inheritdoc} * * @param int $n_cols - * @return \Arma\SpSvMat + * @return SpSvMat */ function tail_cols($n_cols); @@ -84,7 +87,7 @@ interface SparseMatrix extends Sparse, Matrix * {@inheritdoc} * * @param int $n_rows - * @return \Arma\SpSvMat + * @return SpSvMat */ function tail_rows($n_rows); @@ -92,7 +95,7 @@ interface SparseMatrix extends Sparse, Matrix * {@inheritdoc} * * @param int $k[optional] - * @return \Arma\SpDiagView + * @return SpDiagView */ function diag($k = 0); } diff --git a/stubs/internal/SparseNonResizableMatrix.php b/stubs/internal/SparseNonResizableMatrix.php index 4c5d3ae..7d2d544 100644 --- a/stubs/internal/SparseNonResizableMatrix.php +++ b/stubs/internal/SparseNonResizableMatrix.php @@ -2,6 +2,8 @@ namespace Arma\Internal; +use Arma\SpSvMapVal; + /** * Interface for resizable (non-subview) sparse matrices. * @@ -16,7 +18,7 @@ interface SparseNonResizableMatrix extends SparseMatrix, NonResizableMatrix * * @param int $i * @param int $j[optional] - * @return \Arma\SpSvMapVal + * @return SpSvMapVal */ function __invoke($i, $j); @@ -25,7 +27,7 @@ interface SparseNonResizableMatrix extends SparseMatrix, NonResizableMatrix * * @param int $i * @param int $j[optional] - * @return \Arma\SpSvMapVal + * @return SpSvMapVal */ function at($i, $j); } diff --git a/stubs/internal/SparseResizableMatrix.php b/stubs/internal/SparseResizableMatrix.php index 5060b9b..241c6c9 100644 --- a/stubs/internal/SparseResizableMatrix.php +++ b/stubs/internal/SparseResizableMatrix.php @@ -2,6 +2,13 @@ namespace Arma\Internal; +use Arma\SpMapVal; + +/** + * Interface for resizable (non-subview) sparse matrices. + * + * @package Arma\Internal + */ interface SparseResizableMatrix extends SparseMatrix, ResizableMatrix { // Subview @@ -11,7 +18,7 @@ interface SparseResizableMatrix extends SparseMatrix, ResizableMatrix * * @param int $i * @param int $j[optional] - * @return \Arma\SpMapVal + * @return SpMapVal */ function __invoke($i, $j); @@ -20,7 +27,7 @@ interface SparseResizableMatrix extends SparseMatrix, ResizableMatrix * * @param int $i * @param int $j[optional] - * @return \Arma\SpMapVal + * @return SpMapVal */ function at($i, $j); } diff --git a/stubs/internal/SparseVector.php b/stubs/internal/SparseVector.php index 8bffea3..9f075f3 100644 --- a/stubs/internal/SparseVector.php +++ b/stubs/internal/SparseVector.php @@ -2,6 +2,8 @@ namespace Arma\Internal; +use Arma\SpMapVal; + interface SparseVector extends Sparse, Vector { /// Subview @@ -10,7 +12,7 @@ interface SparseVector extends Sparse, Vector * {@inheritdoc} * * @param int $idx - * @return \Arma\SpMapVal + * @return SpMapVal */ function __invoke($idx); @@ -18,7 +20,7 @@ interface SparseVector extends Sparse, Vector * {@inheritdoc} * * @param int $idx - * @return \Arma\SpMapVal + * @return SpMapVal */ function at($idx); } diff --git a/tests/000-constants.phpt b/tests/000-constants.phpt index c9d7002..a052664 100644 --- a/tests/000-constants.phpt +++ b/tests/000-constants.phpt @@ -4,25 +4,31 @@ Test for constants. --FILE-- > 0, HDF5Opts::APPEND >> 1, HDF5Opts::REPLACE >> 2]; + batch_assert('constants', - [range(0, 5), $fill], - [range(0, 7), $file_type], - [range(0, 3), $sort_direction] + [range(0, 5), $fill], + [range(0, 8), $file_type], + [range(0, 3), $sort_direction], + [array_fill(0, 3, 1), $hdf5_opts] ); + ?> --EXPECT-- diff --git a/tests/001-complex.phpt b/tests/001-complex.phpt index 388c392..bbc3899 100644 --- a/tests/001-complex.phpt +++ b/tests/001-complex.phpt @@ -4,17 +4,23 @@ Test for `Arma\Complex`. --FILE-- real], [2.4, $cx_double->imag] ); + $cx_double->real *= 1.1; $cx_double->imag *= 1.3; + batch_assert('Arma\\Complex', [1.2 * 1.1, $cx_double->real], [2.4 * 1.3, $cx_double->imag] ); + ?> --EXPECT--