public abstract class SparseDoubleArray extends Object implements ReadWriteable, Concatenatable<SparseDoubleArray,SparseDoubleArray>
| Modifier and Type | Class and Description |
|---|---|
static class |
SparseDoubleArray.DualEntry
An entry representing the values in two parallel
SparseDoubleArrays
at the same index. |
static class |
SparseDoubleArray.Entry
An entry in a
SparseDoubleArray, consisting of
an index and value. |
| Modifier and Type | Field and Description |
|---|---|
protected static int |
DEFAULT_CAPACITY |
int |
length
The length of the array
|
| Constructor and Description |
|---|
SparseDoubleArray() |
| Modifier and Type | Method and Description |
|---|---|
SparseDoubleArray |
add(SparseDoubleArray vector)
Add the values in the given vector to a copy of
this array and return the result
|
SparseDoubleArray |
addInplace(SparseDoubleArray vector)
Add the values in the given vector to
this vector and return this
|
String |
asciiHeader()
Header for ascii input.
|
byte[] |
binaryHeader()
Header for binary input.
|
abstract void |
compact()
Compact the space being used by the array if possible.
|
SparseDoubleArray |
concatenate(List<SparseDoubleArray> ins)
Concatenate all the inputs with this, returning a new object that is the
result of the concatenation.
|
SparseDoubleArray |
concatenate(SparseDoubleArray... ins)
Concatenate all the inputs with this, returning a new object that is the
result of the concatenation.
|
static SparseDoubleArray |
concatenateArrays(SparseDoubleArray... arrays)
Concatenate multiple arrays into a single new array.
|
abstract SparseDoubleArray |
copy()
Deep copy the array.
|
float |
density() |
double |
dotProduct(SparseDoubleArray vector)
Compute the dot product with another vector
|
abstract Iterable<SparseDoubleArray.Entry> |
entries()
Provide an iterator over the non-zero values.
|
abstract double |
get(int index)
Get the value at the given index.
|
abstract double |
increment(int index,
double value)
Increment the value at the given index.
|
abstract int[] |
indices() |
Iterable<SparseDoubleArray.DualEntry> |
intersectEntries(SparseDoubleArray otherArray)
Provide an iterator over the intersection of values present in
both this array and another array.
|
abstract boolean |
isUsed(int index)
Check whether the given index is used (i.e.
|
int |
length() |
int |
maxIndex() |
double |
maxValue() |
int |
minIndex() |
double |
minValue() |
SparseDoubleArray |
multiply(double value)
Copy this vector and multiply its values by a
scalar
|
SparseDoubleArray |
multiplyInplace(double value)
Multiply the values inplace by a scalar and return this
|
void |
readASCII(Scanner in)
Read internal state from in.
|
void |
readBinary(DataInput in)
Read internal state from in.
|
abstract SparseDoubleArray |
reverse()
Reverse the elements, returning this.
|
abstract double |
set(int index,
double value)
Set the value at the given index.
|
void |
setLength(int newLength)
Set the length of the array.
|
int |
size() |
SparseDoubleArray |
subtract(SparseDoubleArray vector)
Subtract the values in the given vector from a copy of
this vector and return the result
|
SparseDoubleArray |
subtractInplace(SparseDoubleArray vector)
Subtract the values in the given vector from
this array and return this
|
double |
sumValues()
Compute the sum of values
|
double |
sumValuesSquared()
Compute the sum of values squared
|
double[] |
toArray()
Convert this sparse array to a dense array.
|
double[] |
toArray(double[] array)
Convert this sparse array to a dense array.
|
Iterable<SparseDoubleArray.DualEntry> |
unionEntries(SparseDoubleArray otherArray)
Provide an iterator over the union of values present in
both this array and another array.
|
abstract int |
used() |
abstract double[] |
values() |
void |
writeASCII(PrintWriter out)
Write the content of this as ascii to out.
|
void |
writeBinary(DataOutput out)
Write the content of this as binary to out.
|
protected static final int DEFAULT_CAPACITY
public int length
public SparseDoubleArray()
public abstract double increment(int index, double value)
index - the indexvalue - the amount to increment by.public abstract int[] indices()
public abstract double[] values()
public abstract Iterable<SparseDoubleArray.Entry> entries()
Note: the SparseDoubleArray.Entry returned by the iterator
is always the same object. In addition, the iterator
cannot affect the value of anything in the array (i.e.
changing anything in the SparseDoubleArray.Entry has no effect
on the actual array).
public Iterable<SparseDoubleArray.DualEntry> unionEntries(SparseDoubleArray otherArray)
Note: the SparseDoubleArray.DualEntry returned by the iterator
is always the same object. In addition, the iterator
cannot affect the value of anything in the array (i.e.
changing anything in the SparseDoubleArray.DualEntry has no effect
on the actual array).
otherArray - the second arraypublic Iterable<SparseDoubleArray.DualEntry> intersectEntries(SparseDoubleArray otherArray)
Note: the SparseDoubleArray.DualEntry returned by the iterator
is always the same object. In addition, the iterator
cannot affect the value of anything in the array (i.e.
changing anything in the SparseDoubleArray.DualEntry has no effect
on the actual array).
otherArray - the second arraypublic abstract double get(int index)
index - the indexpublic abstract boolean isUsed(int index)
index - the indexpublic abstract double set(int index, double value)
index - the index.value - the value to set.public void setLength(int newLength)
newLength - the new array lengthIllegalArgumentException - if the new length is shorter than
the existing length.public int size()
public int length()
public abstract int used()
public float density()
public abstract void compact()
public void writeASCII(PrintWriter out) throws IOException
WriteableASCIIwriteASCII in interface WriteableASCIIout - sink to write toIOException - an error writing to outpublic void readASCII(Scanner in) throws IOException
ReadableASCIIreadASCII in interface ReadableASCIIin - source to read from.IOException - an error reading inputpublic String asciiHeader()
ReadableASCIIasciiHeader in interface ReadableASCIIasciiHeader in interface WriteableASCIIpublic void writeBinary(DataOutput out) throws IOException
WriteableBinarywriteBinary in interface WriteableBinaryout - sink to write toIOException - an error writing to outpublic void readBinary(DataInput in) throws IOException
ReadableBinaryreadBinary in interface ReadableBinaryin - source to read from.IOException - an error reading inputpublic byte[] binaryHeader()
ReadableBinarybinaryHeader in interface ReadableBinarybinaryHeader in interface WriteableBinarypublic abstract SparseDoubleArray copy()
public SparseDoubleArray add(SparseDoubleArray vector)
vector - the vector to addpublic SparseDoubleArray addInplace(SparseDoubleArray vector)
vector - the vector to addpublic SparseDoubleArray subtract(SparseDoubleArray vector)
vector - the array to addpublic SparseDoubleArray subtractInplace(SparseDoubleArray vector)
vector - the vector to addpublic SparseDoubleArray multiply(double value)
value - scalar multiplierpublic SparseDoubleArray multiplyInplace(double value)
value - scalar multiplierpublic double dotProduct(SparseDoubleArray vector)
vector - the other vectorpublic double maxValue()
public double minValue()
public int maxIndex()
public int minIndex()
public abstract SparseDoubleArray reverse()
public static SparseDoubleArray concatenateArrays(SparseDoubleArray... arrays)
arrays - the arrays to concatenate.public double sumValues()
public double sumValuesSquared()
public double[] toArray()
Be aware that calling this method results in an array of length
being created. This could be very bad for performance.
public double[] toArray(double[] array)
length, then it will be cleared and populated with the data
held in this sparse array. If the input array is null or is
smaller than length, then a new array will be allocated, filled
and returned.
Be aware that calling this method may result in an array of
length being created. This could be very bad for performance.
array - The array to fill or null.public SparseDoubleArray concatenate(SparseDoubleArray... ins)
Concatenatableconcatenate in interface Concatenatable<SparseDoubleArray,SparseDoubleArray>ins - the inputspublic SparseDoubleArray concatenate(List<SparseDoubleArray> ins)
Concatenatableconcatenate in interface Concatenatable<SparseDoubleArray,SparseDoubleArray>ins - the inputs