## org.apache.mahout.math
Class RandomAccessSparseVector

    java.lang.Object
      org.apache.mahout.math.AbstractVector
          org.apache.mahout.math.RandomAccessSparseVector

All Implemented Interfaces:
  Cloneable, Vector

    public class RandomAccessSparseVector

extends AbstractVector

Implements vector that only stores non-zero doubles

Nested Class Summary

Nested classes/interfaces inherited from class org.apache.mahout.math.AbstractVector
`AbstractVector.LocalElement`

Nested classes/interfaces inherited from interface org.apache.mahout.math.Vector
`Vector.Element`

Field Summary

Fields inherited from class org.apache.mahout.math.AbstractVector
`lengthSquared`

Constructor Summary
`RandomAccessSparseVector()` For serialization purposes only.
`RandomAccessSparseVector(int cardinality)`
`RandomAccessSparseVector(int cardinality, int initialCapacity)`
`RandomAccessSparseVector(RandomAccessSparseVector other, boolean shallowCopy)`
`RandomAccessSparseVector(Vector other)`

Method Summary
`Vector` `assign(Vector other)` Assign the other vector values to the receiver
`RandomAccessSparseVector` `clone()` Return a copy of the recipient
`double` `getIteratorAdvanceCost()` Gets an estimate of the cost (in number of operations) it takes to advance an iterator through the nonzero elements of this vector.
`double` `getLookupCost()` Gets an estimate of the cost (in number of operations) it takes to lookup a random element in this vector.
`int` `getNumNondefaultElements()` Return the number of values in the recipient which are not the default value.
`double` `getQuick(int index)` Return the value at the given index, without checking bounds
`void` `incrementQuick(int index, double increment)` Increment the value at the given index by the given value.
`boolean` `isAddConstantTime()` This is "sort of" constant, but really it might resize the array.
`boolean` `isDense()`
`boolean` `isSequentialAccess()`
`Iterator<Vector.Element>` `iterateNonZero()` NOTE: this implementation reuses the Vector.Element instance for each call of next().
`Iterator<Vector.Element>` `iterator()` 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
`RandomAccessSparseVector` `like()` Return an empty vector of the same underlying class as the receiver
`protected Matrix` `matrixLike(int rows, int columns)` Subclasses must override to return an appropriately sparse or dense result
`void` `mergeUpdates(OrderedIntDoubleMapping updates)` Merge a set of (index, value) pairs into the vector.
`void` `setQuick(int index, double value)` Set the value at the given index, without checking bounds
`String` `toString()`

Methods inherited from class org.apache.mahout.math.AbstractVector

`aggregate, aggregate, all, asFormatString, assign, assign, assign, assign, assign, createOptimizedCopy, cross, divide, dot, dotSelf, equals, get, getDistanceSquared, getElement, getLengthSquared, getNumNonZeroElements, hashCode, invalidateCachedLength, logNormalize, logNormalize, logNormalize, maxValue, maxValueIndex, minus, minValue, minValueIndex, nonZeroes, norm, normalize, normalize, plus, plus, set, size, sparseVectorToString, times, times, toString, viewPart, zSum`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### RandomAccessSparseVector

    public RandomAccessSparseVector()

  For serialization purposes only.

### RandomAccessSparseVector

    public RandomAccessSparseVector(int cardinality)

### RandomAccessSparseVector

    public RandomAccessSparseVector(int cardinality,
                                    int initialCapacity)

### RandomAccessSparseVector

    public RandomAccessSparseVector(Vector other)

### RandomAccessSparseVector

    public RandomAccessSparseVector(RandomAccessSparseVector other,
                                    boolean shallowCopy)

Method Detail

### matrixLike

    protected Matrix matrixLike(int rows,
                                int columns)

  Description copied from class: `AbstractVector`
  Subclasses must override to return an appropriately sparse or dense result

  Specified by:
    `matrixLike` in class `AbstractVector`
  Parameters:
    `rows` - the row cardinality
    `columns` - the column cardinality
  Returns:
    a Matrix

### clone

    public RandomAccessSparseVector clone()

  Description copied from interface: `Vector`
  Return a copy of the recipient

  Specified by:
    `clone` in interface `Vector`
  Overrides:
    `clone` in class `AbstractVector`
  Returns:
    a new Vector

### toString

    public String toString()

  Overrides:
    `toString` in class `AbstractVector`

### assign

    public Vector assign(Vector other)

  Description copied from interface: `Vector`
  Assign the other vector values to the receiver

  Specified by:
    `assign` in interface `Vector`
  Overrides:
    `assign` in class `AbstractVector`
  Parameters:
    `other` - a Vector
  Returns:
    the modified receiver

### mergeUpdates

    public void mergeUpdates(OrderedIntDoubleMapping updates)

  Description copied from interface: `Vector`
  Merge a set of (index, value) pairs into the vector.

  Parameters:
    `updates` - an ordered mapping of indices to values to be merged in.

### isDense

    public boolean isDense()

  Returns:
    false

### isSequentialAccess

    public boolean isSequentialAccess()

  Returns:
    false

### getQuick

    public double getQuick(int index)

  Description copied from interface: `Vector`
  Return the value at the given index, without checking bounds

  Parameters:
    `index` - an int index
  Returns:
    the double at the index

### setQuick

    public void setQuick(int index,
                         double value)

  Description copied from interface: `Vector`
  Set the value at the given index, without checking bounds

  Parameters:
    `index` - an int index into the receiver
    `value` - a double value to set

### incrementQuick

    public void incrementQuick(int index,
                               double increment)

  Description copied from interface: `Vector`
  Increment the value at the given index by the given value.

  Specified by:
    `incrementQuick` in interface `Vector`
  Overrides:
    `incrementQuick` in class `AbstractVector`
  Parameters:
    `index` - an int index into the receiver
    `increment` - sets the value at the given index to value + increment;

### like

    public RandomAccessSparseVector like()

  Description copied from interface: `Vector`
  Return an empty vector of the same underlying class as the receiver

  Returns:
    a Vector

### getNumNondefaultElements

    public int getNumNondefaultElements()

  Description copied from interface: `Vector`
  Return the number of values in the recipient which are not the default value. For instance, for a sparse vector, this would be the number of non-zero values.

  Returns:
    an int

### getLookupCost

    public double getLookupCost()

  Description copied from interface: `Vector`
  Gets an estimate of the cost (in number of operations) it takes to lookup a random element in this vector.

### getIteratorAdvanceCost

    public double getIteratorAdvanceCost()

  Description copied from interface: `Vector`
  Gets an estimate of the cost (in number of operations) it takes to advance an iterator through the nonzero elements of this vector.

### isAddConstantTime

    public boolean isAddConstantTime()

  This is "sort of" constant, but really it might resize the array.

### iterateNonZero

    public Iterator<Vector.Element> iterateNonZero()

  NOTE: this implementation reuses the Vector.Element instance for each call of next(). If you need to preserve the instance, you need to make a copy of it

  Specified by:
    `iterateNonZero` in class `AbstractVector`
  Returns:
    an `Iterator` over the Elements.
  See Also:
    `AbstractVector.getElement(int)`

### iterator

    public Iterator<Vector.Element> iterator()

  Description copied from class: `AbstractVector`
  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

  Specified by:
    `iterator` in class `AbstractVector`
  Returns:
    An `Iterator` over all elements

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.