ru.sscc.util.data
Class RealContainer

java.lang.Object
  |
  +--ru.sscc.util.data.RealContainer
Direct Known Subclasses:
DoubleContainer, FloatContainer

public abstract class RealContainer
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This abstract class implements Cloneable and Serializable interfaces for real data container which is an array of the float[] or double[] type. The main use of this class is a container for matrix entries. Internal inner products and some other methods are added to this class for the efficiency reasons.

See Also:
Serialized Form

Field Summary
protected static java.lang.String CANT_MOVE_VECTOR
           
 
Constructor Summary
RealContainer()
           
 
Method Summary
abstract  double add(int index, double value)
          Adds the value to the container's entry.
abstract  void addVector(int index1, int step1, int index2, int step2, double factor, int count)
          Operation vector1 += factor * vector2 upon the vectors stored in the container.
abstract  void assign(int index1, int step1, int index2, int step2, int count)
          Assignment vector1 = vector2 when both vectors are stored in the container.
static RealContainer by(java.lang.Object obj)
          Static service method which creates RealContainer upon an object convertable to it (double[], float[], or RealContainer instance).
 java.lang.Object clone()
          Clones the container.
 void ensureSize(int size)
          Tests a container size to be not less that specified size and throws the IllegalArgumentException if not.
abstract  double get(int index)
          Gets the value of a container entry.
abstract  java.lang.Object getData()
          Returns the data container encapsulated in the object (instance of double[] or float[] type).
abstract  RealPointer getPointer()
          Gets a pointer to the beginning of the container with the unit increment.
 RealPointer getPointer(int index, int step)
          Gets a pointer and resets it for sequential access to the container entries starting from the index position with the step increment.
 RealVector getVector()
          Gets RealVector consisting of all container entries.
abstract  RealVector getVector(int index, int step, int length)
          Creates a vector within the real container.
abstract  int indexOfNormMax(int index, int step, int count)
          Calculates the index of the first entry having the maximum module for the vector stored in the container.
abstract  void moveVector(RealVector vector, int newStartIndex)
          Moves the starting index of vector created upon this container to a new location in the container.
abstract  double mul(int index, double value)
          Multiplies the container's entry by the value.
abstract  void multiply(int index, int step, double value, int count)
          Multiplies the vector posed in the container on a value.
abstract  RealContainer newContainer(int size)
          Creates a new container of the same type with the required size.
abstract  double normalize(int index, int step, double value, int count)
          Multiplies the vector posed in the container on a value and calculates its sum-norm.
abstract  double normMax(int index, int step, int count)
          Calculates the maximum modules norm of the vector stored in the container.
abstract  double normSum(int index, int step, int count)
          Calculates the sum of modules norm of the vector stored in the container.
abstract  double postProduct(int index1, int step1, int index2, int step2, int count)
          Calculates an inner product of two vectors distributed within the container with post-increment of starting indices.
abstract  double postProduct(int index, int step, RealPointer vec, int count)
          Calculates an inner product of two vectors with post-increment of starting indices.
abstract  double preProduct(int index1, int step1, int index2, int step2, int count)
          Calculates an inner product of two vectors distributed within the container with pre-increment of starting indices.
abstract  double preProduct(int index, int step, RealPointer vec, int count)
          Calculates an inner product of two vectors with pre-increment of starting indices.
abstract  double relativeAccuracy()
          Returns the relative accuracy: smallest value e such that 1+e isn't equal to 1 for the data type used in the container.
abstract  void resize(int newSize)
          Changes size of the container to a new size.
abstract  void rotate(double cos, double sin, int index1, int step1, int index2, int step2, int count)
          Rotates two container's vectors with the Givens rotataion by the formulas v1' = v1*cos(a) + v2*sin(a), v2' = -v1*sin(a) + v2*cos(a).
abstract  double set(int index, double value)
          Sets the value of a container entry.
 void shiftVector(RealVector vector, int startIndexIncrement)
          Shifts the starting index of vector created upon this container by a specified increment.
abstract  int size()
          Gets the container size.
abstract  void swap(int index1, int step1, int index2, int step2, int count)
          Swaps entries of vector1 with corresponding entries of vector2 for the vectors stored in the container.
abstract  double weightedNormMax(int index, int step, RealPointer weight, int count)
          Calculates the weighted maximum modules norm of the vector stored in the container.
abstract  double weightedNormSum(int index, int step, RealPointer weight, int count)
          Calculates the weighted sum of modules norm of the vector stored in the container.
