当前位置: 首页>>代码示例>>PHP>>正文


PHP Matrix类代码示例

本文整理汇总了PHP中Matrix的典型用法代码示例。如果您正苦于以下问题:PHP Matrix类的具体用法?PHP Matrix怎么用?PHP Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compute

 /**
  * Return all possibility for the matrix
  *
  * @return array
  */
 public function compute()
 {
     $dimensions = $this->dimensions;
     if (empty($dimensions)) {
         return array();
     }
     // Pop first dimension
     $values = reset($dimensions);
     $name = key($dimensions);
     unset($dimensions[$name]);
     // Create all possiblites for the first dimension
     $posibilities = array();
     foreach ($values as $v) {
         $posibilities[] = array($name => $v);
     }
     // If only one dimension return simple all the possibilites created (break point of recursivity)
     if (empty($dimensions)) {
         return $posibilities;
     }
     // If not create a new matrix with remaining dimension
     $matrix = new Matrix();
     foreach ($dimensions as $name => $values) {
         $matrix->setDimension($name, $values);
     }
     $result = $matrix->compute();
     $newResult = array();
     foreach ($result as $value) {
         foreach ($posibilities as $possiblity) {
             $newResult[] = $value + $possiblity;
         }
     }
     return $newResult;
 }
开发者ID:Chris7,项目名称:JoliCi,代码行数:38,代码来源:Matrix.php

示例2: getD

 /**
  * Get D - the diagonal matrix.
  * 
  * @return  matrix  D
  */
 public function getD()
 {
     $D = new Matrix($this->_matrix->rows(), $this->_matrix->columns());
     for ($i = 0; $i < $D->rows(); $i++) {
         $D->set($i, $i, $this->_matrix->get($i, $i));
     }
     return $D;
 }
开发者ID:hoenirvili,项目名称:cn,代码行数:13,代码来源:Cholesky.php

示例3: testShouldReturnOne

 public function testShouldReturnOne()
 {
     $matrix = new Matrix();
     $matrix->setSize(5);
     $matrix->setValues(array(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5));
     $analyzer = new MatrixAnalyzer();
     $analyzer->getGreaterProduct($matrix);
 }
开发者ID:amaivsimau,项目名称:dojos,代码行数:8,代码来源:MatrixAnalyzerTest.php

示例4: testConstructor

 /**
  * @dataProvider dataProviderForConstructor
  */
 public function testConstructor(array $M, array $V)
 {
     $R = new RowVector($M);
     $V = new Matrix($V);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\RowVector', $R);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $R);
     $this->assertEquals($V[0], $R[0]);
     $this->assertEquals(1, $V->getM());
     $this->assertEquals(count($M), $V->getN());
 }
开发者ID:markrogoyski,项目名称:math-php,代码行数:13,代码来源:RowVectorTest.php

示例5: testMatrixGetReturnsCorrectValue

 public function testMatrixGetReturnsCorrectValue()
 {
     $testArray = array(array(1, 2, 3), array(0, 2, 1), array(2.5, 1, 3));
     $this->object = new RationalMatrix($testArray);
     for ($r = 1; $r < 4; $r++) {
         for ($c = 1; $c < 4; $c++) {
             $this->assertEquals(RationalTypeFactory::create($testArray[$r - 1][$c - 1]), $this->object->get($r, $c));
         }
     }
 }
开发者ID:chippyash,项目名称:math-matrix,代码行数:10,代码来源:RationalMatrixTest.php

示例6: testJackingAHumanIncreasesTheCount

 public function testJackingAHumanIncreasesTheCount()
 {
     $human = $this->getMock('Human', null, array(), 'MockHuman', null, false);
     $humanFactory = $this->getMock('HumanFactory');
     $humanFactory->expects($this->once())->method('create')->will($this->returnValue($human));
     $matrix = new Matrix();
     $matrix->setHumanFactory($humanFactory);
     $expectedCount = $matrix->count();
     $matrix->jackIn('robin');
     $this->assertEquals($expectedCount + 1, $matrix->count());
 }
开发者ID:nottrobin,项目名称:tdd-training-exercises,代码行数:11,代码来源:MatrixTest.php

示例7: multiplicationScalar

 public function multiplicationScalar($multiplier)
 {
     $result = new Matrix($this->matrix->getNumRows(), $this->matrix->getNumCols(), $this->precision);
     for ($row = 1; $row <= $this->matrix->getNumRows(); $row++) {
         for ($col = 1; $col <= $this->matrix->getNumCols(); $col++) {
             $newValue = bcmul($this->matrix->getPoint($row, $col), $multiplier, $this->precision);
             $result->setPoint($row, $col, $newValue);
         }
     }
     return $result;
 }
开发者ID:skilla,项目名称:matrix,代码行数:11,代码来源:Operations.php

示例8: _construct_view_matrix

 private function _construct_view_matrix(Vertex $origin, Matrix $orientation)
 {
     $this->_origin = $origin;
     $this->_tT = new Matrix(array('preset' => Matrix::TRANSLATION, 'vtc' => (new Vector(array('dest' => $origin)))->opposite()));
     $this->_tR = $orientation->transpose();
     print $this->_tT;
     print $this->_tR;
     $this->_view_matrix = $this->_tR->mult($this->_tT);
     if (self::$verbose) {
         echo "Camera instance constructed." . PHP_EOL;
     }
 }
开发者ID:eXcomm,项目名称:3D-PHP-Class,代码行数:12,代码来源:Camera.class.php

