Пример #1
0
 public function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->function = function ($row, $col) {
         return $row - $col;
     };
 }
Пример #2
0
 /**
  * Return number as Rational number.
  * NB, numerator and denominator will be caste as IntTypes
  *
  * @return \Chippyash\Type\Number\Rational\RationalType
  */
 public function asRational()
 {
     if (RequiredType::getInstance()->get() == RequiredType::TYPE_NATIVE) {
         return new RationalType(clone $this, new static(1));
     }
     return new GMPRationalType(new GMPIntType($this->value), new GMPIntType(1));
 }
Пример #3
0
 public function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new AsciiNumeric();
     $this->rationalOne = TypeFactory::createRational(TypeFactory::createInt(1), TypeFactory::createInt(1));
     $this->rationalHalf = TypeFactory::createRational(TypeFactory::createInt(1), TypeFactory::createInt(2));
     $this->complexTwo = TypeFactory::createComplex(TypeFactory::createRational(TypeFactory::createInt(2), TypeFactory::createInt(1)), TypeFactory::createRational(TypeFactory::createInt(0), TypeFactory::createInt(1)));
     $this->complexThree = TypeFactory::createComplex(TypeFactory::createRational(TypeFactory::createInt(3), TypeFactory::createInt(1)), TypeFactory::createRational(TypeFactory::createInt(-3), TypeFactory::createInt(2)));
 }
Пример #4
0
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new CMatrix();
     $this->empty = new NumericMatrix([]);
     $this->rowVector = new NumericMatrix([[1, 2, 3]]);
     $this->colVector = new NumericMatrix([[1], [2], [3]]);
     $this->square = new NumericMatrix([[1, 2, 3], [1, 2, 3], [1, 2, 3]]);
     $this->single = new NumericMatrix([1]);
 }
 public function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new Mult();
     $this->empty = new Matrix(array());
     $this->rowVector = new Matrix(array(array(1, 2, 3)));
     $this->colVector = new Matrix(array(array(1), array(2), array(3)));
     $this->square = new Matrix(array(array(1, 2, 3), array(1, 2, 3), array(1, 2, 3)));
     $this->single = new Matrix(array(1));
     $this->wideRectangle = new Matrix(array(array(1, 2, 3), array(1, 2, 3)));
     $this->longRectangle = new Matrix(array(array(1, 2), array(1, 2), array(1, 2)));
 }
Пример #6
0
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new CMatrix();
     $this->empty = new NumericMatrix([]);
     $this->rowVector = new NumericMatrix([[1, 2, 3]]);
     $this->colVector = new NumericMatrix([[1], [2], [3]]);
     $this->deepColVector = new NumericMatrix([[1], [2], [3], [4], [5]]);
     $this->square = new NumericMatrix([[1, 2, 3], [1, 2, 3], [1, 2, 3]]);
     $this->bigSquare = new NumericMatrix([[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]);
     $this->single = new NumericMatrix([1]);
     $this->wideRectangle = new NumericMatrix([[1, 2, 3], [1, 2, 3]]);
     $this->vwideRectangle = new NumericMatrix([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]]);
     $this->longRectangle = new NumericMatrix([[1, 2], [1, 2], [1, 2]]);
     $this->vlongRectangle = new NumericMatrix([[1, 2], [1, 2], [1, 2], [1, 2], [1, 2], [1, 2]]);
     $this->onesRow = new NumericMatrix([[1, 1, 1]]);
     $this->onesCol = new NumericMatrix([[1], [1], [1]]);
 }
 public function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = $this->getMockForAbstractClass('Chippyash\\Type\\Number\\Rational\\AbstractRationalType', array(new IntType(3), new IntType(4)));
 }
Пример #8
0
 protected function setUp()
 {
     $this->sut = RequiredType::getInstance();
 }
Пример #9
0
 /**
  * Native constructor.
  * Ensure that Type Factories use PHP Native types
  */
 public function __construct()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
 }
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = $this->getMockForAbstractClass('Chippyash\\Math\\Matrix\\Computation\\AbstractComputation');
 }
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new stubTraitAssertParameterIsRationalNumber();
 }
Пример #12
0
 public function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
 }
Пример #13
0
 public function computeMatrices()
 {
     //set required type as data is generated before tests
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     return [[[[1, 2, 3], [3, 2, 1], [2, 1, 3]], [[TypeFactory::createInt(2), TypeFactory::createInt(4), TypeFactory::createInt(6)], [TypeFactory::createInt(6), TypeFactory::createInt(4), TypeFactory::createInt(2)], [TypeFactory::createInt(4), TypeFactory::createInt(2), TypeFactory::createInt(6)]], 2], [[[1, 2, 3]], [[RationalTypeFactory::create(2.5), RationalTypeFactory::create(5.0), RationalTypeFactory::create(7.5)]], 2.5], [[[1.5, 2.5, 3.5]], [[RationalTypeFactory::create(3.0), RationalTypeFactory::create(5.0), RationalTypeFactory::create(7.0)]], 2], [[[1.12, 2.12, 3.12]], [[RationalTypeFactory::create(1.12), RationalTypeFactory::create(2.12), RationalTypeFactory::create(3.12)]], 1.0], [[[1, 2, 3]], [[TypeFactory::createInt(1), TypeFactory::createInt(2), TypeFactory::createInt(3)]], true], [[[1, 2, 3]], [[TypeFactory::createInt(0), TypeFactory::createInt(0), TypeFactory::createInt(0)]], false], [[[true, false]], [[TypeFactory::createInt(1), TypeFactory::createInt(0)]], true], [[[true, false]], [[TypeFactory::createInt(0), TypeFactory::createInt(0)]], false]];
 }
