public class DoubleVector extends java.lang.Object implements java.lang.Cloneable, RevisionHandler
Constructor and Description |
---|
DoubleVector()
Constructs a null vector.
|
DoubleVector(double[] v)
Constructs a vector directly from a double array
|
DoubleVector(int n)
Constructs an n-vector of zeros.
|
DoubleVector(int n,
double s)
Constructs a constant n-vector.
|
Modifier and Type | Method and Description |
---|---|
void |
addElement(double x)
Adds an element into the vector
|
int |
capacity()
Gets the capacity of the vector.
|
DoubleVector |
cat(DoubleVector v)
Combine two vectors together
|
java.lang.Object |
clone()
Clones the DoubleVector object.
|
DoubleVector |
copy()
Makes a deep copy of the vector
|
DoubleVector |
cumulate()
Returns a vector that stores the cumulated values of the original
vector
|
DoubleVector |
cumulateInPlace()
Cumulates the original vector in place
|
DoubleVector |
dividedBy(DoubleVector v)
Divided by another DoubleVector element by element
|
DoubleVector |
dividedByEquals(DoubleVector v)
Divided by another DoubleVector element by element in place
|
double |
get(int i)
Gets a single element.
|
double[] |
getArray()
Access the internal one-dimensional array.
|
double[] |
getArrayCopy()
Returns a copy of the DoubleVector usng a double array.
|
java.lang.String |
getRevision()
Returns the revision string.
|
int |
indexOfMax()
Returns the index of the maximum.
|
double |
innerProduct(DoubleVector v)
Returns the inner product of two DoubleVectors
|
boolean |
isEmpty()
Checks if it is an empty vector
|
static void |
main(java.lang.String[] args) |
DoubleVector |
map(java.lang.String className,
java.lang.String method)
Applies a method to the vector
|
double |
max()
Returns the maximum value of all elements
|
DoubleVector |
minus(double x)
Subtracts a value
|
DoubleVector |
minus(DoubleVector v)
Subtracts another DoubleVector element by element
|
DoubleVector |
minusEquals(double x)
Subtracts a value in place
|
DoubleVector |
minusEquals(DoubleVector v)
Subtracts another DoubleVector element by element in place
|
double |
norm1()
Returns the L1-norm of the vector
|
double |
norm2()
Returns the L2-norm of the vector
|
DoubleVector |
plus(double x)
Adds a value to all the elements
|
DoubleVector |
plus(DoubleVector v)
Adds another vector element by element
|
DoubleVector |
plusEquals(double x)
Adds a value to all the elements in place
|
DoubleVector |
plusEquals(DoubleVector v)
Adds another vector in place element by element
|
static DoubleVector |
random(int n)
Returns a random vector of uniform distribution
|
DoubleVector |
rev()
Returns the reverse vector
|
void |
set(double s)
Set all elements to a value
|
void |
set(DoubleVector v)
Set the elements using a DoubleVector
|
void |
set(int i,
double s)
Set a single element.
|
void |
set(int i0,
int i1,
double s)
Set some elements to a value
|
void |
set(int i0,
int i1,
double[] v,
int j0)
Set some elements using a 2-D array
|
void |
set(int i0,
int i1,
DoubleVector v,
int j0)
Set some elements using a DoubleVector.
|
void |
setCapacity(int n)
Sets the capacity of the vector
|
void |
setPlus(int i,
double s)
Adds a value to an element
|
void |
setSize(int m)
Sets the size of the vector
|
void |
setTimes(int i,
double s)
Multiplies a value to an element
|
DoubleVector |
sign()
Returns the signs of all elements in terms of -1, 0 and +1.
|
int |
size()
Gets the size of the vector.
|
void |
sort()
Sorts the array in place
|
IntVector |
sortWithIndex()
Sorts the array in place with index returned
|
void |
sortWithIndex(int xi,
int xj,
IntVector index)
Sorts the array in place with index changed
|
DoubleVector |
sqrt()
Returns the square-root of all the elements in the vector
|
DoubleVector |
square()
Returns the squared vector
|
DoubleVector |
subvector(int i0,
int i1)
Returns a subvector.
|
DoubleVector |
subvector(IntVector index)
Returns a subvector.
|
double |
sum()
Returns the sum of all elements in the vector.
|
double |
sum2()
Returns the squared sum of all elements in the vector.
|
double |
sum2(DoubleVector v)
Returns ||u-v||^2
|
void |
swap(int i,
int j)
Swaps the values stored at i and j
|
DoubleVector |
times(double s)
Multiplies a scalar
|
DoubleVector |
times(DoubleVector v)
Multiplies another DoubleVector element by element
|
DoubleVector |
timesEquals(double s)
Multiply a vector by a scalar in place, u = s * u
|
DoubleVector |
timesEquals(DoubleVector v)
Multiplies another DoubleVector element by element in place
|
java.lang.String |
toString()
Convert the DoubleVecor to a string
|
java.lang.String |
toString(int digits,
boolean trailing)
Convert the DoubleVecor to a string
|
DoubleVector |
unpivoting(IntVector index,
int length)
Returns a vector from the pivoting indices.
|
boolean |
unsorted()
Returns true if vector not sorted
|
public DoubleVector()
public DoubleVector(int n)
n
- length.public DoubleVector(int n, double s)
n
- length.s
- the scalar value used to fill the vectorpublic DoubleVector(double[] v)
v
- the arraypublic void set(int i, double s)
i
- Index.s
- a[i].public void set(double s)
s
- the valuepublic void set(int i0, int i1, double s)
i0
- the index of the first elementi1
- the index of the second elements
- the valuepublic void set(int i0, int i1, double[] v, int j0)
i0
- the index of the first elementi1
- the index of the second elementj0
- the index of the starting element in the 2-D arrayv
- the valuespublic void set(DoubleVector v)
v
- the DoubleVectorpublic void set(int i0, int i1, DoubleVector v, int j0)
i0
- the index of the first elementi1
- the index of the second elementv
- the DoubleVectorj0
- the index of the starting element in the DoubleVectorpublic double[] getArray()
public double[] getArrayCopy()
public void sort()
public IntVector sortWithIndex()
public void sortWithIndex(int xi, int xj, IntVector index)
xi
- first indexxj
- last indexindex
- array that stores all indicespublic int size()
public void setSize(int m)
m
- the sizepublic int capacity()
public void setCapacity(int n)
n
- the capacity.public double get(int i)
i
- Index.public void setPlus(int i, double s)
i
- the index of the elements
- the valuepublic void setTimes(int i, double s)
i
- the index of the elements
- the valuepublic void addElement(double x)
x
- the value of the new elementpublic DoubleVector square()
public DoubleVector sqrt()
public DoubleVector copy()
public java.lang.Object clone()
clone
in class java.lang.Object
public double innerProduct(DoubleVector v)
v
- the second DoubleVectorpublic DoubleVector sign()
public double sum()
public double sum2()
public double norm1()
public double norm2()
public double sum2(DoubleVector v)
v
- the second vectorpublic DoubleVector subvector(int i0, int i1)
i0
- the index of the first elementi1
- the index of the last elementpublic DoubleVector subvector(IntVector index)
index
- stores the indices of the needed elementspublic DoubleVector unpivoting(IntVector index, int length)
index
- stores the pivoting indiceslength
- the total number of the potential elementspublic DoubleVector plus(double x)
x
- the valuepublic DoubleVector plusEquals(double x)
x
- the valuepublic DoubleVector plus(DoubleVector v)
v
- the second vectorpublic DoubleVector plusEquals(DoubleVector v)
v
- the second vectorpublic DoubleVector minus(double x)
x
- the valuepublic DoubleVector minusEquals(double x)
x
- the valuepublic DoubleVector minus(DoubleVector v)
v
- the second DoubleVectorpublic DoubleVector minusEquals(DoubleVector v)
v
- the second DoubleVectorpublic DoubleVector times(double s)
s
- scalarpublic DoubleVector timesEquals(double s)
s
- scalarpublic DoubleVector times(DoubleVector v)
v
- the second DoubleVectorpublic DoubleVector timesEquals(DoubleVector v)
v
- the second DoubleVectorpublic DoubleVector dividedBy(DoubleVector v)
v
- the second DoubleVectorpublic DoubleVector dividedByEquals(DoubleVector v)
v
- the second DoubleVectorpublic boolean isEmpty()
public DoubleVector cumulate()
public DoubleVector cumulateInPlace()
public int indexOfMax()
If multiple maximums exist, the index of the first is returned.
public boolean unsorted()
public DoubleVector cat(DoubleVector v)
v
- the second vectorpublic void swap(int i, int j)
i
- the index ij
- the index jpublic double max()
public DoubleVector map(java.lang.String className, java.lang.String method)
className
- the class namemethod
- the methodpublic DoubleVector rev()
public static DoubleVector random(int n)
n
- the size of the vectorpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(int digits, boolean trailing)
digits
- the number of digits after decimal pointtrailing
- true if trailing zeros are to be shownpublic java.lang.String getRevision()
getRevision
in interface RevisionHandler
public static void main(java.lang.String[] args)