You are here

static function Vector::create in Recommender API 6.2

Same name and namespace in other branches
  1. 7.6 classes/Matrix.php \Vector::create()

Factory method to create a vector. Note, no parameter checking. Array index has to be [0..n), otherwise program unstable

Parameters

$type Create a sparse vector or a real vector. Could be 'SparseVector' or 'RealVector':

$size:

$value:

Return value

unknown_type

1 call to Vector::create()
RecommenderMatrixTestCase::testVector in ./recommender.test

File

./Matrix.php, line 148

Class

Vector
This is the Vector superclass. @author danithaca

Code

static function create($type, $size = 0, $value = 0) {
  if ($type == 'SparseVector') {
    $vector = new SparseVector();
    $vector->values = array();
  }
  elseif ($type == 'RealVector') {
    $vector = new RealVector();
    $vector->count = $size;
    $vector->values = array_fill(0, $size, $value);
  }
  else {
    trigger_error('Vector type not recognized', E_USER_ERROR);
  }
  return $vector;
}