This commit is contained in:
CismonX 2019-02-05 21:31:16 +08:00
parent ca30fcbef5
commit 5bd00fe37d
20 changed files with 206 additions and 31 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.h linguist-language=C

38
.gitignore vendored
View File

@ -1,2 +1,38 @@
.deps
*.lo
*.la
.libs
acinclude.m4
aclocal.m4
autom4te.cache
build
config.guess
config.h
config.h.in
config.log
config.nice
config.status
config.sub
configure
configure.in
configure.ac
include
install-sh
libtool
ltmain.sh
Makefile
Makefile.fragments
Makefile.global
Makefile.objects
missing
mkinstalldirs
modules
run-tests.php
tests/*/*.diff
tests/*/*.out
tests/*/*.php
tests/*/*.exp
tests/*/*.log
tests/*/*.sh
.idea/
.vscode/
.vscode/

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018
Copyright (c) 2019 CismonX
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

7
config.m4 Normal file
View File

@ -0,0 +1,7 @@
PHP_ARG_ENABLE(arma, for armadillo support,
[ --enable-arma Enable armadillo support])
if test "$PHP_ARMA" != "no"; then
ARMA_SRC="src/arma.c"
PHP_NEW_EXTENSION(arma, $ARMA_SRC, $ext_shared)
fi

64
src/arma.c Normal file
View File

@ -0,0 +1,64 @@
//
// php-armadillo/arma.c
//
// @Author CismonX
//
#include "php_arma.h"
#include <zend_interfaces.h>
#include <ext/standard/info.h>
#define ARMA_CE_INIT(cls, name) \
zend_class_entry cls##_ce; \
INIT_CLASS_ENTRY(cls##_ce, name, cls##_methods); \
arma_##cls##_ce = zend_register_internal_class(&cls##_ce)
#define ARMA_CONST_DECLARE(cls, name, val) \
zend_declare_class_constant_long(arma_##cls##_ce, name, sizeof(name) - 1, val)
#define ARMA_PROP_DECLARE(cls, name, flags) \
zend_declare_property_null(arma_##cls##_ce, name, sizeof(name) - 1, flags)
#define ARMA_HANDLERS_INIT(cls) \
memcpy(&cls##_handlers, &std_object_handlers, sizeof(zend_object_handlers))
#define ARMA_HANDLER_SET(cls, name) \
cls##_handlers.name = cls##_##name
ZEND_DECLARE_MODULE_GLOBALS(arma)
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
PHP_MINIT_FUNCTION(arma)
{
#ifdef ZTS
ZEND_INIT_MODULE_GLOBALS(arma, NULL, NULL);
#endif
// ...
return SUCCESS;
}
PHP_MINFO_FUNCTION(arma)
{
php_info_print_table_start();
php_info_print_table_header(2, "armadillo support", "enabled");
php_info_print_table_end();
}
zend_module_entry arma_module_entry = {
STANDARD_MODULE_HEADER,
"arma",
NULL,
PHP_MINIT(arma),
NULL,
NULL,
NULL,
PHP_MINFO(arma),
PHP_ARMA_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_ARMA
ZEND_GET_MODULE(arma)
#endif

43
src/php_arma.h Normal file
View File

@ -0,0 +1,43 @@
//
// php-armadillo/php_arma.h
//
// @Author CismonX
//
#ifndef PHP_ARMA_H
#define PHP_ARMA_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <php.h>
extern zend_module_entry arma_module_entry;
#define PHP_ARMA_VERSION "0.0.1"
#ifdef PHP_WIN32
#define PHP_ARMA_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
#define PHP_ARMA_API __attribute__ ((visibility("default")))
#else
#define PHP_ARMA_API
#endif
ZEND_BEGIN_MODULE_GLOBALS(arma)
int unused;
ZEND_END_MODULE_GLOBALS(arma)
ZEND_EXTERN_MODULE_GLOBALS(arma)
#ifdef ZTS
#ifdef COMPILE_DL_ARMA
ZEND_TSRMLS_CACHE_EXTERN()
#endif
#define ARMA_G(v) TSRMG(arma_globals_id, zend_arma_globals*, v)
#else
#define ARMA_G(v) (arma_globals.v)
#endif
#endif // !PHP_ARMA_H

26
stubs/Base.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace Arma;
interface Base
{
function add($other);
function sub($other);
function mul($other);
function div($other);
function equals($others);
function notEquals($other);
function greaterThan($other);
function smallerThan($other);
function notGreaterThan($other);
function notSmallerThan($other);
}

View File

@ -5,4 +5,4 @@ namespace Arma;
interface Colvec
{
}
}

View File

@ -33,4 +33,4 @@ abstract class Fill
* Set each element to a random value from a normal/Gaussian distribution with zero mean and unit variance.
*/
const RANDN = 5;
}
}

View File

@ -43,4 +43,4 @@ interface Mat
*/
static function fromSparse($sp_mat);
}
}

