public abstract class SparseFloatArray extends Object implements ReadWriteable, Concatenatable<SparseFloatArray,SparseFloatArray>
Modifier and Type | Class and Description |
---|---|
static class |
SparseFloatArray.DualEntry
An entry representing the values in two parallel
SparseFloatArray s
at the same index. |
static class |
SparseFloatArray.Entry
An entry in a
SparseFloatArray , 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 |
---|
SparseFloatArray() |
Modifier and Type | Method and Description |
---|---|
SparseFloatArray |
add(SparseFloatArray vector)
Add the values in the given vector to a copy of
this array and return the result
|
SparseFloatArray |
addInplace(SparseFloatArray 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.
|
SparseFloatArray |
concatenate(List<SparseFloatArray> ins)
Concatenate all the inputs with this, returning a new object that is the
result of the concatenation.
|
SparseFloatArray |
concatenate(SparseFloatArray... ins)
Concatenate all the inputs with this, returning a new object that is the
result of the concatenation.
|
static SparseFloatArray |
concatenateArrays(SparseFloatArray... arrays)
Concatenate multiple arrays into a single new array.
|
abstract SparseFloatArray |
copy()
Deep copy the array.
|
float |
density() |
double |
dotProduct(SparseFloatArray vector)
Compute the dot product with another vector
|
abstract Iterable<SparseFloatArray.Entry> |
entries()
Provide an iterator over the non-zero values.
|
abstract float |
get(int index)
Get the value at the given index.
|
abstract float |
increment(int index,
float value)
Increment the value at the given index.
|
abstract int[] |
indices() |
Iterable<SparseFloatArray.DualEntry> |
intersectEntries(SparseFloatArray 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() |
float |
maxValue() |
int |
minIndex() |
float |
minValue() |
SparseFloatArray |
multiply(double value)
Copy this vector and multiply its values by a
scalar
|
SparseFloatArray |
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 SparseFloatArray |
reverse()
Reverse the elements, returning this.
|
abstract float |
set(int index,
float value)
Set the value at the given index.
|
void |
setLength(int newLength)
Set the length of the array.
|
int |
size() |
SparseFloatArray |
subtract(SparseFloatArray vector)
Subtract the values in the given vector from a copy of
this vector and return the result
|
SparseFloatArray |
subtractInplace(SparseFloatArray vector)
Subtract the values in the given vector from
this array and return this
|
float |
sumValues()
Compute the sum of values
|
float |
sumValuesSquared()
Compute the sum of values squared
|
float[] |
toArray()
Convert this sparse array to a dense array.
|
float[] |
toArray(float[] array)
Convert this sparse array to a dense array.
|
Iterable<SparseFloatArray.DualEntry> |
unionEntries(SparseFloatArray otherArray)
Provide an iterator over the union of values present in
both this array and another array.
|
abstract int |
used() |
abstract float[] |
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 SparseFloatArray()
public abstract float increment(int index, float value)
index
- the indexvalue
- the amount to increment by.public abstract int[] indices()
public abstract float[] values()
public abstract Iterable<SparseFloatArray.Entry> entries()
Note: the SparseFloatArray.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 SparseFloatArray.Entry
has no effect
on the actual array).
public Iterable<SparseFloatArray.DualEntry> unionEntries(SparseFloatArray otherArray)
Note: the SparseFloatArray.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 SparseFloatArray.DualEntry
has no effect
on the actual array).
otherArray
- the second arraypublic Iterable<SparseFloatArray.DualEntry> intersectEntries(SparseFloatArray otherArray)
Note: the SparseFloatArray.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 SparseFloatArray.DualEntry
has no effect
on the actual array).
otherArray
- the second arraypublic abstract float get(int index)
index
- the indexpublic abstract boolean isUsed(int index)
index
- the indexpublic abstract float set(int index, float 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
WriteableASCII
writeASCII
in interface WriteableASCII
out
- sink to write toIOException
- an error writing to outpublic void readASCII(Scanner in) throws IOException
ReadableASCII
readASCII
in interface ReadableASCII
in
- source to read from.IOException
- an error reading inputpublic String asciiHeader()
ReadableASCII
asciiHeader
in interface ReadableASCII
asciiHeader
in interface WriteableASCII
public void writeBinary(DataOutput out) throws IOException
WriteableBinary
writeBinary
in interface WriteableBinary
out
- sink to write toIOException
- an error writing to outpublic void readBinary(DataInput in) throws IOException
ReadableBinary
readBinary
in interface ReadableBinary
in
- source to read from.IOException
- an error reading inputpublic byte[] binaryHeader()
ReadableBinary
binaryHeader
in interface ReadableBinary
binaryHeader
in interface WriteableBinary
public abstract SparseFloatArray copy()
public SparseFloatArray add(SparseFloatArray vector)
vector
- the vector to addpublic SparseFloatArray addInplace(SparseFloatArray vector)
vector
- the vector to addpublic SparseFloatArray subtract(SparseFloatArray vector)
vector
- the array to addpublic SparseFloatArray subtractInplace(SparseFloatArray vector)
vector
- the vector to addpublic SparseFloatArray multiply(double value)
value
- scalar multiplierpublic SparseFloatArray multiplyInplace(double value)
value
- scalar multiplierpublic double dotProduct(SparseFloatArray vector)
vector
- the other vectorpublic float maxValue()
public float minValue()
public int maxIndex()
public int minIndex()
public abstract SparseFloatArray reverse()
public static SparseFloatArray concatenateArrays(SparseFloatArray... arrays)
arrays
- the arrays to concatenate.public float sumValues()
public float sumValuesSquared()
public float[] toArray()
Be aware that calling this method results in an array of length
being created. This could be very bad for performance.
public float[] toArray(float[] 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 SparseFloatArray concatenate(SparseFloatArray... ins)
Concatenatable
concatenate
in interface Concatenatable<SparseFloatArray,SparseFloatArray>
ins
- the inputspublic SparseFloatArray concatenate(List<SparseFloatArray> ins)
Concatenatable
concatenate
in interface Concatenatable<SparseFloatArray,SparseFloatArray>
ins
- the inputs