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 a vector with all the same values.
 
 public class ConstantVector extends AbstractVector {
   private final double value;
 
   public ConstantVector(double valueint size) {
     super(size);
     this. = value;
   }

  
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) {
     return new DenseMatrix(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) {
     throw new UnsupportedOperationException("Cannot mutate a ConstantVector");
   }

  

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

  

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

  
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
 
   @Override
   public Iterator<Elementiterator() {
     return new AbstractIterator<Element>() {
       private int i = 0;
       private final int n = size();
       @Override
       protected Element computeNext() {
         if ( < ) {
           return new LocalElement(++);
         } 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 iterator();
  }

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

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

Returns:
a Vector
  public Vector like() {
    return new DenseVector(size());
  }

  
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) {
    throw new UnsupportedOperationException("Can't set a value in a constant matrix");
  }

  
Return the number of values in the recipient

Returns:
an int
  public int getNumNondefaultElements() {
    return size();
  }
  public double getLookupCost() {
    return 1;
  }
  public double getIteratorAdvanceCost() {
    return 1;
  }
  public boolean isAddConstantTime() {
    throw new UnsupportedOperationException("Cannot mutate a ConstantVector");
  }
New to GrepCode? Check out our FAQ X