You are here

static function Vector::wrap in Recommender API 6.2

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

Factory method. Wrap the array of numbers into the vector. Note: passing by reference!

Parameters

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

$values the array of numbers. index staring at 0, or the program will be unexpected.:

Return value

Vector

3 calls to Vector::wrap()
Matrix::row_vectors in ./Matrix.php
Only return the row vectors that have at least one element. Work for both RealMatrix and SparseMatrix
RecommenderMatrixTestCase::testVector in ./recommender.test
SparseVector::common_items in ./Matrix.php

File

./Matrix.php, line 169

Class

Vector
This is the Vector superclass. @author danithaca

Code

static function wrap($type, &$values) {

  // & required, or it will make a copy when passing.
  if ($type == 'SparseVector') {
    $vector = new SparseVector();
  }
  elseif ($type == 'RealVector') {
    $vector = new RealVector();
  }
  else {
    trigger_error('Vector type not recognized', E_USER_ERROR);
  }
  $vector->values =& $values;

  // & required, or it will make a copy here too.
  return $vector;
}