public class DoubleArrayList extends Object implements DoubleList, Cloneable, Externalizable
ArrayList specialized for primitive
doubles and augmented with mathematical vector operations.| Constructor and Description |
|---|
DoubleArrayList()
Constructs an empty list with an initial capacity of ten.
|
DoubleArrayList(double[] c)
Constructs a list containing the elements of the specified array, in the
order they appear in the array.
|
DoubleArrayList(DoubleList c)
Constructs a list containing the elements of the specified list, in the
order they are returned by the list's
DoubleList.toArray()
method. |
DoubleArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.
|
DoubleArrayList(int initialLength,
double initialValue)
Constructs a list with length
initialLength where all elements
have initialValue as initial value. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(double e)
Appends the specified element to the end of this list.
|
void |
add(int index,
double element)
Inserts the specified element at the specified position in this list.
|
boolean |
addAll(DoubleList c)
Appends all of the elements in the specified list to the end of this
list, in the order that they are returned by the specified list's
DIterator.
|
boolean |
addAll(int index,
DoubleList c)
Inserts all of the elements in the specified list into this list,
starting at the specified position.
|
DoubleList |
assignConst(double val)
Assign the constant
val to each element in this list. |
double |
avg()
Returns the average value of the elements in this list if this list has
at least one element, otherwise throws
NoSuchElementException. |
void |
clear()
Removes all of the elements from this list.
|
Object |
clone()
Returns a deep copy of this
DoubleArrayList instance. |
boolean |
contains(double o)
Returns
true if this list contains the specified element. |
boolean |
containsAll(DoubleList c)
Returns
true if this DoubleList contains all of the elements in
the specified DoubleList. |
DoubleList |
cross(double[] array)
Computes the cross
product of this DoubleList and the given
array provided that
both, this DoubleList and the given array, have a dimension of
3. |
DoubleList |
cross(DoubleList list)
Computes the cross
product of this DoubleList and the given
list provided that
both, this DoubleList and the given list, have a dimension of
3. |
double |
dot(double[] array)
Computes the dot product of this list and the given
array. |
double |
dot(DoubleList list)
Computes the dot product of this list and the given
list. |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this
DoubleArrayList instance, if
necessary, to ensure that it can hold at least the number of elements
specified by the minimum capacity argument. |
boolean |
equals(Object o)
Compares the specified object with this DoubleList for equality.
|
void |
forEach(DoubleConsumer action)
Performs the given action for each element of this list in the order of
iteration until all elements have been processed or the action throws an
exception.
|
double |
get(int index)
Returns the element at the specified position in this list.
|
double[] |
getArrayUnsafe()
Returns the underlying array as an escape hatch.
|
int |
hashCode()
Returns the hash code value for this DoubleList.
|
int |
indexOf(double o)
Returns the index of the first occurrence of the specified element in
this list, or -1 if this list does not contain the element.
|
boolean |
isEmpty()
Returns
true if this list contains no elements. |
DForEachIterator |
iterator()
Returns an iterator over the elements in this list in proper sequence.
|
int |
lastIndexOf(double o)
Returns the index of the last occurrence of the specified element in this
list, or -1 if this list does not contain the element.
|
DListIterator |
listIterator()
Returns a list iterator over the elements in this list (in proper
sequence).
|
DListIterator |
listIterator(int index)
Returns a list iterator over the elements in this list (in proper
sequence), starting at the specified position in the list.
|
double |
logSumExp()
Returns the logarithm of the sum of the exponentials of this list (see
LogSumExp) if it
has at least one element, otherwise
NoSuchElementException is
thrown. |
double |
max()
Returns the maximum of the elements in this list if this list has at
least one element, otherwise throws
NoSuchElementException. |
double |
median()
Returns the median value of the elements in this list if this list has at
least one element, otherwise throws
NoSuchElementException. |
double |
min()
Returns the minimum of the elements in this list if this list has at
least one element, otherwise throws
NoSuchElementException. |
DoubleList |
mul(double val)
Multiply each element in this list by the scalar
val. |
double |
muli(int index,
double val)
Multiply the element at
index by the scalar val. |
DoubleList |
muln(double[] array)
Multiplies the scalars from this list by the scalars from the given
array. |
DoubleList |
muln(DoubleList list)
Multiplies the scalars from this list by the scalars from the given
list. |
double |
norm2()
Computes the euclidean norm (magnitude) of this list.
|
DoubleList |
normalizedSoftmax(double normalizedSum)
Returns a new list that contains the contents of this list normalized to
a distribution according to the
softmax
function which sums up to
normalizedSum. |
static DoubleArrayList |
of(double... values)
Constructs a list containing the passed values in the order of their
appearance.
|
int |
offset()
Returns the offset of this list.
|
DoubleList |
plus(double val)
Add the scalar
val to each element in this list. |
double |
plusi(int index,
double val)
Add the scalar
val to the element at index. |
DoubleList |
plusn(double[] array)
Add the scalars from the given
array to the elements in this
list. |
DoubleList |
plusn(DoubleList list)
Add the scalars from the given
list to the elements in this list. |
static DoubleArrayList |
randomNormal(double mu,
double sigma,
int size)
Constructs a random list of length
size with random values
normally distributed with mean mu and standard deviation
sigma. |
static DoubleArrayList |
randomUniform(double min,
double max,
int size)
Constructs a random list of length
size with random values
uniformly distributed between min and max. |
void |
readExternal(ObjectInput in) |
boolean |
remove(double o)
Removes the first occurrence of the specified element from this list, if
it is present.
|
double |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
removeAll(DoubleList c)
Removes from this list all of its elements that are contained in the
specified list.
|
protected void |
removeRange(int fromIndex,
int toIndex)
Removes from this list all of the elements whose index is between
fromIndex, inclusive, and toIndex, exclusive. |
boolean |
retainAll(DoubleList c)
Retains only the elements in this list that are contained in the
specified list.
|
DoubleList |
round(int scale)
Round the scalars in this list to
scale. |
DoubleList |
sanitizeNonFinite(double nanSurrogate,
double posInfSurrogate,
double negInfSurrogate)
Set all scalars that are either NaN, positive or negative infinity to the
respective ersatz value provided by the
nanSurrogate,
posInfSurrogate and negInfSurrogate arguments. |
double |
set(int index,
double element)
Replaces the element at the specified position in this list with the
specified element.
|
int |
size()
Returns the number of elements in this list.
|
DoubleList |
softmax()
Returns a new list that contains the contents of this list normalized to
a probability distribution according to the
softmax
function which sums up to
1.0. |
void |
sort()
Sorts this list in ascending order.
|
Spliterator.OfDouble |
spliterator()
Creates a late-binding and fail-fast
Spliterator over the elements in this list. |
double |
stddev()
Returns the standard deviation of the elements in this list if this list
has at least two elements, otherwise throws
IllegalArgumentException. |
DoubleList |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this list between the specified
fromIndex, inclusive, and toIndex, exclusive. |
double |
sum()
Returns the sum of the elements in this list.
|
double[] |
toArray()
Returns an array containing all of the elements in this list in proper
sequence (from first to last element).
|
String |
toString() |
void |
trimToSize()
Trims the capacity of this
DoubleArrayList instance to be the
list's current size. |
void |
writeExternal(ObjectOutput out) |
finalize, getClass, notify, notifyAll, wait, wait, waitapproxEqual, approxEqual, parallelStream, streampublic DoubleArrayList(int initialCapacity)
initialCapacity - the initial capacity of the listIllegalArgumentException - if the specified initial capacity is negativepublic DoubleArrayList(int initialLength,
double initialValue)
initialLength where all elements
have initialValue as initial value.initialLength - the initial length of the listinitialValue - the initial value of all elements in the listIllegalArgumentException - if the specified initial length is negativepublic DoubleArrayList()
public DoubleArrayList(double[] c)
c - the array whose elements are to be placed into this listNullPointerException - if the specified array is nullpublic DoubleArrayList(DoubleList c)
DoubleList.toArray()
method.c - the list whose elements are to be placed into this listNullPointerException - if the specified list is nullpublic static DoubleArrayList of(double... values)
of in interface DoubleListvalues - the values which are to be placed into the listDoubleArrayList constructed from the passed valuespublic static DoubleArrayList randomUniform(double min, double max, int size)
size with random values
uniformly distributed between min and max.randomUniform in interface DoubleListmin - lower bound of the uniform distributionmax - upper bound of the uniform distributionsize - length of the listsizepublic static DoubleArrayList randomNormal(double mu, double sigma, int size)
size with random values
normally distributed with mean mu and standard deviation
sigma.randomNormal in interface DoubleListmu - mean (expectation) of the normal distributionsigma - standard deviation of the normal distribution, must be
> 0.0size - length of the listsizepublic void trimToSize()
DoubleArrayList instance to be the
list's current size. An application can use this operation to minimize
the storage of an DoubleArrayList instance.public void ensureCapacity(int minCapacity)
DoubleArrayList instance, if
necessary, to ensure that it can hold at least the number of elements
specified by the minimum capacity argument.minCapacity - the desired minimum capacitypublic int size()
size in interface DoubleListpublic boolean isEmpty()
true if this list contains no elements.isEmpty in interface DoubleListtrue if this list contains no elementspublic boolean contains(double o)
true if this list contains the specified element. More
formally, returns true if and only if this list contains at least
one element e such that o == e.contains in interface DoubleListo - element whose presence in this list is to be testedtrue if this list contains the specified elementpublic boolean containsAll(DoubleList c)
true if this DoubleList contains all of the elements in
the specified DoubleList.containsAll in interface DoubleListc - DoubleList to be checked for containment in this DoubleListtrue if this DoubleList contains all of the elements in
the specified DoubleListpublic int indexOf(double o)
i such that
o == get(i), or -1 if there is no such index.indexOf in interface DoubleListo - element to search for-1 if not foundpublic int lastIndexOf(double o)
i such that o == get(i), or -1
if there is no such index.lastIndexOf in interface DoubleListo - element to search for-1 if not foundpublic Object clone()
DoubleArrayList instance.public double[] toArray()
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
toArray in interface DoubleListpublic double get(int index)
get in interface DoubleListindex - index of the element to returnpublic double set(int index,
double element)
set in interface DoubleListindex - index of the element to replaceelement - element to be stored at the specified positionpublic boolean add(double e)
add in interface DoubleListe - element to be appended to this listtruepublic void add(int index,
double element)
add in interface DoubleListindex - index at which the specified element is to be insertedelement - element to be insertedpublic double remove(int index)
remove in interface DoubleListindex - the index of the element to be removedpublic boolean equals(Object o)
true if and only if the specified object is also a DoubleList,
both lists have the same size, and all corresponding pairs of elements in
the two lists are equal. In other words, two DoubleList are
defined to be equal if they contain the same elements in the same order.equals in interface DoubleListequals in class Objecto - the object to be compared for equality with this DoubleListtrue if the specified object is equal to this DoubleListpublic int hashCode()
int hashCode = 1;
for (int i = 0; i < list.size(); i++) {
hashCode = 31 * hashCode + Double.hashCode(list.get(i));
}
This ensures that list1.equals(list2) implies that
list1.hashCode()==list2.hashCode() for any two DoubleLists,
list1 and list2, as required by the general contract of
Object.hashCode().hashCode in interface DoubleListhashCode in class Objectpublic boolean remove(double o)
i such
that o == get(i) (if such an element exists). Returns
true if this list contained the specified element (or
equivalently, if this list changed as a result of the call).remove in interface DoubleListo - element to be removed from this list, if presenttrue if this list contained the specified elementpublic void clear()
clear in interface DoubleListpublic boolean addAll(DoubleList c)
addAll in interface DoubleListc - list containing elements to be added to this listtrue if this list changed as a result of the callpublic boolean addAll(int index,
DoubleList c)
addAll in interface DoubleListindex - index at which to insert the first element from the specified
listc - list containing elements to be added to this listtrue if this list changed as a result of the callprotected void removeRange(int fromIndex,
int toIndex)
fromIndex, inclusive, and toIndex, exclusive. Shifts any
succeeding elements to the left (reduces their index). This call shortens
the list by (toIndex - fromIndex) elements. (If
toIndex==fromIndex, this operation has no effect.)fromIndex - start index, inclusivetoIndex - end index, exclusiveIndexOutOfBoundsException - if fromIndex or toIndex is out of range
(fromIndex < 0 ||
toIndex > size() ||
toIndex < fromIndex)public boolean removeAll(DoubleList c)
removeAll in interface DoubleListc - list containing elements to be removed from this listtrue if this list changed as a result of the callpublic boolean retainAll(DoubleList c)
retainAll in interface DoubleListc - list containing elements to be retained in this listtrue if this list changed as a result of the callpublic DListIterator listIterator(int index)
next. An initial call to
previous would return the element with the
specified index minus one.
The returned list iterator is fail-fast.
listIterator in interface DoubleListindex - starting positionpublic DListIterator listIterator()
The returned list iterator is fail-fast.
listIterator in interface DoubleListpublic DForEachIterator iterator()
The returned iterator is fail-fast.
iterator in interface DoubleListpublic DoubleList subList(int fromIndex, int toIndex)
fromIndex, inclusive, and toIndex, exclusive. (If
fromIndex and toIndex are equal, the returned list is
empty.) The returned list is backed by this list, so non-structural
changes in the returned list are reflected in this list, and vice-versa.
The returned list supports all of the optional list operations.
This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
list.subList(from, to).clear();Similar idioms may be constructed for
DoubleList.indexOf(double) and
DoubleList.lastIndexOf(double), and all of the algorithms in a
DoubleList can be applied to a subList.
The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
subList in interface DoubleListfromIndex - start index, inclusivetoIndex - end index, exclusivepublic void forEach(DoubleConsumer action)
forEach in interface DoubleListaction - The action to be performed for each elementpublic Spliterator.OfDouble spliterator()
Spliterator over the elements in this list.
The Spliterator.OfDouble reports Spliterator.SIZED,
Spliterator.SUBSIZED, and Spliterator.ORDERED. Overriding
implementations should document the reporting of additional
characteristic values.
spliterator in interface DoubleListSpliterator.OfDouble over the elements in this listpublic void sort()
sort in interface DoubleListpublic int offset()
offset in interface DoubleListpublic double[] getArrayUnsafe()
getArrayUnsafe in interface DoubleListpublic DoubleList assignConst(double val)
val to each element in this list.assignConst in interface DoubleListval - the constant to assignDoubleListpublic DoubleList round(int scale)
scale.round in interface DoubleListscale - if zero or positive, the scale is the number of digits to the
right of the decimal point. If negative, the unscaled value of
the number is multiplied by ten to the power of the negation
of the scale.DoubleListpublic DoubleList plus(double val)
val to each element in this list.plus in interface DoubleListval - the scalar to addDoubleListpublic DoubleList mul(double val)
val.mul in interface DoubleListval - the scalar to multiply byDoubleListpublic double sum()
sum in interface DoubleListpublic double plusi(int index,
double val)
val to the element at index.plusi in interface DoubleListindex - index of the element to increment by valval - the scalar to add to the elementpublic double muli(int index,
double val)
index by the scalar val.muli in interface DoubleListindex - index of the element to multiply by valval - the scalar to multiply bypublic double dot(DoubleList list)
list.dot in interface DoubleListlist - a DoubleList which must have the same DoubleList.size() as this
listlistpublic double dot(double[] array)
array.dot in interface DoubleListarray - an array which must have the same length as this list's
DoubleList.size()array.public DoubleList cross(DoubleList list)
list provided that
both, this DoubleList and the given list, have a dimension of
3. If this DoubleList is not of DoubleList.size() == 3 an
UnsupportedOperationException is thrown. Also, if the given
list doesn't satisfy list.size() == 3 an
IllegalArgumentException is thrown.cross in interface DoubleListlist - a DoubleList which must have the size() == 3listpublic DoubleList cross(double[] array)
array provided that
both, this DoubleList and the given array, have a dimension of
3. If this DoubleList is not of DoubleList.size() == 3 an
UnsupportedOperationException is thrown. Also, if the given
array doesn't satisfy array.length == 3 an
IllegalArgumentException is thrown.cross in interface DoubleListarray - an array which must have length == 3arraypublic double norm2()
norm2 in interface DoubleListpublic DoubleList softmax()
1.0.softmax in interface DoubleListpublic DoubleList normalizedSoftmax(double normalizedSum)
normalizedSum.normalizedSoftmax in interface DoubleListnormalizedSum - the overall sum of the desired distributionnormalizedSumpublic double logSumExp()
NoSuchElementException is
thrown.logSumExp in interface DoubleListpublic double min()
NoSuchElementException.min in interface DoubleListpublic double max()
NoSuchElementException.max in interface DoubleListpublic double avg()
NoSuchElementException.avg in interface DoubleListpublic double stddev()
IllegalArgumentException. The value is computed without Bessel's
correction, i.e., we divide by n, not by n - 1.stddev in interface DoubleListpublic double median()
NoSuchElementException.median in interface DoubleListpublic DoubleList plusn(DoubleList list)
list to the elements in this list.
Note that list doesn't have to have the same DoubleList.size() as
this list as the minimum of both list sizes is used to determine the
number of scalars to add.plusn in interface DoubleListlist - a DoubleList of scalars to add to this listDoubleListpublic DoubleList plusn(double[] array)
array to the elements in this
list. Note that array doesn't have to have the same length as
this list as the minimum of both lengths is used to determine the number
of scalars to add.plusn in interface DoubleListarray - an array of scalars to add to this listDoubleListpublic DoubleList muln(DoubleList list)
list. Note that list doesn't have to have the same
DoubleList.size() as this list as the minimum of both list sizes is used to
determine the number of scalars to multiply.muln in interface DoubleListlist - a DoubleList of scalars to multiply by the elements in this
listDoubleListpublic DoubleList muln(double[] array)
array. Note that array doesn't have to have the same
length as this list as the minimum of both lengths is used to determine
the number of scalars to multiply.muln in interface DoubleListarray - an array of scalars to multiply by the elements in this listDoubleListpublic DoubleList sanitizeNonFinite(double nanSurrogate, double posInfSurrogate, double negInfSurrogate)
nanSurrogate,
posInfSurrogate and negInfSurrogate arguments.sanitizeNonFinite in interface DoubleListnanSurrogate - the substitution value to use for NaN values, NaNs won't get
substituted if you pass Double.NaNposInfSurrogate - the substitution value to use for positive infinity values, no
substitution happens if you pass
Double.POSITIVE_INFINITYnegInfSurrogate - the substitution value to use for negative infinity values, no
substitution happens if you pass
Double.NEGATIVE_INFINITYDoubleListpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionCopyright © 2022. All rights reserved.