示例9: testConstructor

 /**
  * @dataProvider dataProviderForConstructor
  */
 public function testConstructor(array $M, array $V)
 {
     $C = new ColumnVector($M);
     $V = new Matrix($V);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\ColumnVector', $C);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $C);
     foreach ($M as $row => $value) {
         $this->assertEquals($value, $V[$row][0]);
     }
     $this->assertEquals(count($M), $V->getM());
     $this->assertEquals(1, $V->getN());
 }
开发者ID:markrogoyski,项目名称:math-php,代码行数:15,代码来源:ColumnVectorTest.php

示例10: testCompute

 public function testCompute()
 {
     $matrix = new Matrix();
     $matrix->setDimension('a', array(1, 2, 3));
     $matrix->setDimension('b', array(1, 2, 3));
     $matrix->setDimension('c', array(1, 2, 3));
     $possibilities = $matrix->compute();
     $expected = array(array('a' => 1, 'b' => 1, 'c' => 1), array('a' => 1, 'b' => 1, 'c' => 2), array('a' => 1, 'b' => 1, 'c' => 3), array('a' => 1, 'b' => 2, 'c' => 1), array('a' => 1, 'b' => 2, 'c' => 2), array('a' => 1, 'b' => 2, 'c' => 3), array('a' => 1, 'b' => 3, 'c' => 1), array('a' => 1, 'b' => 3, 'c' => 2), array('a' => 1, 'b' => 3, 'c' => 3), array('a' => 2, 'b' => 1, 'c' => 1), array('a' => 2, 'b' => 1, 'c' => 2), array('a' => 2, 'b' => 1, 'c' => 3), array('a' => 2, 'b' => 2, 'c' => 1), array('a' => 2, 'b' => 2, 'c' => 2), array('a' => 2, 'b' => 2, 'c' => 3), array('a' => 2, 'b' => 3, 'c' => 1), array('a' => 2, 'b' => 3, 'c' => 2), array('a' => 2, 'b' => 3, 'c' => 3), array('a' => 3, 'b' => 1, 'c' => 1), array('a' => 3, 'b' => 1, 'c' => 2), array('a' => 3, 'b' => 1, 'c' => 3), array('a' => 3, 'b' => 2, 'c' => 1), array('a' => 3, 'b' => 2, 'c' => 2), array('a' => 3, 'b' => 2, 'c' => 3), array('a' => 3, 'b' => 3, 'c' => 1), array('a' => 3, 'b' => 3, 'c' => 2), array('a' => 3, 'b' => 3, 'c' => 3));
     $this->assertCount(count($expected), $possibilities);
     foreach ($expected as $value) {
         $this->assertContains($value, $possibilities);
     }
 }
开发者ID:beberlei,项目名称:JoliCi,代码行数:13,代码来源:MatrixTest.php

示例11: polyfit

function polyfit($X, $Y, $n) {
	for($i = 0; $i < sizeof ( $X ); ++ $i)
		for($j = 0; $j <= $n; ++ $j)
			$A [$i] [$j] = pow ( $X [$i], $j );
	for($i = 0; $i < sizeof ( $Y ); ++ $i)
		$B [$i] = array (
				$Y [$i] 
		);
	$matrixA = new Matrix ( $A );
	$matrixB = new Matrix ( $B );
	$C = $matrixA->solve ( $matrixB );
	return $C->getMatrix ( 0, $n, 0, 1 );
}
开发者ID:nanpeixoto,项目名称:cide,代码行数:13,代码来源:polyfit.php

示例12: testConstructor

 /**
  * @dataProvider dataProviderMulti
  */
 public function testConstructor(array $A, array $R)
 {
     $D = new DiagonalMatrix($A);
     $R = new Matrix($R);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\DiagonalMatrix', $D);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $D);
     $m = $D->getM();
     for ($i = 0; $i < $m; $i++) {
         $this->assertEquals($R[$i], $D[$i]);
     }
     $m = $R->getM();
     for ($i = 0; $i < $m; $i++) {
         $this->assertEquals($R[$i], $D[$i]);
     }
 }
开发者ID:markrogoyski,项目名称:math-php,代码行数:18,代码来源:DiagonalMatrixTest.php

示例13: testConstructor

 /**
  * @dataProvider dataProviderForTestConstructor
  */
 public function testConstructor($M, int $n, $V)
 {
     $M = new VandermondeMatrix($M, $n);
     $V = new Matrix($V);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\VandermondeMatrix', $M);
     $this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $M);
     $m = $V->getM();
     for ($i = 0; $i < $m; $i++) {
         $this->assertEquals($V[$i], $M[$i]);
     }
     $m = $M->getM();
     for ($i = 0; $i < $m; $i++) {
         $this->assertEquals($V[$i], $M[$i]);
     }
 }
开发者ID:markrogoyski,项目名称:math-php,代码行数:18,代码来源:VandermondeMatrixTest.php

示例14: testMap

    public function testMap()
    {
        $callback = function ($elem) {
            return $elem * 2;
        };
        $c = MatrixFactory::fromString('2, 4;
			 6, 8');
        $this->assertEquals($c->getArray(), $this->B->map($callback)->getArray());
    }
开发者ID:nosun,项目名称:Matrix,代码行数:9,代码来源:matrix_test.php

示例15: ensureLoaded

 /**
  * 确保已经加载了配置
  */
 public function ensureLoaded()
 {
     Lazy::init($this->_items, function () {
         /** @var CDbConnection $db */
         $db = Yii::app()->db;
         $items = $db->createCommand()->select(array('key', 'value'))->from('t_config')->queryAll();
         return Matrix::from($items)->indexedBy('key')->column('value');
     });
 }
开发者ID:Clarence-pan,项目名称:org-wiki,代码行数:12,代码来源:Config.php


注:本文中的Matrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。