Refactor code.
This commit is contained in:
parent
aaf11592c7
commit
6eb263b763
|
@ -22,7 +22,8 @@ before_install:
|
|||
install:
|
||||
- sudo apt-get install -qq g++-7 cmake
|
||||
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90
|
||||
- sudo apt-get install -qq libopenblas-dev liblapack-dev libarpack2-dev libsuperlu-dev
|
||||
- sudo apt-get install -qq libopenblas-dev liblapack-dev libarpack2-dev
|
||||
- sudo apt-get install -qq libsuperlu-dev libhdf5-dev
|
||||
- pushd armadillo-${ARMA_VERSION} && cmake . && make && sudo make install && popd
|
||||
|
||||
script:
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "mat.hh"
|
||||
|
||||
#include <armadillo>
|
||||
#include <zend_interfaces.h>
|
||||
|
||||
namespace php_arma
|
||||
{
|
||||
|
@ -159,7 +160,7 @@ namespace php_arma
|
|||
|
||||
void base_init()
|
||||
{
|
||||
base_ce = interface_register<base_php_name>();
|
||||
base_ce = interface_register<base_php_name>(zend_ce_countable);
|
||||
}
|
||||
|
||||
PHP_ARMA_INSTANTIATE(base, mat);
|
||||
|
|
|
@ -21,8 +21,7 @@ namespace php_arma
|
|||
zend_always_inline
|
||||
static int count_elements(zval *zv, zend_long *count)
|
||||
{
|
||||
auto zobj = Z_OBJ_P(zv);
|
||||
*count = to_native_object<native_t>(zobj)->n_elem;
|
||||
*count = Z_NATIVE_OBJ_P(zv)->n_elem;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,32 @@
|
|||
|
||||
namespace php_arma
|
||||
{
|
||||
arma::file_type file_type::native(zend_long val)
|
||||
{
|
||||
switch (val) {
|
||||
case file_type::auto_detect:
|
||||
return arma::file_type::auto_detect;
|
||||
case file_type::arma_binary:
|
||||
return arma::file_type::arma_binary;
|
||||
case file_type::arma_ascii:
|
||||
return arma::file_type::arma_ascii;
|
||||
case file_type::raw_binary:
|
||||
return arma::file_type::raw_binary;
|
||||
case file_type::csv_ascii:
|
||||
return arma::file_type::csv_ascii;
|
||||
case file_type::coord_ascii:
|
||||
return arma::file_type::coord_ascii;
|
||||
case file_type::pgm_binary:
|
||||
return arma::file_type::pgm_binary;
|
||||
#ifdef ARMA_USE_HDF5
|
||||
case file_type::hdf5_binary:
|
||||
return arma::file_type::hdf5_binary;
|
||||
#endif // ARMA_USE_HDF5
|
||||
default:
|
||||
return arma::file_type::file_type_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
zend_always_inline
|
||||
void const_declare(zend_class_entry *ce, Ts&&... constants)
|
||||
|
@ -46,11 +72,14 @@ namespace php_arma
|
|||
std::tuple("STRICT_ASCEND", sort_direction::strict_ascend),
|
||||
std::tuple("STRICT_DESCEND", sort_direction::strict_descend)
|
||||
);
|
||||
#ifdef ARMA_USE_HDF5
|
||||
const_declare(hdf5_opts_ce = abstract_class_register<hdf5_opts_php_name>(),
|
||||
std::tuple("NONE", hdf5_opts::none),
|
||||
std::tuple("TRANS", hdf5_opts::trans),
|
||||
std::tuple("APPEND", hdf5_opts::append),
|
||||
std::tuple("REPLACE", hdf5_opts::replace)
|
||||
);
|
||||
#endif // ARMA_USE_HDF5
|
||||
const_declare(features_ce = abstract_class_register<features_php_name>(),
|
||||
std::tuple("OPERATORS", features::operators)
|
||||
);
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "php_arma.hh"
|
||||
|
||||
#include <armadillo>
|
||||
|
||||
namespace php_arma
|
||||
{
|
||||
struct fill
|
||||
|
@ -21,6 +23,9 @@ namespace php_arma
|
|||
static constexpr auto randn = 5;
|
||||
};
|
||||
|
||||
constexpr const char fill_php_name[] = "Fill";
|
||||
inline zend_class_entry *fill_ce;
|
||||
|
||||
struct file_type
|
||||
{
|
||||
static constexpr auto auto_detect = 0;
|
||||
|
@ -32,8 +37,13 @@ namespace php_arma
|
|||
static constexpr auto coord_ascii = 6;
|
||||
static constexpr auto pgm_binary = 7;
|
||||
static constexpr auto hdf5_binary = 8;
|
||||
|
||||
static arma::file_type native(zend_long);
|
||||
};
|
||||
|
||||
constexpr const char file_type_php_name[] = "FileType";
|
||||
inline zend_class_entry *file_type_ce;
|
||||
|
||||
struct sort_direction
|
||||
{
|
||||
static constexpr auto ascend = 0;
|
||||
|
@ -42,13 +52,22 @@ namespace php_arma
|
|||
static constexpr auto strict_descend = 3;
|
||||
};
|
||||
|
||||
constexpr const char sort_direction_php_name[] = "SortDirection";
|
||||
inline zend_class_entry *sort_direction_ce;
|
||||
|
||||
#ifdef ARMA_USE_HDF5
|
||||
struct hdf5_opts
|
||||
{
|
||||
static constexpr auto none = 0u;
|
||||
static constexpr auto trans = 1u << 0;
|
||||
static constexpr auto append = 1u << 1;
|
||||
static constexpr auto replace = 1u << 2;
|
||||
};
|
||||
|
||||
constexpr const char hdf5_opts_php_name[] = "HDF5Opts";
|
||||
inline zend_class_entry *hdf5_opts_ce;
|
||||
#endif // ARMA_USE_HDF5
|
||||
|
||||
struct features
|
||||
{
|
||||
#ifdef PHP_ARMA_OPERATORS
|
||||
|
@ -56,21 +75,17 @@ namespace php_arma
|
|||
#else
|
||||
static constexpr auto operators = false;
|
||||
#endif // PHP_ARMA_OPERATORS
|
||||
#ifdef ARMA_USE_HDF5
|
||||
static constexpr auto hdf5 = true;
|
||||
#else
|
||||
static constexpr auto hdf5 = false;
|
||||
#endif // ARMA_USE_HDF5
|
||||
};
|
||||
|
||||
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";
|
||||
constexpr const char features_php_name[] = "Features";
|
||||
|
||||
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;
|
||||
constexpr const char features_php_name[] = "Features";
|
||||
inline zend_class_entry *features_ce;
|
||||
|
||||
void constants_init();
|
||||
}
|
||||
|
||||
#endif //!PHP_ARMA_CONSTANTS_HH
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//
|
||||
|
||||
#ifndef PHP_ARMA_DENSE_RESIZABLE_MATRIX_HH
|
||||
#define PHP_ARMA_DENSE_RESIZBALE_MATRIX_HH
|
||||
#define PHP_ARMA_DENSE_RESIZABLE_MATRIX_HH
|
||||
|
||||
#include "php_arma.hh"
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ namespace php_arma
|
|||
T mapval<T, IsSparse, B>::get_val(zend_object *zobj)
|
||||
{
|
||||
if constexpr (IsSparse) {
|
||||
return *to_native_object<native_t>(zobj);
|
||||
return *ZOBJ_NATIVE(zobj);
|
||||
} else {
|
||||
return **to_native_object<native_t>(zobj);
|
||||
return **ZOBJ_NATIVE(zobj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,8 @@
|
|||
// Forward declarations.
|
||||
namespace arma
|
||||
{
|
||||
template <typename T>
|
||||
class SpMat_MapMat_val;
|
||||
|
||||
template <typename T>
|
||||
class SpSubview_MapMat_val;
|
||||
template <typename T> class SpMat_MapMat_val;
|
||||
template <typename T> class SpSubview_MapMat_val;
|
||||
}
|
||||
|
||||
namespace php_arma
|
||||
|
@ -35,9 +32,9 @@ namespace php_arma
|
|||
static void set_val(zend_object *zobj, T val)
|
||||
{
|
||||
if constexpr (IsSparse) {
|
||||
*to_native_object<native_t>(zobj) = val;
|
||||
*ZOBJ_NATIVE(zobj) = val;
|
||||
} else {
|
||||
**to_native_object<native_t>(zobj) = val;
|
||||
**ZOBJ_NATIVE(zobj) = val;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,10 +55,12 @@ namespace php_arma
|
|||
PHP_ARMA_FENTRY(me)
|
||||
));
|
||||
ce->create_object = object_non_constructible;
|
||||
|
||||
object_handlers_init(&handlers);
|
||||
handlers.offset = sizeof(native_t);
|
||||
handlers.clone_obj = nullptr;
|
||||
handlers.dtor_obj = object_destroy<native_t>;
|
||||
handlers.offset = sizeof(native_t);
|
||||
handlers.clone_obj = nullptr;
|
||||
handlers.dtor_obj = object_destroy<native_t>;
|
||||
handlers.count_elements = base<T, mat>::count_elements;
|
||||
}
|
||||
|
||||
PHP_ARMA_NAME_DECLARE(mat, "DMat", double);
|
||||
|
|
|
@ -102,6 +102,14 @@
|
|||
|
||||
#endif // PHP_ARMA_OPERATORS
|
||||
|
||||
/// Helper macros for handling native objects.
|
||||
|
||||
#define ZOBJ_NATIVE(zobj) \
|
||||
to_native_object<native_t>(zobj)
|
||||
|
||||
#define Z_NATIVE_OBJ_P(zv) ZOBJ_NATIVE(Z_OBJ_P(zv))
|
||||
#define THIS_NATIVE Z_NATIVE_OBJ_P(getThis())
|
||||
|
||||
namespace php_arma
|
||||
{
|
||||
extern zend_module_entry module_entry;
|
||||
|
|
|
@ -10,7 +10,12 @@ namespace Arma;
|
|||
abstract class HDF5Opts
|
||||
{
|
||||
/**
|
||||
* Save/load the data with columns transposed to rows (and vice versa)
|
||||
* No extra options.
|
||||
*/
|
||||
const NONE = 0;
|
||||
|
||||
/**
|
||||
* Save/load the data with columns transposed to rows (and vice versa).
|
||||
*/
|
||||
const TRANS = 1 << 0;
|
||||
|
||||
|
|
|
@ -52,11 +52,14 @@ interface Resizable
|
|||
*/
|
||||
function setImag($other);
|
||||
|
||||
// Saving
|
||||
// Saving/loading
|
||||
|
||||
/**
|
||||
* Store data in a file or stream (the stream must be opened in binary mode).
|
||||
*
|
||||
* Data will be saved to $dest, which can be the file name, stream handle, or (HDF5 only) an array which
|
||||
* specifies HDF5 names and options (['file_name' => string, 'dataset_name' => string, 'options' => int]).
|
||||
*
|
||||
* @param resource|string|array $dest
|
||||
* @param int $file_type[optional]
|
||||
* @return bool
|
||||
|
@ -66,6 +69,9 @@ interface Resizable
|
|||
/**
|
||||
* Retrieve data from a file or stream (the stream must be opened in binary mode).
|
||||
*
|
||||
* Data will be read from $from, which can be the source file name, stream handle, or (HDF5 only)
|
||||
* an array which specifies HDF5 names and options.
|
||||
*
|
||||
* On failure, the object is reset so that it has no elements.
|
||||
*
|
||||
* @param resource|string|array $from
|
||||
|
|
Reference in New Issue