arange() public static method

Creates a vector (NumArray) from $low to $high with $step steps
Since: 1.0.0
public static arange ( float $low, float $high, float $step = 1 ) : NumArray
$low float beginning of the vector
$high float end of the vector
$step float steps, if not given `$step` = `1.0`
return NumArray
Ejemplo n.º 1
0
 public function testSetMatrixSlice()
 {
     $matrix = NumPHP::arange(-20, -1)->reshape(4, 5);
     $subMatrix = NumPHP::arange(1, 6)->reshape(2, 3);
     $expectedNumArray = new NumArray([[-20, -19, -18, -17, -16], [-15, -14, 1, 2, 3], [-10, -9, 4, 5, 6], [-5, -4, -3, -2, -1]]);
     $this->assertNumArrayEquals($expectedNumArray, $matrix->set('1:3', '2:5', $subMatrix));
 }
Ejemplo n.º 2
0
 /**
  * Tests NumArray::sub with scalar and vector
  */
 public function testSubVectorSingle()
 {
     $numArray1 = new NumArray(45);
     $numArray2 = NumPHP::arange(3, 8);
     $expectedNumArray = NumPHP::arange(42, 37);
     $this->assertNumArrayEquals($expectedNumArray, $numArray1->sub($numArray2));
 }
Ejemplo n.º 3
0
 /**
  * Tests NumArray::__toString with matrix
  */
 public function testToString3x4()
 {
     $numArray = NumPHP::arange(1, 12)->reshape(3, 4);
     $expectedOutput = "NumArray([\n  [1, 2, 3, 4],\n  [5, 6, 7, 8],\n  [9, 10," . " 11, 12]\n])\n";
     $this->expectOutputString($expectedOutput);
     echo $numArray;
 }
Ejemplo n.º 4
0
 /**
  * Tests NumArray::getNDim
  */
 public function testNDim()
 {
     $numArray = new NumArray(1);
     $this->assertSame(0, $numArray->getNDim());
     $numArray = NumPHP::arange(1, 2);
     $this->assertSame(1, $numArray->getNDim());
     $numArray = NumPHP::arange(1, 6)->reshape(2, 3);
     $this->assertSame(2, $numArray->getNDim());
 }
Ejemplo n.º 5
0
 /**
  * Tests if InvalidArgumentException will be thrown, when using NumArray::add with vectors of different size
  *
  * @expectedException        \NumPHP\Core\Exception\InvalidArgumentException
  * @expectedExceptionMessage Size 5 is different from size 4
  */
 public function testAddDifferentShape()
 {
     $numArray1 = NumPHP::arange(1, 5);
     $numArray2 = NumPHP::arange(1, 4);
     $numArray1->add($numArray2);
 }
Ejemplo n.º 6
0
 /**
  * Tests if DivideByZeroException will be thrown, when using NumArray::div with zero value in divisor
  *
  * @expectedException        \NumPHP\Core\Exception\DivideByZeroException
  * @expectedExceptionMessage Dividing by zero is forbidden
  */
 public function testDivZero()
 {
     $numArray1 = NumPHP::arange(1, 5);
     $numArray2 = NumPHP::arange(-2, 2);
     $numArray1->div($numArray2);
 }
Ejemplo n.º 7
0
 /**
  * Tests if InvalidArgumentException will be thrown, when using NumArray::dot
  * with two matrices that are not align
  *
  * @expectedException        \NumPHP\Core\Exception\InvalidArgumentException
  * @expectedExceptionMessage Matrix with shape (3, 4) and matrix with shape (3, 3) are not align.
  */
 public function testDotMatrix3x4Matrix3x3()
 {
     $numArray1 = NumPHP::arange(1, 12)->reshape(3, 4);
     $numArray2 = NumPHP::arange(1, 9)->reshape(3, 3);
     $numArray1->dot($numArray2);
 }
 /**
  * Tests if NoSquareMatrixException will be thrown, when using LinAlg::cholesky with not square matrix
  *
  * @expectedException        \NumPHP\LinAlg\Exception\NoSquareMatrixException
  * @expectedExceptionMessage Matrix with shape (2, 3) given, matrix has to be square
  */
 public function testCholeskyNotSquare()
 {
     $matrix = NumPHP::arange(1, 6)->reshape(2, 3);
     LinAlg::cholesky($matrix);
 }
Ejemplo n.º 9
0
 /**
  * Tests if InvalidArgumentException will be thrown by using NumArray::max and a
  * wrong axis on a matrix
  *
  * @expectedException        \NumPHP\Core\Exception\InvalidArgumentException
  * @expectedExceptionMessage Axis 2 out of bounds
  */
 public function testMaxMatrixAxis2()
 {
     $numArray = NumPHP::arange(1, 4)->reshape(2, 2);
     $numArray->max(2);
 }
Ejemplo n.º 10
0
 /**
  * Tests NumArray::get with negative slicing argument `:-1` on vector
  */
 public function testGet4ArgsSliceMinus1()
 {
     $numArray = NumPHP::arange(1, 4);
     $expectedNumArray = NumPHP::arange(1, 3);
     $this->assertNumArrayEquals($expectedNumArray, $numArray->get(':-1'));
 }