abstract  double weightedProduct(int index1, int step1, int index2, int step2, RealPointer weight, int count)
          Calculates a weighted inner product of two vectors distributed within the container.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CANT_MOVE_VECTOR

protected static final java.lang.String CANT_MOVE_VECTOR
Constructor Detail

RealContainer

public RealContainer()
Method Detail

by

public static RealContainer by(java.lang.Object obj)
Static service method which creates RealContainer upon an object convertable to it (double[], float[], or RealContainer instance). In the last case the same object will be returned.

size

public abstract int size()
Gets the container size.

ensureSize

public final void ensureSize(int size)
Tests a container size to be not less that specified size and throws the IllegalArgumentException if not.
Parameters:
size - a minimum size needed

resize

public abstract void resize(int newSize)
Changes size of the container to a new size. The old container contents is copied to the new one.

newContainer

public abstract RealContainer newContainer(int size)
Creates a new container of the same type with the required size.

get

public abstract double get(int index)
Gets the value of a container entry.
Parameters:
index - an entry position in the container
Returns:
an entry value at the required position

set

public abstract double set(int index,
                           double value)
Sets the value of a container entry.
Parameters:
index - an entry position in the container
value - a value to set
Returns:
the set value

add

public abstract double add(int index,
                           double value)
Adds the value to the container's entry.
Parameters:
index - the entry position in the container
value - the value to add
Returns:
the result of addition

mul

public abstract double mul(int index,
                           double value)
Multiplies the container's entry by the value.
Parameters:
index - the entry position in the container
value - the value to multiply
Returns:
the result of multiplication

getPointer

public abstract RealPointer getPointer()
Gets a pointer to the beginning of the container with the unit increment.
Returns:
RealPointer object

getPointer

public final RealPointer getPointer(int index,
                                    int step)
Gets a pointer and resets it for sequential access to the container entries starting from the index position with the step increment.
Parameters:
index - a starting index in the container
step - an increment step in the container

getVector

public abstract RealVector getVector(int index,
                                     int step,
                                     int length)
Creates a vector within the real container.
Parameters:
index - a starting index in the container
step - an increment step in the container
length - a length of the vector

getVector

public final RealVector getVector()
Gets RealVector consisting of all container entries.

moveVector

public abstract void moveVector(RealVector vector,
                                int newStartIndex)
Moves the starting index of vector created upon this container to a new location in the container. In attempt to move an alien vector, the IllegalArgumentException will be thrown.
Parameters:
vector - the vector to be moved to
newStartIndex - the new starting index

shiftVector

public final void shiftVector(RealVector vector,
                              int startIndexIncrement)
Shifts the starting index of vector created upon this container by a specified increment. In attempt to shoft an alien vector, the IllegalArgumentException will be thrown.
Parameters:
vector - the vector to be shifted
newStartIndex - the increment to shift the starting index

clone

public java.lang.Object clone()
Clones the container.
Overrides:
clone in class java.lang.Object
Returns:
clone of this container

getData

public abstract java.lang.Object getData()
Returns the data container encapsulated in the object (instance of double[] or float[] type).

relativeAccuracy

public abstract double relativeAccuracy()
Returns the relative accuracy: smallest value e such that 1+e isn't equal to 1 for the data type used in the container.

assign

public abstract void assign(int index1,
                            int step1,
                            int index2,
                            int step2,
                            int count)
Assignment vector1 = vector2 when both vectors are stored in the container.
Parameters:
index1 - a starting index for the first vector
step1 - an increment step for the first vector
index2 - a starting index for the second vector
step2 - an increment step for the second vector
count - vector's size

multiply

public abstract void multiply(int index,
                              int step,
                              double value,
                              int count)
Multiplies the vector posed in the container on a value.
Parameters:
index - the starting index for the vector
step - the increment step for the vector
value - the multiple
count - the vector length

normalize

public abstract double normalize(int index,
                                 int step,
                                 double value,
                                 int count)
Multiplies the vector posed in the container on a value and calculates its sum-norm.
Parameters:
index - the starting index for the vector
step - the increment step for the vector
value - the multiple
count - the vector length
the - sum of modules norm after the multiplication

addVector

public abstract void addVector(int index1,
                               int step1,
                               int index2,
                               int step2,
                               double factor,
                               int count)
Operation vector1 += factor * vector2 upon the vectors stored in the container.
Parameters:
index1 - a starting index for the first vector
step1 - an increment step for the first vector
index2 - a starting index for the second vector
step2 - an increment step for the second vector
factor - a multiplier
count - a vector size

