/** * Combines all elements of an NumArray at a given axis with the `$callback` * function * * @param NumArray $numArray given NumArray * @param callback $callback callback function * @param int $axis given axis * * @return NumArray * * @throws InvalidArgumentException will be thrown, if axis is out of bounds * * @since 1.0.0 */ public static function reduceArray(NumArray $numArray, $callback, $axis) { if ($axis && $axis >= $numArray->getNDim()) { throw new InvalidArgumentException('Axis ' . $axis . ' out of bounds'); } return new NumArray(self::reduceRecursive($numArray->getData(), $callback, $axis)); }
/** * Multiplies an array, NumArray or numeric value to the existing NumArray * * @param mixed $factor an other int, float, array or NumArray * * @return $this * * @api * @since 1.0.0 */ public function dot($factor) { if (!$factor instanceof NumArray) { $factor = new NumArray($factor); } $result = Dot::dotArray($this->data, $this->shape, $factor->getData(), $factor->getShape()); $this->data = $result['data']; $this->shape = $result['shape']; $this->flushCache(); return $this; }
/** * Tests NumArray::getData */ public function testGetData() { $array = [1, 2, 3]; $numArray = new NumArray($array); $this->assertSame($array, $numArray->getData()); }