Class AbstractVector

java.lang.Object
no.uib.cipr.matrix.AbstractVector
All Implemented Interfaces:
Serializable, Iterable<VectorEntry>, Vector
Direct Known Subclasses:
DenseVector, DistVector, SparseVector

public abstract class AbstractVector extends Object implements Vector, Serializable
Partial implementation of Vector. The following methods throw UnsupportedOperationException, and should be overridden by a subclass:
  • get(int)
  • set(int,double)
  • copy

For the rest of the methods, simple default implementations using a vector iterator has been provided. There are some kernel operations which the simpler operations forward to, and they are:

  • add(double,Vector) and set(double,Vector).
  • scale(double).
  • dot(Vector) and all the norms.

Finally, a default iterator is provided by this class, which works by calling the get function. A tailored replacement should be used by subclasses.

See Also:
  • Field Details

    • size

      protected int size
      Size of the vector
  • Constructor Details

    • AbstractVector

      protected AbstractVector(int size)
      Constructor for AbstractVector.
      Parameters:
      size - Size of the vector
    • AbstractVector

      protected AbstractVector(Vector x)
      Constructor for AbstractVector, same size as x
      Parameters:
      x - Vector to get the size from
  • Method Details

    • size

      public int size()
      Description copied from interface: Vector
      Size of the vector
      Specified by:
      size in interface Vector
    • set

      public void set(int index, double value)
      Description copied from interface: Vector
      x(index) = value
      Specified by:
      set in interface Vector
    • add

      public void add(int index, double value)
      Description copied from interface: Vector
      x(index) += value
      Specified by:
      add in interface Vector
    • get

      public double get(int index)
      Description copied from interface: Vector
      Returns x(index)
      Specified by:
      get in interface Vector
    • copy

      public Vector copy()
      Description copied from interface: Vector
      Creates a deep copy of the vector
      Specified by:
      copy in interface Vector
    • check

      protected void check(int index)
      Checks the index
    • zero

      public Vector zero()
      Description copied from interface: Vector
      Zeros all the entries in the vector, while preserving any underlying structure
      Specified by:
      zero in interface Vector
    • scale

      public Vector scale(double alpha)
      Description copied from interface: Vector
      x=alpha*x
      Specified by:
      scale in interface Vector
      Returns:
      x
    • set

      public Vector set(Vector y)
      Description copied from interface: Vector
      x=y
      Specified by:
      set in interface Vector
      Returns:
      x
    • set

      public Vector set(double alpha, Vector y)
      Description copied from interface: Vector
      x=alpha*y
      Specified by:
      set in interface Vector
      Returns:
      x
    • add

      public Vector add(Vector y)
      Description copied from interface: Vector
      x = y + x
      Specified by:
      add in interface Vector
      Returns:
      x
    • add

      public Vector add(double alpha, Vector y)
      Description copied from interface: Vector
      x = alpha*y + x
      Specified by:
      add in interface Vector
      Returns:
      x
    • dot

      public double dot(Vector y)
      Description copied from interface: Vector
      xT*y
      Specified by:
      dot in interface Vector
    • checkSize

      protected void checkSize(Vector y)
      Checks for conformant sizes
    • norm

      public double norm(Vector.Norm type)
      Description copied from interface: Vector
      Computes the given norm of the vector
      Specified by:
      norm in interface Vector
      Parameters:
      type - The type of norm to compute
    • norm1

      protected double norm1()
    • norm2

      protected double norm2()
    • norm2_robust

      protected double norm2_robust()
    • normInf

      protected double normInf()
    • iterator

      public Iterator<VectorEntry> iterator()
      Specified by:
      iterator in interface Iterable<VectorEntry>
    • toString

      public String toString()
      Overrides:
      toString in class Object