postProduct

public abstract double postProduct(int index1,
                                   int step1,
                                   int index2,
                                   int step2,
                                   int count)
Calculates an inner product of two vectors distributed within the container with post-increment of starting indices.
Parameters:
index1 - a starting index for the first vector
step1 - an increment step for the first vector
index2 - a starting index for the second vector
step2 - an increment step for the second vector
count - a vectors length

postProduct

public abstract double postProduct(int index,
                                   int step,
                                   RealPointer vec,
                                   int count)
Calculates an inner product of two vectors with post-increment of starting indices. The first vector is situated within the container and the second one is represented by a RealPointer.
Parameters:
index - a starting index for the first vector
step - an increment step for the first vector
vec - a pointer to the second vector
count - a vectors length

preProduct

public abstract double preProduct(int index1,
                                  int step1,
                                  int index2,
                                  int step2,
                                  int count)
Calculates an inner product of two vectors distributed within the container with pre-increment of starting indices.
Parameters:
index1 - an index before the first vector
step1 - an increment step for the first vector
index2 - an index before the second vector
step2 - an increment step for the second vector
count - a vectors length

preProduct

public abstract double preProduct(int index,
                                  int step,
                                  RealPointer vec,
                                  int count)
Calculates an inner product of two vectors with pre-increment of starting indices. The first vector is situated within the container and the second one is represented by a RealPointer.
Parameters:
index - an index before the first vector
step - an increment step for the first vector
vec - a pointer to an entry before the second vector
count - a vectors length

weightedProduct

public abstract double weightedProduct(int index1,
                                       int step1,
                                       int index2,
                                       int step2,
                                       RealPointer weight,
                                       int count)
Calculates a weighted inner product of two vectors distributed within the container.
Parameters:
index1 - a starting index for the first vector
step1 - an increment step for the first vector
index2 - a starting index for the second vector
step2 - an increment step for the second vector
weight - a weight vector (may be equal to null)
count - a vectors length

indexOfNormMax

public abstract int indexOfNormMax(int index,
                                   int step,
                                   int count)
Calculates the index of the first entry having the maximum module for the vector stored in the container. If vector length is nonpositive, (-1) is returned.
Parameters:
index - the starting index
step - the increment step
count - the vector size
Returns:
the index of entry having the maximum module

normMax

public abstract double normMax(int index,
                               int step,
                               int count)
Calculates the maximum modules norm of the vector stored in the container.
Parameters:
index - the starting index
step - the increment step
count - the vector size
Returns:
the max-norm

normSum

public abstract double normSum(int index,
                               int step,
                               int count)
Calculates the sum of modules norm of the vector stored in the container.
Parameters:
index - the starting index
step - the increment step
count - the vector size
Returns:
the sum-norm

weightedNormMax

public abstract double weightedNormMax(int index,
                                       int step,
                                       RealPointer weight,
                                       int count)
Calculates the weighted maximum modules norm of the vector stored in the container.
Parameters:
index - the starting index
step - the increment step
weight - the weight vector (may be equal to null)
count - the vector size
Returns:
the weighted max-norm

weightedNormSum

public abstract double weightedNormSum(int index,
                                       int step,
                                       RealPointer weight,
                                       int count)
Calculates the weighted sum of modules norm of the vector stored in the container.
Parameters:
index - the starting index
step - the increment step
weight - the weight vector (may be equal to null)
count - the vector size
Returns:
the weighted sum-norm

rotate

public abstract void rotate(double cos,
                            double sin,
                            int index1,
                            int step1,
                            int index2,
                            int step2,
                            int count)
Rotates two container's vectors with the Givens rotataion by the formulas v1' = v1*cos(a) + v2*sin(a), v2' = -v1*sin(a) + v2*cos(a).
Parameters:
cos - a cosine of the rotaion angle a
sin - a sine of the rotatin angle a
index1 - a starting index for the first vector
step1 - an increment step for the first vector
index2 - a starting index for the second vector
step2 - an increment step for the second vector
count - a vectors length

swap

public abstract void swap(int index1,
                          int step1,
                          int index2,
                          int step2,
                          int count)
Swaps entries of vector1 with corresponding entries of vector2 for the vectors stored in the container.
Parameters:
index1 - a starting index for the first vector
step1 - an increment step for the first vector
index2 - a starting index for the second vector
step2 - an increment step for the second vector
count - a vector size