From 34281e40eec2c71cf6a242c5b1f4c708179ee4a4 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Thu, 21 Apr 2016 00:23:03 +0200 Subject: [PATCH] add scalar product function --- src/Phpml/Math/Product.php | 25 +++++++++++++++++++++++++ tests/Phpml/Math/ProductTest.php | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/Phpml/Math/Product.php create mode 100644 tests/Phpml/Math/ProductTest.php diff --git a/src/Phpml/Math/Product.php b/src/Phpml/Math/Product.php new file mode 100644 index 0000000..992eeaa --- /dev/null +++ b/src/Phpml/Math/Product.php @@ -0,0 +1,25 @@ + $value) { + $product += $value * $b[$index]; + } + + return $product; + } + +} diff --git a/tests/Phpml/Math/ProductTest.php b/tests/Phpml/Math/ProductTest.php new file mode 100644 index 0000000..d7aa015 --- /dev/null +++ b/tests/Phpml/Math/ProductTest.php @@ -0,0 +1,20 @@ +assertEquals(10, $product->scalar([2, 3], [-1, 4])); + $this->assertEquals(-0.1, $product->scalar([1, 4, 1], [-2, 0.5, -0.1])); + $this->assertEquals(8, $product->scalar([2], [4])); + } + +} \ No newline at end of file