update
This commit is contained in:
parent
b114b55fcf
commit
b15a04b95c
|
@ -3,10 +3,15 @@ PHP_ARG_ENABLE(arma, for armadillo support,
|
|||
|
||||
if test "$PHP_ARMA" != "no"; then
|
||||
PHP_REQUIRE_CXX()
|
||||
|
||||
ARMA_SRC=" \
|
||||
src/php_arma.cc \
|
||||
src/interfaces.cc \
|
||||
src/constants.cc \
|
||||
src/complex.cc"
|
||||
src/complex.cc \
|
||||
src/subview_val.cc"
|
||||
PHP_NEW_EXTENSION(arma, $ARMA_SRC, $ext_shared, , -std=c++17)
|
||||
|
||||
PHP_ADD_LIBRARY(armadillo, 1, ARMA_SHARED_LIBADD)
|
||||
PHP_SUBST(ARMA_SHARED_LIBADD)
|
||||
fi
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace php_arma
|
||||
{
|
||||
template <typename T>
|
||||
ZEND_NAMED_FUNCTION(complex<T>::__construct)
|
||||
PHP_ARMA_FUNCTION(complex, __construct, T)
|
||||
{
|
||||
zval *real, *imag;
|
||||
ZEND_PARSE_PARAMETERS_START(0, 2)
|
||||
|
@ -45,7 +45,7 @@ namespace php_arma
|
|||
object_set_property(Z_OBJ_P(current), 1, &zero_val);
|
||||
}
|
||||
|
||||
Z_OBJ_HT_P(current) = PHP_ARMA_HANDLERS(complex, T);
|
||||
Z_OBJ_HT_P(current) = &handlers;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -74,9 +74,10 @@ namespace php_arma
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void complex<T>::ce_init(zend_class_entry *parent_ce)
|
||||
zend_always_inline
|
||||
void complex<T>::ce_init(const char *name, zend_class_entry *parent_ce)
|
||||
{
|
||||
ce = class_register("CxDouble", parent_ce, me);
|
||||
ce = class_register(name, parent_ce, me);
|
||||
property_declare(ce, "real");
|
||||
property_declare(ce, "imag");
|
||||
object_handlers_init(&handlers);
|
||||
|
@ -87,6 +88,6 @@ namespace php_arma
|
|||
{
|
||||
complex_ce = abstract_class_register("Complex");
|
||||
|
||||
complex<double>::ce_init(complex_ce);
|
||||
complex<double>::ce_init("CxDouble", complex_ce);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,16 +20,14 @@ namespace php_arma
|
|||
{
|
||||
friend void complex_init();
|
||||
|
||||
PHP_ARMA_CE_DECLARE();
|
||||
PHP_ARMA_HANDLERS_DECLARE();
|
||||
PHP_ARMA_CE_HANDLRES_DECLARE();
|
||||
|
||||
private:
|
||||
static ZEND_NAMED_FUNCTION(__construct);
|
||||
|
||||
static void write_property(zval*, zval*, zval*, void**);
|
||||
|
||||
zend_always_inline
|
||||
static void ce_init(zend_class_entry*);
|
||||
static void ce_init(const char*, zend_class_entry*);
|
||||
|
||||
PHP_ARMA_START_ME()
|
||||
PHP_ARMA_ME(__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// php-armadillo/fill.cc
|
||||
// php-armadillo/constants.cc
|
||||
//
|
||||
// @Author CismonX
|
||||
//
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "interfaces.hh"
|
||||
#include "constants.hh"
|
||||
#include "complex.hh"
|
||||
#include "subview_val.hh"
|
||||
|
||||
#include <ext/standard/info.h>
|
||||
|
||||
|
|
|
@ -26,9 +26,6 @@ extern zend_module_entry arma_module_entry;
|
|||
|
||||
/// Helper macros for method entry.
|
||||
|
||||
#define Z_OBJNAME_P(zval_p) \
|
||||
ZSTR_VAL(Z_OBJCE_P(zval_p)->name)
|
||||
|
||||
#define PHP_ARMA_START_ME() \
|
||||
static constexpr zend_function_entry const me[] = {
|
||||
|
||||
|
@ -42,12 +39,13 @@ extern zend_module_entry arma_module_entry;
|
|||
#define PHP_ARMA_METHODS(cls, ...) \
|
||||
cls<__VA_ARGS__>::me
|
||||
|
||||
#define PHP_ARMA_FUNCTION(cls, func, ...) \
|
||||
void ZEND_FASTCALL cls<__VA_ARGS__>::func(INTERNAL_FUNCTION_PARAMETERS)
|
||||
|
||||
/// Helper macros for class entry and object handlers
|
||||
|
||||
#define PHP_ARMA_CE_DECLARE() \
|
||||
static inline zend_class_entry *ce
|
||||
|
||||
#define PHP_ARMA_HANDLERS_DECLARE() \
|
||||
#define PHP_ARMA_CE_HANDLRES_DECLARE() \
|
||||
static inline zend_class_entry *ce; \
|
||||
static inline zend_object_handlers handlers
|
||||
|
||||
#define PHP_ARMA_CE(cls, ...) \
|
||||
|
@ -56,6 +54,9 @@ extern zend_module_entry arma_module_entry;
|
|||
#define PHP_ARMA_HANDLERS(cls, ...) \
|
||||
&cls<__VA_ARGS__>::handlers
|
||||
|
||||
#define Z_OBJNAME_P(zval_p) \
|
||||
ZSTR_VAL(Z_OBJCE_P(zval_p)->name)
|
||||
|
||||
namespace php_arma
|
||||
{
|
||||
/// Helper functions for initializing class entry and object handlers.
|
||||
|
@ -138,21 +139,20 @@ namespace php_arma
|
|||
{
|
||||
auto obj = reinterpret_cast<T*>(ecalloc(1,
|
||||
sizeof(T) + sizeof(zend_object) + zend_object_properties_size(ce)));
|
||||
auto handlers = init(obj);
|
||||
auto zobj = to_zend_object(obj);
|
||||
zobj->handlers = init(obj);
|
||||
zend_object_std_init(zobj, ce);
|
||||
zobj->handlers = handlers ? handlers : &std_object_handlers;
|
||||
return zobj;
|
||||
}
|
||||
|
||||
zend_always_inline
|
||||
zend_object *object_create(zend_class_entry *ce, const zend_object_handlers *handlers = &std_object_handlers)
|
||||
zend_object *object_create(zend_class_entry *ce, const zend_object_handlers *handlers)
|
||||
{
|
||||
auto zobj = reinterpret_cast<zend_object *>(ecalloc(1,
|
||||
sizeof(zend_object) + zend_object_properties_size(ce)));
|
||||
zobj->handlers = handlers;
|
||||
zend_object_std_init(zobj, ce);
|
||||
object_properties_init(zobj, ce);
|
||||
zobj->handlers = handlers;
|
||||
return zobj;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// php-armadillo/subview_val.cc
|
||||
//
|
||||
// @Author CismonX
|
||||
//
|
||||
|
||||
#include "subview_val.hh"
|
||||
|
||||
namespace php_arma
|
||||
{
|
||||
template <typename T, bool B1, bool B2>
|
||||
zend_always_inline
|
||||
T subview_val<T, B1, B2>::get_val(zend_object *zobj)
|
||||
{
|
||||
return static_cast<T>(*to_native_object<native_t>(zobj));
|
||||
}
|
||||
|
||||
template <typename T, bool B1, bool B2>
|
||||
PHP_ARMA_FUNCTION(subview_val, val, T, B1, B2)
|
||||
{
|
||||
zval *current = getThis();
|
||||
|
||||
zval_set_scalar(return_value, get_val(Z_OBJ_P(current)));
|
||||
}
|
||||
|
||||
template <typename T, bool B1, bool B2>
|
||||
PHP_ARMA_FUNCTION(subview_val, setTo, T, B1, B2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template <typename T, bool B1, bool B2>
|
||||
zend_always_inline
|
||||
void subview_val<T, B1, B2>::ce_init(const char *name, zend_class_entry *parent_ce)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// php-armadillo/subview_val.hh
|
||||
//
|
||||
// @Author CismonX
|
||||
//
|
||||
|
||||
#ifndef PHP_ARMA_SVVAL_HH
|
||||
#define PHP_ARMA_SVVAL_HH
|
||||
|
||||
#include "php_arma.hh"
|
||||
|
||||
#include <armadillo>
|
||||
|
||||
namespace php_arma
|
||||
{
|
||||
template <typename T, bool IsSparse, bool IsSubview>
|
||||
struct subview_val
|
||||
{
|
||||
using sp_svval_t = std::conditional_t<IsSubview,
|
||||
arma::SpSubview_MapMat_val<T>, arma::SpMat_MapMat_val<T>>;
|
||||
|
||||
using native_t = std::conditional_t<IsSparse, sp_svval_t, T>;
|
||||
|
||||
zend_always_inline
|
||||
static void set_val(zend_object *zobj, native_t &&val)
|
||||
{
|
||||
*to_native_object<native_t>(zobj) = std::move(val);
|
||||
}
|
||||
|
||||
static T get_val(zend_object*);
|
||||
|
||||
PHP_ARMA_CE_HANDLRES_DECLARE();
|
||||
|
||||
private:
|
||||
static ZEND_NAMED_FUNCTION(val);
|
||||
static ZEND_NAMED_FUNCTION(setTo);
|
||||
|
||||
static void ce_init(const char*, zend_class_entry*);
|
||||
|
||||
PHP_ARMA_START_ME()
|
||||
PHP_ARMA_ME(val, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_ME(setTo, ZEND_ACC_PUBLIC)
|
||||
PHP_ARMA_END_ME();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //!PHP_ARMA_SVVAL_HH
|
8
stubs/MapVal.php
Normal file
8
stubs/MapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
abstract class MapVal implements Internal\Scalar
|
||||
{
|
||||
|
||||
}
|
8
stubs/SpMapVal.php
Normal file
8
stubs/SpMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
abstract class SpMapVal implements Internal\Scalar
|
||||
{
|
||||
|
||||
}
|
8
stubs/SpSvMapVal.php
Normal file
8
stubs/SpSvMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
abstract class SpSvMapVal implements Internal\Scalar
|
||||
{
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
abstract class SpSvVal implements Internal\Scalar
|
||||
{
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
abstract class SvVal implements Internal\Scalar
|
||||
{
|
||||
|
||||
}
|
8
stubs/impl/CxDMapVal.php
Normal file
8
stubs/impl/CxDMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class CxDMapVal extends MapVal
|
||||
{
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Arma;
|
||||
|
||||
class ISvVal extends SvVal
|
||||
class DMapVal extends MapVal
|
||||
{
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class DSvVal extends SvVal
|
||||
{
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Arma;
|
||||
|
||||
class CxDSvVal extends SvVal
|
||||
class IMapVal extends MapVal
|
||||
{
|
||||
|
||||
}
|
8
stubs/impl/SpCxDMapVal.php
Normal file
8
stubs/impl/SpCxDMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpCxDMapVal extends SpMapVal
|
||||
{
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpCxDSvVal extends SpSvVal
|
||||
{
|
||||
|
||||
}
|
8
stubs/impl/SpDMapVal.php
Normal file
8
stubs/impl/SpDMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpDMapVal extends SpMapVal
|
||||
{
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpDSvVal extends SpSvVal
|
||||
{
|
||||
|
||||
}
|
8
stubs/impl/SpIMapVal.php
Normal file
8
stubs/impl/SpIMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpIMapVal extends SpMapVal
|
||||
{
|
||||
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpISvVal extends SpSvVal
|
||||
{
|
||||
|
||||
}
|
8
stubs/impl/SpSvCxDMapVal.php
Normal file
8
stubs/impl/SpSvCxDMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpSvCxDMapVal extends SpSvMapVal
|
||||
{
|
||||
|
||||
}
|
8
stubs/impl/SpSvDMapVal.php
Normal file
8
stubs/impl/SpSvDMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpSvDMapVal extends SpSvMapVal
|
||||
{
|
||||
|
||||
}
|
8
stubs/impl/SpSvIMapVal.php
Normal file
8
stubs/impl/SpSvIMapVal.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Arma;
|
||||
|
||||
class SpSvIMapVal extends SpSvMapVal
|
||||
{
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ interface DenseMatrix extends Dense, Matrix
|
|||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpSvVal
|
||||
* @return \Arma\MapVal
|
||||
*/
|
||||
function at($i, $j);
|
||||
|
||||
|
@ -25,7 +25,7 @@ interface DenseMatrix extends Dense, Matrix
|
|||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpSvVal
|
||||
* @return \Arma\MapVal
|
||||
*/
|
||||
function __invoke($i, $j);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ interface DenseVector extends Dense, Vector
|
|||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $idx
|
||||
* @return \Arma\SvVal
|
||||
* @return \Arma\MapVal
|
||||
*/
|
||||
function __invoke($idx);
|
||||
|
||||
|
@ -22,7 +22,7 @@ interface DenseVector extends Dense, Vector
|
|||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $idx
|
||||
* @return \Arma\SvVal
|
||||
* @return \Arma\MapVal
|
||||
*/
|
||||
function at($idx);
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ interface Matrix
|
|||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return Subview
|
||||
* @return Scalar
|
||||
*/
|
||||
function __invoke($i, $j);
|
||||
|
||||
|
@ -104,7 +104,7 @@ interface Matrix
|
|||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return Subview
|
||||
* @return Scalar
|
||||
*/
|
||||
function at($i, $j);
|
||||
|
||||
|
|
|
@ -11,24 +11,6 @@ interface SparseMatrix extends Sparse, Matrix
|
|||
{
|
||||
// Subview
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpSvVal
|
||||
*/
|
||||
function at($i, $j);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpSvVal
|
||||
*/
|
||||
function __invoke($i, $j);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
|
|
@ -4,5 +4,23 @@ namespace Arma\Internal;
|
|||
|
||||
interface SparseNonResizableMatrix extends SparseMatrix, NonResizableMatrix
|
||||
{
|
||||
// Subview
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpSvMapVal
|
||||
*/
|
||||
function at($i, $j);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpSvMapVal
|
||||
*/
|
||||
function __invoke($i, $j);
|
||||
}
|
||||
|
|
|
@ -4,5 +4,23 @@ namespace Arma\Internal;
|
|||
|
||||
interface SparseResizableMatrix extends SparseMatrix, ResizableMatrix
|
||||
{
|
||||
// Subview
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpMapVal
|
||||
*/
|
||||
function at($i, $j);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $i
|
||||
* @param int $j[optional]
|
||||
* @return \Arma\SpMapVal
|
||||
*/
|
||||
function __invoke($i, $j);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ interface SparseVector extends Sparse, Vector
|
|||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $idx
|
||||
* @return \Arma\SpSvVal
|
||||
* @return \Arma\SpMapVal
|
||||
*/
|
||||
function __invoke($idx);
|
||||
|
||||
|
@ -18,7 +18,7 @@ interface SparseVector extends Sparse, Vector
|
|||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $idx
|
||||
* @return \Arma\SpSvVal
|
||||
* @return \Arma\SpMapVal
|
||||
*/
|
||||
function at($idx);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ interface Vector
|
|||
* Read/write access to the n-th element.
|
||||
*
|
||||
* @param int $idx
|
||||
* @return Subview
|
||||
* @return Scalar
|
||||
*/
|
||||
function __invoke($idx);
|
||||
|
||||
|
@ -46,7 +46,7 @@ interface Vector
|
|||
* Without a bounds check. Not recommended for use unless your code has been thoroughly debugged.
|
||||
*
|
||||
* @param int $idx
|
||||
* @return Subview
|
||||
* @return Scalar
|
||||
*/
|
||||
function at($idx);
|
||||
|
||||
|
|
Reference in New Issue
Block a user