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;

Implements subset view of a Matrix
 
 public class MatrixView extends AbstractMatrix {
 
   private Matrix matrix;
 
   // the offset into the Matrix
   private int[] offset;

  
Construct a view of the matrix with given offset and cardinality

Parameters:
matrix an underlying Matrix
offset the int[2] offset into the underlying matrix
size the int[2] size of the view
 
   public MatrixView(Matrix matrixint[] offsetint[] size) {
     super(size[], size[]);
     int rowOffset = offset[];
     if (rowOffset < 0) {
       throw new IndexException(rowOffsetrowSize());
     }
 
     int rowsRequested = size[];
     if (rowOffset + rowsRequested > matrix.rowSize()) {
       throw new IndexException(rowOffset + rowsRequestedmatrix.rowSize());
     }
 
     int columnOffset = offset[];
     if (columnOffset < 0) {
       throw new IndexException(columnOffsetcolumnSize());
     }
 
     int columnsRequested = size[];
     if (columnOffset + columnsRequested > matrix.columnSize()) {
       throw new IndexException(columnOffset + columnsRequestedmatrix.columnSize());
     }
     this. = matrix;
     this. = offset;
   }
 
   @Override
   public Matrix clone() {
     MatrixView clone = (MatrixViewsuper.clone();
     clone.matrix = .clone();
     clone.offset = .clone();
     return clone;
   }
 
   @Override
   public double getQuick(int rowint column) {
     return .getQuick([] + row[] + column);
   }
 
   @Override
   public Matrix like() {
     return .like(rowSize(), columnSize());
   }
 
   @Override
   public Matrix like(int rowsint columns) {
     return .like(rowscolumns);
   }
 
   @Override
   public void setQuick(int rowint columndouble value) {
     .setQuick([] + row[] + columnvalue);
   }
 
   @Override
   public int[] getNumNondefaultElements() {
     return new int[]{rowSize(), columnSize()};
 
   }
 
   @Override
   public Matrix viewPart(int[] offsetint[] size) {
     if (offset[] < 0) {
       throw new IndexException(offset[], 0);
     }
     if (offset[] + size[] > rowSize()) {
      throw new IndexException(offset[] + size[], rowSize());
    }
    if (offset[] < 0) {
      throw new IndexException(offset[], 0);
    }
    if (offset[] + size[] > columnSize()) {
      throw new IndexException(offset[] + size[], columnSize());
    }
    int[] origin = this..clone();
    origin[] += offset[];
    origin[] += offset[];
    return new MatrixView(originsize);
  }
  public Matrix assignColumn(int columnVector other) {
    if (rowSize() != other.size()) {
      throw new CardinalityException(rowSize(), other.size());
    }
    for (int row = 0; row < rowSize(); row++) {
      .setQuick(row + [], column + [], other
          .getQuick(row));
    }
    return this;
  }
  public Matrix assignRow(int rowVector other) {
    if (columnSize() != other.size()) {
      throw new CardinalityException(columnSize(), other.size());
    }
    for (int col = 0; col < columnSize(); col++) {
      
          .setQuick(row + [], col + [], other.getQuick(col));
    }
    return this;
  }
  public Vector viewColumn(int column) {
    if (column < 0 || column >= columnSize()) {
      throw new IndexException(columncolumnSize());
    }
    return new VectorView(.viewColumn(column + []), [], rowSize());
  }
  public Vector viewRow(int row) {
    if (row < 0 || row >= rowSize()) {
      throw new IndexException(rowrowSize());
    }
    return new VectorView(.viewRow(row + []), [], columnSize());
  }
New to GrepCode? Check out our FAQ X