Ejemplo n.º 1
0
 public function testConstructGivesExpectedOutput()
 {
     $expected = [[TypeFactory::createInt(0), TypeFactory::createInt(-1), TypeFactory::createInt(-2)], [TypeFactory::createInt(1), TypeFactory::createInt(0), TypeFactory::createInt(-1)], [TypeFactory::createInt(2), TypeFactory::createInt(1), TypeFactory::createInt(0)]];
     $this->object = new FunctionMatrix($this->function, TypeFactory::createInt(3), TypeFactory::createInt(3));
     $this->assertEquals($expected, $this->object->toArray());
     $this->assertTrue($this->object->is('Complete'));
     $this->assertTrue($this->object->is('Square'));
     $this->assertFalse($this->object->is('Empty'));
     $this->assertFalse($this->object->is('RowVector'));
     $this->assertFalse($this->object->is('ColumnVector'));
 }
Ejemplo n.º 2
0
 /**
  * Construct a Matrix with all entries set to IntType(0)
  *
  * @param NumericTypeInterface $rows Number of required rows
  * @param NumericTypeInterface $cols Number of required columns
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(NumericTypeInterface $rows, NumericTypeInterface $cols)
 {
     $comp = new Comparator();
     $one = TypeFactory::createInt(1);
     if ($comp->lt($rows, $one)) {
         throw new \InvalidArgumentException('$rows must be >= 1');
     }
     if ($comp->lt($cols, $one)) {
         throw new \InvalidArgumentException('$cols must be >= 1');
     }
     $f = function ($row, $col) {
         return TypeFactory::createInt(0);
     };
     parent::__construct($f, $rows, $cols);
 }
Ejemplo n.º 3
0
 /**
  * Construct a square NumericMatrix whose entries on the diagonal ==  1, 1/1 or 1+0i
  * All other entries == 0, 0/1 or 0+0i
  *
  * @param IntType $size Number of required rows and columns
  * @param IntType $identityType Type of identity entries: default == IDM_TYPE_INT
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(IntType $size, IntType $identityType = null)
 {
     if (is_null($identityType)) {
         $idt = self::IDM_TYPE_INT;
     } else {
         $idt = $identityType();
     }
     if (!in_array($idt, $this->availableTypes)) {
         throw new \InvalidArgumentException('Identity type invalid');
     }
     if ($size() < 1) {
         throw new \InvalidArgumentException('size must be >= 1');
     }
     $f = function ($row, $col) use($idt) {
         if ($idt == self::IDM_TYPE_RATIONAL) {
             return RationalTypeFactory::create($row == $col ? 1 : 0, 1);
         } elseif ($idt == self::IDM_TYPE_COMPLEX) {
             return ComplexTypeFactory::create(RationalTypeFactory::create($row == $col ? 1 : 0, 1), RationalTypeFactory::create(0, 1));
         } else {
             return TypeFactory::createInt($row == $col ? 1 : 0);
         }
     };
     parent::__construct($f, $size, $size);
 }