Ejemplo n.º 11
0
 /**
  * Tests if InvalidArgumentException will be thrown, when using NumPHP::arange
  * with negative step
  *
  * @expectedException        \NumPHP\Core\Exception\InvalidArgumentException
  * @expectedExceptionMessage Step has to be a positive value
  */
 public function testArangeInvalidArgumentException()
 {
     NumPHP::arange(1, 2, -1);
 }
Ejemplo n.º 12
0
 /**
  * Tests if NoSquareMatrixException will be thrown, when using LinAlg::det with
  * 2x3 matrix
  *
  * @expectedException        \NumPHP\LinAlg\Exception\NoSquareMatrixException
  * @expectedExceptionMessage Matrix with shape (2, 3) given, matrix has to be square
  */
 public function testDet2x3()
 {
     $numArray = NumPHP::arange(1, 6)->reshape(2, 3);
     LinAlg::det($numArray);
 }
Ejemplo n.º 13
0
 /**
  * Tests NumArray::getTranspose on a 2x3x4 matrix
  */
 public function testTranspose2x3x4()
 {
     $numArray = NumPHP::arange(1, 24)->reshape(2, 3, 4);
     $expectedNumArray = new NumArray([[[1, 13], [5, 17], [9, 21]], [[2, 14], [6, 18], [10, 22]], [[3, 15], [7, 19], [11, 23]], [[4, 16], [8, 20], [12, 24]]]);
     $this->assertNumArrayEquals($expectedNumArray, $numArray->getTranspose());
 }
Ejemplo n.º 14
0
 /**
  * Tests if cache will be flushed after NumArray::reshape
  */
 public function testReshapeCache()
 {
     $numArray = NumPHP::arange(1, 4);
     $numArray->setCache('key', 6);
     $numArray->reshape(2, 2);
     $this->assertFalse($numArray->inCache('key'));
 }
Ejemplo n.º 15
0
 /**
  * Tests if InvalidArgumentException will be thrown, when using NumArray::mult with vectors of different size
  *
  * @expectedException        \NumPHP\Core\Exception\InvalidArgumentException
  * @expectedExceptionMessage Size 5 is different from size 4
  */
 public function testMultDifferentShape()
 {
     $numArray1 = NumPHP::arange(1, 5);
     $numArray2 = NumPHP::arange(1, 4);
     $numArray1->mult($numArray2);
 }
Ejemplo n.º 16
0
 /**
  * Tests if InvalidArgumentException will be thrown by using NumArray::min and a
  * wrong axis on a matrix
  *
  * @expectedException        \NumPHP\Core\Exception\InvalidArgumentException
  * @expectedExceptionMessage Axis 2 out of bounds
  */
 public function testNimMatrixAxis2()
 {
     $numArray = NumPHP::arange(1, 9)->reshape(3, 3);
     $numArray->min(2);
 }
Ejemplo n.º 17
0
 /**
  * Tests NumArray::abs with a matrix
  */
 public function testAbsMatrix()
 {
     $numArray = new NumArray([[1, -2, -3], [-4, -5, 6]]);
     $expectedNumArray = NumPHP::arange(1, 6)->reshape(2, 3);
     $this->assertNumArrayEquals($expectedNumArray, $numArray->abs());
 }
Ejemplo n.º 18
0
 /**
  * Tests NumArray::sum with a 2x3x4 matrix and argument 2
  */
 public function testSumMatrix2x3x4Axis2()
 {
     $numArray = NumPHP::arange(1, 24)->reshape(2, 3, 4);
     $expectedNumArray = NumPHP::arange(10, 90, 16)->reshape(2, 3);
     $this->assertNumArrayEquals($expectedNumArray, $numArray->sum(2));
 }
Ejemplo n.º 19
0
 /**
  * Tests if InvalidArgumentException will be thrown, when using LinAlg::solve with 2x3x4 matrix
  *
  * @expectedException        \NumPHP\LinAlg\Exception\InvalidArgumentException
  * @expectedExceptionMessage Second argument has to be a vector or a matrix, NumArray with dimension 3 given
  */
 public function testSolve2x3x4Matrix()
 {
     $identity = NumPHP::identity(2);
     $matrix = NumPHP::arange(1, 24)->reshape(2, 3, 4);
     LinAlg::solve($identity, $matrix);
 }
Ejemplo n.º 20
0
 /**
  * Tests NumArray::sum with a 2x3x4 matrix and argument 0
  */
 public function testMeanMatrix2x3x4Axis0()
 {
     $numArray = NumPHP::arange(1, 24)->reshape(2, 3, 4);
     $expectedNumArray = NumPHP::arange(7, 18)->reshape(3, 4);
     $this->assertNumArrayEquals($expectedNumArray, $numArray->mean(0));
 }
Ejemplo n.º 21
0
 /**
  * Tests if NoMatrixException will be thrown, when using LinAlg::lud a vector
  *
  * @expectedException        \NumPHP\LinAlg\Exception\NoMatrixException
  * @expectedExceptionMessage NumArray with dimension 1 given, NumArray should have 2 dimensions
  */
 public function testLUDecompositionVector()
 {
     $numArray = NumPHP::arange(1, 2);
     LinAlg::lud($numArray);
 }