RubixML / Tensor

A library and extension that provides objects for scientific computing in PHP.
https://rubixml.com
MIT License
229 stars 28 forks source link

Instabilities in Tensor\Matrix->multiply #43

Closed Aweptimum closed 6 months ago

Aweptimum commented 6 months ago

I installed version 3.0.4 of both the composer package (for autocompletion) and the PHP extension (using php-extension-installer) inside of a docker environment.

I verified it was enabled correctly using php -i, and then I did a basic multiplication test:

$A = Tensor\Matrix::quick([
  [1,2,3],
  [1,2,3],
  [1,2,3],
]);

$b = Tensor\Vector::quick([1,2,4]);
print_r($A->multiply($b))

What I got back was not the right answer:

[
  [1, 12, 0],
  [1, 12, 0],
  [1, 12, 0],
]

It should be:

[
  [1, 4, 12],
  [1, 4, 12],
  [1, 4, 12],
]

The first column is fine, however, the last column is shifted over one and the second column (of 4's) is just missing.

Aweptimum commented 6 months ago

In looking around at other issues, I found this statement by @andrewdalpino in the RubixML repo on https://github.com/RubixML/ML/issues/303

I believe we have a fix for this now ... please try compiling the Tensor extension from the latest master branch. Or wait for us to test and release Tensor 3.0.5 and download from PECL.

So I changed from installing the latest release to @master and re-ran my test. I am now getting the correct answer! Moreover, I had also been getting a crash when trying the svd and pseudoinverse methods, but they also work.

It might be a good idea to tag a new release that includes an upgraded zephir dep - a fix for the self, static deprecation errors was just merged in a month ago: https://github.com/zephir-lang/zephir/issues/2405#issuecomment-1934185734

Aweptimum commented 6 months ago

Newest 3.0.5 release fixes the crash, all good. #38 might also be able to be closed, but they manually compiled the extension.