You are here

static function Vector::create in Recommender API 7.6

Same name and namespace in other branches
  1. 6.2 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

File

classes/Matrix.php, line 143

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;
}