Exemplo n.º 1
0
 /**
  * Gives a multidimensional array a new shape
  *
  * @param array $data     given data
  * @param array $shape    old shape
  * @param array $newShape new shape
  *
  * @return array
  *
  * @throws InvalidArgumentException will be thrown, if the new shape has other size than the old one
  *
  * @since 1.0.0
  */
 public static function reshape(array $data, array $shape, array $newShape)
 {
     $oldSize = Helper::multiply($shape);
     $newSize = Helper::multiply($newShape);
     if ($newSize !== $oldSize) {
         throw new InvalidArgumentException('Total size of new array must be unchanged');
     }
     return self::reshapeRecursive(self::reshapeToVectorRecursive($data), $newShape);
 }
Exemplo n.º 2
0
 /**
  * Tests Helper::multiply with empty array
  */
 public function testMultiplyEmpty()
 {
     $this->assertSame(1, Helper::multiply([]));
 }
Exemplo n.º 3
0
 /**
  * Returns the number of elements the NumArray
  *
  * @return int
  *
  * @api
  * @since 1.0.0
  */
 public function getSize()
 {
     return Helper::multiply($this->getShape());
 }