Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.mahout.math;

sparse matrix with general element values whose columns are accessible quickly. Implemented as a column array of SparseVectors.
 
 public class SparseColumnMatrix extends AbstractMatrix {
 
   private Vector[] columnVectors;

  
Construct a matrix of the given cardinality with the given data columns

Parameters:
columns a RandomAccessSparseVector[] array of columns
columnVectors
 
   public SparseColumnMatrix(int rowsint columnsRandomAccessSparseVector[] columnVectors) {
     super(rowscolumns);
     this. = columnVectors.clone();
     for (int col = 0; col < columnSize(); col++) {
       this.[col] = this.[col].clone();
     }
   }

  
Construct a matrix of the given cardinality

Parameters:
rows
columns
 
   public SparseColumnMatrix(int rowsint columns) {
     super(rowscolumns);
     for (int col = 0; col < columnSize(); col++) {
       this.[col] = new RandomAccessSparseVector(rowSize());
     }
   }
 
   @Override
   public Matrix clone() {
     SparseColumnMatrix clone = (SparseColumnMatrixsuper.clone();
     clone.columnVectors = new Vector[.];
     for (int i = 0; i < .i++) {
       clone.columnVectors[i] = [i].clone();
     }
     return clone;
   }

  
Abstracted out for the iterator

 
   @Override
   public int numSlices() {
     return numCols();
   }
 
   @Override
   public double getQuick(int rowint column) {
     return [column] == null ? 0.0 : [column].getQuick(row);
   }
 
   @Override
   public Matrix like() {
     return new SparseColumnMatrix(rowSize(), columnSize());
   }
 
   @Override
   public Matrix like(int rowsint columns) {
     return new SparseColumnMatrix(rowscolumns);
   }
 
   @Override
   public void setQuick(int rowint columndouble value) {
     if ([column] == null) {
       [column] = new RandomAccessSparseVector(rowSize());
     }
     [column].setQuick(rowvalue);
   }
 
   @Override
   public int[] getNumNondefaultElements() {
    int[] result = new int[2];
    result[] = .;
    for (int col = 0; col < columnSize(); col++) {
      result[] = Math.max(result[], [col]
          .getNumNondefaultElements());
    }
    return result;
  }
  public Matrix viewPart(int[] offsetint[] size) {
    if (offset[] < 0) {
      throw new IndexException(offset[], [].size());
    }
    if (offset[] + size[] > [].size()) {
      throw new IndexException(offset[] + size[], [].size());
    }
    if (offset[] < 0) {
      throw new IndexException(offset[], .);
    }
    if (offset[] + size[] > .) {
      throw new IndexException(offset[] + size[], .);
    }
    return new MatrixView(thisoffsetsize);
  }
  public Matrix assignColumn(int columnVector other) {
    if (rowSize() != other.size()) {
      throw new CardinalityException(rowSize(), other.size());
    }
    if (column < 0 || column >= columnSize()) {
      throw new IndexException(columncolumnSize());
    }
    [column].assign(other);
    return this;
  }
  public Matrix assignRow(int rowVector other) {
    if (columnSize() != other.size()) {
      throw new CardinalityException(columnSize(), other.size());
    }
    if (row < 0 || row >= rowSize()) {
      throw new IndexException(rowrowSize());
    }
    for (int col = 0; col < columnSize(); col++) {
      [col].setQuick(rowother.getQuick(col));
    }
    return this;
  }
  public Vector viewColumn(int column) {
    if (column < 0 || column >= columnSize()) {
      throw new IndexException(columncolumnSize());
    }
    return [column];
  }
New to GrepCode? Check out our FAQ X