View File

@ -5,4 +5,4 @@ namespace Arma;
interface Rowvec
{
}
}

View File

@ -5,4 +5,4 @@ namespace Arma;
interface SpMat
{
}
}

View File

@ -1,2 +0,0 @@
<?php

View File

@ -2,35 +2,35 @@
namespace Arma;
class CxDmat implements CxMat
class CxDMat implements CxMat
{
/**
* @inheritdoc
* @return CxDmat
* @return CxDMat
*/
static function init($in_rows, $in_cols, $fill = null) {}
/**
* @inheritdoc
* @return CxDmat
* @return CxDMat
*/
public static function fromMats($real, $imag) {}
/**
* @inheritdoc
* @return CxDmat
* @return CxDMat
*/
static function fromSparse($sp_mat) {}
/**
* @inheritdoc
* @return CxDmat
* @return CxDMat
*/
static function fromString($text) {}
/**
* @inheritdoc
* @return CxDmat
* @return CxDMat
*/
static function fromVec($vector) {}
}

View File

@ -2,35 +2,35 @@
namespace Arma;
class CxImat implements CxMat
class CxIMat implements CxMat
{
/**
* @inheritdoc
* @return CxImat
* @return CxIMat
*/
static function init($in_rows, $in_cols, $fill = 0) {}
/**
* @inheritdoc
* @return CxImat
* @return CxIMat
*/
public static function fromMats($real, $imag) {}
/**
* @inheritdoc
* @return CxImat
* @return CxIMat
*/
static function fromSparse($sp_mat) {}
/**
* @inheritdoc
* @return CxImat
* @return CxIMat
*/
static function fromString($text) {}
/**
* @inheritdoc
* @return CxImat
* @return CxIMat
*/
static function fromVec($vector) {}
}

0
stubs/impl/DColvec.php Normal file
View File

View File

@ -2,29 +2,29 @@
namespace Arma;
class Dmat implements Mat
class DMat implements Mat
{
/**
* @inheritdoc
* @return Dmat
* @return DMat
*/
static function init($in_rows, $in_cols, $fill = null) {}
/**
* @inheritdoc
* @return Dmat
* @return DMat
*/
static function fromSparse($sp_mat) {}
/**
* @inheritdoc
* @return Dmat
* @return DMat
*/
static function fromString($text) {}
/**
* @inheritdoc
* @return Dmat
* @return DMat
*/
static function fromVec($vector) {}
}

0
stubs/impl/DRowvec.php Normal file
View File

0
stubs/impl/DVec.php Normal file
View File

View File

@ -2,29 +2,29 @@
namespace Arma;
class Imat implements Mat
class IMat implements Mat
{
/**
* @inheritdoc
* @return Imat
* @return IMat
*/
static function init($in_rows, $in_cols, $fill = 0) {}
/**
* @inheritdoc
* @return Imat
* @return IMat
*/
static function fromSparse($sp_mat) {}
/**
* @inheritdoc
* @return Imat
* @return IMat
*/
static function fromString($text) {}
/**
* @inheritdoc
* @return Imat
* @return IMat
*/
static function fromVec($vector) {}
}