You are here

static function Vector::wrap in Recommender API 7.6

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

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

File

classes/Matrix.php, line 164

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