diff --git a/.travis.yml b/.travis.yml
index 5d65be0..c2cbacf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,16 +9,17 @@ dist: trusty
php:
- 7.1
- 7.2
+ - 7.2.3
matrix:
fast_finish: true
allow_failures:
- php: 7.1
+ - php: 7.2.3
cache:
apt: true
- ccache: true
install:
- curl -s http://getcomposer.org/installer | php
@@ -27,7 +28,6 @@ install:
before_script:
- ccache --version
- ccache --zero-stats
- - export USE_CCACHE=1
- git clone https://github.com/phpsci/phpsci-ext.git
- cd phpsci-ext
- ./travis/compile.sh
@@ -36,7 +36,5 @@ before_script:
script:
- cd $TRAVIS_BUILD_DIR
+ - export USE_ZEND_ALLOC=0
- vendor/bin/phpunit
-
-after_success:
- - ccache --show-stats
\ No newline at end of file
diff --git a/README.md b/README.md
index 11d054c..34ad015 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@
[](https://coveralls.io/github/phpsci/phpsci?branch=master)
-
+
diff --git a/src/PHPSci/Kernel/CArray/CArrayWrapper.php b/src/PHPSci/Kernel/CArray/CArrayWrapper.php
index 86c1447..e7517aa 100644
--- a/src/PHPSci/Kernel/CArray/CArrayWrapper.php
+++ b/src/PHPSci/Kernel/CArray/CArrayWrapper.php
@@ -4,6 +4,7 @@
use PHPSci\Kernel\Initializers\Creatable;
use PHPSci\Kernel\LinearAlgebra\Operatable;
use PHPSci\Kernel\Orchestrator\MemoryPointer;
+use PHPSci\Kernel\PropertiesProcessor\Inflatable;
use PHPSci\Kernel\Ranges\Rangeable;
use PHPSci\Kernel\Transform\Transformable;
use PHPSci\PHPSci;
@@ -16,8 +17,7 @@
*/
abstract class CArrayWrapper implements Stackable, \ArrayAccess, \Countable
{
-
- use Transformable, Creatable, Operatable, Rangeable;
+ use Transformable, Creatable, Operatable, Rangeable, Printable, Inflatable;
/**
* @var
@@ -26,7 +26,6 @@ abstract class CArrayWrapper implements Stackable, \ArrayAccess, \Countable
/**
- *
* @return int|void
*/
public function count()
@@ -126,13 +125,7 @@ public function __invoke()
// TODO: Implement __invoke() method.
}
- /**
- *
- */
- public function __toString()
- {
- // TODO: Implement __toString() method.
- }
+
/**
* Get current Pointer Object
diff --git a/src/PHPSci/Kernel/CArray/Printable.php b/src/PHPSci/Kernel/CArray/Printable.php
new file mode 100644
index 0000000..6a0fbce
--- /dev/null
+++ b/src/PHPSci/Kernel/CArray/Printable.php
@@ -0,0 +1,23 @@
+
+ * @package PHPSci\Kernel\CArray
+ */
+trait Printable
+{
+ /**
+ * Print current CArray
+ *
+ * @author Henrique Borba
+ */
+ public function __toString()
+ {
+ echo \CArray::print_r($this->ptr()->getPointer(), $this->rows, $this->cols);
+ return '';
+ }
+}
\ No newline at end of file
diff --git a/src/PHPSci/Kernel/Orchestrator/MemoryPointer.php b/src/PHPSci/Kernel/Orchestrator/MemoryPointer.php
index ddd6f8d..82cad0b 100644
--- a/src/PHPSci/Kernel/Orchestrator/MemoryPointer.php
+++ b/src/PHPSci/Kernel/Orchestrator/MemoryPointer.php
@@ -23,9 +23,11 @@ class MemoryPointer
* MemoryPointer constructor.
*
* @author Henrique Borba
- * @param \stdClass $ptr
+ * @param \CArray $ptr
+ * @param int $rows
+ * @param int $cols
*/
- public function __construct(\stdClass $ptr, int $rows, int $cols)
+ public function __construct(\CArray $ptr, int $rows, int $cols)
{
$this->uuid = $ptr->uuid;
$this->rows = $rows;
@@ -42,12 +44,12 @@ public function getPointer() {
}
/**
- * Get current UUID
+ * Get current UUID (alias of getPointer)
*
* @author Henrique Borba
*/
public function getUUID() {
- return $this->uuid;
+ return $this->getPointer();
}
/**
diff --git a/src/PHPSci/Kernel/PropertiesProcessor/Inflatable.php b/src/PHPSci/Kernel/PropertiesProcessor/Inflatable.php
new file mode 100644
index 0000000..e275a2f
--- /dev/null
+++ b/src/PHPSci/Kernel/PropertiesProcessor/Inflatable.php
@@ -0,0 +1,27 @@
+
+ * @package PHPSci\Kernel\PropertiesProcessor
+ */
+trait Inflatable
+{
+
+ /**
+ * Emulates properties based on available classes.
+ *
+ * @author Henrique Borba
+ * @param $name
+ * @return
+ */
+ public function __get($name)
+ {
+ return call_user_func('PHPSci\\Kernel\\PropertiesProcessor\\'.$name.'::run', $this);
+ }
+
+}
\ No newline at end of file
diff --git a/src/PHPSci/PropertiesProcessor/PropertiesProcessor.php b/src/PHPSci/Kernel/PropertiesProcessor/PropertiesProcessor.php
similarity index 76%
rename from src/PHPSci/PropertiesProcessor/PropertiesProcessor.php
rename to src/PHPSci/Kernel/PropertiesProcessor/PropertiesProcessor.php
index 801d4fa..216c553 100644
--- a/src/PHPSci/PropertiesProcessor/PropertiesProcessor.php
+++ b/src/PHPSci/Kernel/PropertiesProcessor/PropertiesProcessor.php
@@ -1,5 +1,5 @@
* @param PHPSci $obj
* @return int
*/
public static function run(PHPSci $obj)
{
- return $obj->getCols();
+ return $obj->ptr()->getCols();
}
}
\ No newline at end of file
diff --git a/src/PHPSci/PropertiesProcessor/rows.php b/src/PHPSci/Kernel/PropertiesProcessor/rows.php
similarity index 80%
rename from src/PHPSci/PropertiesProcessor/rows.php
rename to src/PHPSci/Kernel/PropertiesProcessor/rows.php
index 6eceaaa..705b784 100644
--- a/src/PHPSci/PropertiesProcessor/rows.php
+++ b/src/PHPSci/Kernel/PropertiesProcessor/rows.php
@@ -1,5 +1,5 @@
getRows();
+ return $obj->ptr()->getRows();
}
}
\ No newline at end of file
diff --git a/src/PHPSci/PropertiesProcessor/sizeOf.php b/src/PHPSci/Kernel/PropertiesProcessor/sizeOf.php
similarity index 64%
rename from src/PHPSci/PropertiesProcessor/sizeOf.php
rename to src/PHPSci/Kernel/PropertiesProcessor/sizeOf.php
index c9398f9..4e78ac1 100644
--- a/src/PHPSci/PropertiesProcessor/sizeOf.php
+++ b/src/PHPSci/Kernel/PropertiesProcessor/sizeOf.php
@@ -1,5 +1,5 @@
sizeOf();
+ return $obj->ptr()->sizeOf();
}
}
\ No newline at end of file
diff --git a/src/PHPSci/Kernel/PropertiesProcessor/took.php b/src/PHPSci/Kernel/PropertiesProcessor/took.php
new file mode 100644
index 0000000..1102779
--- /dev/null
+++ b/src/PHPSci/Kernel/PropertiesProcessor/took.php
@@ -0,0 +1,24 @@
+getTook();
+ }
+}
\ No newline at end of file
diff --git a/src/PHPSci/Kernel/Ranges/Rangeable.php b/src/PHPSci/Kernel/Ranges/Rangeable.php
index 51a69cd..e4f72f0 100644
--- a/src/PHPSci/Kernel/Ranges/Rangeable.php
+++ b/src/PHPSci/Kernel/Ranges/Rangeable.php
@@ -60,4 +60,25 @@ public static function linspace(float $stop, float $start = 0., float $num = 50)
);
}
+ /**
+ * Return numbers spaced evenly on a log scale.
+ *
+ * @author Henrique Borba
+ * @param float $start base ** start is the starting value of the sequence.
+ * @param float $stop base ** stop is the final value of the sequence
+ * @param int $num Number of samples to generate. Default is 50.
+ * @param float $base The base of the log space.
+ * @return CArrayWrapper
+ */
+ public static function logspace(float $start, float $stop, int $num = 50, float $base = 10) : CArrayWrapper {
+ $new_ptr = \CArray::logspace($start, $stop, $num, $base);
+ return new PHPSci(
+ new MemoryPointer(
+ $new_ptr,
+ $new_ptr->x,
+ $new_ptr->y
+ )
+ );
+ }
+
}
\ No newline at end of file
diff --git a/src/PHPSci/Kernel/Transform/Transformable.php b/src/PHPSci/Kernel/Transform/Transformable.php
index cee0284..6fe2a27 100644
--- a/src/PHPSci/Kernel/Transform/Transformable.php
+++ b/src/PHPSci/Kernel/Transform/Transformable.php
@@ -40,4 +40,16 @@ public function toDouble() {
return \CArray::toDouble($this->ptr()->getPointer());
}
+ /**
+ * Convert the input CArray to an array.
+ *
+ * Created for NumPy compatibility.
+ *
+ * @author Henrique Borba
+ * @param PHPSci $obj
+ * @return array
+ */
+ public static function asarray(PHPSci $obj) : array {
+ return $obj->toArray();
+ }
}
\ No newline at end of file
diff --git a/src/PHPSci/PropertiesProcessor/took.php b/src/PHPSci/PropertiesProcessor/took.php
deleted file mode 100644
index daf3368..0000000
--- a/src/PHPSci/PropertiesProcessor/took.php
+++ /dev/null
@@ -1,14 +0,0 @@
-getTook();
- }
-}
\ No newline at end of file
diff --git a/tests/Initializers/ArrayConvertTest.php b/tests/Initializers/ArrayConvertTest.php
index c60189d..13eca18 100644
--- a/tests/Initializers/ArrayConvertTest.php
+++ b/tests/Initializers/ArrayConvertTest.php
@@ -47,7 +47,7 @@ public function testFromArray1D() {
public function testToArray1D() {
$parr = [1,0,1,0,0,1,0,1];
$a = ps::fromArray($parr);
- $b = $a->toArray();
+ $b = ps::asarray($a);
$this->assertObjectNotHasAttribute('uuid', $a);
$this->assertEquals($parr, $b);
}
diff --git a/tests/Ranges/LogspaceTest.php b/tests/Ranges/LogspaceTest.php
new file mode 100644
index 0000000..69b2b8f
--- /dev/null
+++ b/tests/Ranges/LogspaceTest.php
@@ -0,0 +1,31 @@
+
+ * @package PHPSci\Tests\Ranges
+ */
+class LogspaceTest extends TestCase
+{
+
+ /**
+ * Test logspace static range initializer
+ *
+ * @author Henrique Borba
+ */
+ public function testLogspaceRangeInitializer() {
+ $expected = [100, 215.4434356689453, 464.1589660644531, 1000];
+ $returned = PHPSci::logspace(2,3, 4)->toArray();
+ $this->assertEquals($expected, $returned);
+
+ $expected = [4, 5.039683818817139, 6.349604606628418, 8];
+ $returned = PHPSci::logspace(2,3, 4, 2)->toArray();
+ $this->assertEquals($expected, $returned);
+ }
+
+}
\ No newline at end of file