本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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());
}
示例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));
}
}
}
示例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());
}
示例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;
}
示例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;
}
}
示例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());
}
示例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);
}
}
示例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 );
}
示例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]);
}
}
示例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]);
}
}
示例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());
}
示例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');
});
}