Пример #14
0
 public function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_DEFAULT);
 }
 public function correctResults()
 {
     //set required type as data created before tests are run
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     return [[1, 2, new IntType(3)], [new IntType(1), 2, new IntType(3)], [1, new IntType(2), new IntType(3)], [new IntType(1), new IntType(2), new IntType(3)], [2.0, 3.0, new FloatType(5.0)], [new FloatType(2.0), 3.0, new FloatType(5.0)], [2.0, new FloatType(3.0), new FloatType(5.0)], [new FloatType(2.0), new FloatType(3.0), new FloatType(5.0)], [new IntType(2), 3.0, new FloatType(5.0)], [new WholeIntType(2), 3, new WholeIntType(5)], [2, new WholeIntType(3), new WholeIntType(5)], [new NaturalIntType(2), 3, new NaturalIntType(5)], [2, new NaturalIntType(3), new NaturalIntType(5)], [RationalTypeFactory::create(4), RationalTypeFactory::create(4), RationalTypeFactory::create(8)]];
 }
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new GaussJordanElimination();
 }
Пример #17
0
 public function correctResults()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     return [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[1, 2, 4], [3, 6, 9], [-4, 12, 15]], [[0, '1/3', 0], ['-39/20', '107/60', '-3/20'], ['-39/10', '97/30', '-3/10']]]];
 }
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = $this->getMockForAbstractClass('Chippyash\\Math\\Matrix\\Derivative\\AbstractDerivative');
     $this->object->expects($this->any())->method('derive')->will($this->returnValue(new NumericMatrix([2])));
 }
Пример #19
0
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new CMatrix();
 }
Пример #20
0
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->sut = new MarkovRandomWalk();
 }
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = $this->getMockForAbstractClass('Chippyash\\Math\\Matrix\\Decomposition\\AbstractDecomposition');
     $this->object->expects($this->any())->method('product')->will($this->returnValue($this->object));
 }
 public function testCreationWillUseGmpAutomaticallyIfItExists()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_DEFAULT);
     $c = ComplexTypeFactory::create('2+3i');
     $this->assertInstanceOf(self::CTYPE_NAME, $c);
 }
 public function testSetNumberTypeToDefaultWillSetGmpIfAvailable()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_DEFAULT);
     $this->assertInstanceOf('Chippyash\\Type\\Number\\Rational\\GMPRationalType', TypeFactory::create('rational', 2));
 }
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->sut = new VertexDescription(new StringType('foo'));
 }
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new Invert(Invert::METHOD_DET);
 }
Пример #26
0
 public function computeMatrices()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     return [[[[1, 2, 3], [3, 2, 1], [2, 1, 3]], [[0.5, 1, 1.5], [1.5, 1, 0.5], [1, 0.5, 1.5]], 2], [[[1, 2, 3]], [[1 / 2.5, 2 / 2.5, 3 / 2.5]], 2.5], [[[1.12, 2.12, 3.12]], [[1.12, 2.12, 3.12]], 1.0], [[[1, 2, 3]], [[1, 2, 3]], true], [[[true, false]], [[1, 0]], true]];
 }
Пример #27
0
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->sut = new Cauchy();
 }
Пример #28
0
 /**
  * @requires extension gmp
  * @runInSeparateProcess
  */
 public function testCreatingFloatsViaTypeFactoryUnderGmpWillReturnGMPRationalType()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_GMP);
     $this->assertInstanceOf('Chippyash\\Type\\Number\\Rational\\GMPRationalType', TypeFactory::create('float', 2 / 3));
 }
Пример #29
0
 * set tolerance for creating rationals from floats - sqrt() function will use it.
 *
 * Try setting this to the PHP int limit i.e. 1e-17.  You will find that some
 * of the square roots cannot be computed because the limits of the mechanism
 * to convert floats to rational numbers busts the available precision and therefore
 * we get into an overflow situation.
 *
 * Setting tolerance to a lower number, say 1e-6, will compute faster but at the
 * expense of accuracy
 */
RationalTypeFactory::setDefaultFromFloatTolerance(1.0E-15);
/**
 * Set the required number type.  System will automatically use GMP if
 * it is available.  You can force it to use native PHP thus:
 */
RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
//now create 10000 numbers for the test
//try playing with this figure to see the results
$numbers = [];
for ($x = 1; $x < 10001; $x++) {
    $numbers[$x] = TypeFactory::create('int', $x);
}
//create primes
$primes = [];
$start = microtime(true);
foreach ($numbers as $key => $number) {
    $primes[$key] = $number->primeFactors();
}
$end = microtime(true);
$time = $end - $start;
echo "{$time} secs.\n";
Пример #30
0
 protected function setUp()
 {
     RequiredType::getInstance()->set(RequiredType::TYPE_NATIVE);
     $this->object = new IsNonsingular();
 }