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;
 
 
Provides a permuted view of a vector.
 
 public class PermutedVectorView extends AbstractVector {
   private final Vector vector;            // the vector containing the data
   private final int[] pivot;              // convert from external index to internal
   private final int[] unpivot;            // convert from internal index to external
 
   public PermutedVectorView(Vector vectorint[] pivotint[] unpivot) {
     super(vector.size());
     this. = vector;
     this. = pivot;
     this. = unpivot;
   }
 
   public PermutedVectorView(Vector vectorint[] pivot) {
     this(vectorpivotreversePivotPermutation(pivot));
   }
 
   private static int[] reversePivotPermutation(int[] pivot) {
     int[] unpivot1 = new int[pivot.length];
     for (int i = 0; i < pivot.lengthi++) {
       unpivot1[pivot[i]] = i;
     }
     return unpivot1;
   }

  
Subclasses must override to return an appropriately sparse or dense result

Parameters:
rows the row cardinality
columns the column cardinality
Returns:
a Matrix
 
   @Override
   protected Matrix matrixLike(int rowsint columns) {
     if (.isDense()) {
       return new DenseMatrix(rowscolumns);
     } else {
       return new SparseRowMatrix(rowscolumns);
     }
   }

  
Used internally by assign() to update multiple indices and values at once. Only really useful for sparse vectors (especially SequentialAccessSparseVector).

If someone ever adds a new type of sparse vectors, this method must merge (index, value) pairs into the vector.

Parameters:
updates a mapping of indices to values to merge in the vector.
 
   @Override
   public void mergeUpdates(OrderedIntDoubleMapping updates) {
     for (int i = 0; i < updates.getNumMappings(); ++i) {
       updates.setIndexAt(i[updates.indexAt(i)]);
     }
     .mergeUpdates(updates);
   }

  

Returns:
true iff this implementation should be considered dense -- that it explicitly represents every value
 
   @Override
   public boolean isDense() {
     return .isDense();
   }

  
If the view is permuted, the elements cannot be accessed in the same order.

Returns:
true iff this implementation should be considered to be iterable in index order in an efficient way. In particular this implies that iterator() and iterateNonZero() return elements in ascending order by index.
 
   @Override
  public boolean isSequentialAccess() {
    return false;
  }

  
Iterates over all elements

* NOTE: Implementations may choose to reuse the Element returned for performance reasons, so if you need a copy of it, you should call AbstractVector.getElement(int) for the given index

Returns:
An java.util.Iterator over all elements
  public Iterator<Elementiterator() {
    return new AbstractIterator<Element>() {
      private final Iterator<Elementi = .all().iterator();
      @Override
      protected Vector.Element computeNext() {
        if (.hasNext()) {
          final Element x = .next();
          return new Element() {
            private final int index = [x.index()];
            @Override
            public double get() {
              return x.get();
            }
            @Override
            public int index() {
              return ;
            }
            @Override
            public void set(double value) {
              x.set(value);
            }
          };
        } else {
          return endOfData();
        }
      }
    };
  }

  
Iterates over all non-zero elements.

NOTE: Implementations may choose to reuse the Element returned for performance reasons, so if you need a copy of it, you should call AbstractVector.getElement(int) for the given index

Returns:
An java.util.Iterator over all non-zero elements
    return new AbstractIterator<Element>() {
      private final Iterator<Elementi = .nonZeroes().iterator();
      @Override
      protected Vector.Element computeNext() {
        if (.hasNext()) {
          final Element x = .next();
          return new Element() {
            private final int index = [x.index()];
            @Override
            public double get() {
              return x.get();
            }
            @Override
            public int index() {
              return ;
            }
            @Override
            public void set(double value) {
              x.set(value);
            }
          };
        } else {
          return endOfData();
        }
      }
    };
  }

  
Return the value at the given index, without checking bounds

Parameters:
index an int index
Returns:
the double at the index
  public double getQuick(int index) {
    return .getQuick([index]);
  }

  
Return an empty vector of the same underlying class as the receiver

Returns:
a Vector
  public Vector like() {
    return .like();
  }

  
Set the value at the given index, without checking bounds

Parameters:
index an int index into the receiver
value a double value to set
  public void setQuick(int indexdouble value) {
    .setQuick([index], value);
  }

  
Return the number of values in the recipient

Returns:
an int
  public int getNumNondefaultElements() {
  }
  public double getLookupCost() {
    return .getLookupCost();
  }
  public double getIteratorAdvanceCost() {
  }
  public boolean isAddConstantTime() {
    return .isAddConstantTime();
  }
New to GrepCode? Check out our FAQ X