You are here

function Matrix::row_vectors in Recommender API 6.2

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

Only return the row vectors that have at least one element. Work for both RealMatrix and SparseMatrix

Return value

unknown_type

File

./Matrix.php, line 72

Class

Matrix
This PHP file has to work with Drupal. Including both Matrix and Vector implementation. Missing data are treated as NAN. Some extra complexity comes from trying to increase memory/cpu performance Note, this implementation does check input parameters.…

Code

function row_vectors() {

  // $this could be either RealMatrix or SparseMatrix
  $type = $this instanceof RealMatrix ? 'RealVector' : 'SparseVector';
  $vectors = array();
  foreach ($this->values as $row_i => &$row_value) {
    $vectors[$row_i] = Vector::wrap($type, $row_value);

    // note, by default this is passing by reference.
  }
  return $vectors;

  // don't have to return by reference.
  // Do not use return-by-reference to increase performance. The engine will automatically optimize this on its own. Only return references when you have a valid technical reason to do so.
}