java.lang.Object
org.ojalgo.array.BasicArray<N>
org.ojalgo.array.SparseArray<N>
- All Implemented Interfaces:
Access1D<N>,Access1D.Aggregatable<N>,Access1D.Collectable<N,,Mutate1D> Access1D.Visitable<N>,Mutate1D,Mutate1D.Fillable<N>,Mutate1D.Modifiable<N>,Structure1D
Only stores nonzero elements and/or elements specifically set by the user. The nonzero elements are stored
internally in a DenseArray.
- Author:
- apete
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfaceSparseArray.NonzeroReferenceTypeCallback<N extends Comparable<N>>static final classSparseArray.NonzeroView<N extends Comparable<N>>static final classSparseArray.SparseFactory<N extends Comparable<N>>Nested classes/interfaces inherited from class org.ojalgo.array.BasicArray
BasicArray.Factory<N extends Comparable<N>>Nested classes/interfaces inherited from interface org.ojalgo.structure.Access1D
Access1D.Aggregatable<N extends Comparable<N>>, Access1D.Collectable<N extends Comparable<N>,R extends Mutate1D>, Access1D.ElementView<N extends Comparable<N>>, Access1D.SelectionView<N extends Comparable<N>>, Access1D.Sliceable<N extends Comparable<N>>, Access1D.Visitable<N extends Comparable<N>> Nested classes/interfaces inherited from interface org.ojalgo.structure.Mutate1D
Mutate1D.Fillable<N extends Comparable<N>>, Mutate1D.Mixable<N extends Comparable<N>>, Mutate1D.Modifiable<N extends Comparable<N>>, Mutate1D.ModifiableReceiver<N extends Comparable<N>>, Mutate1D.Receiver<N extends Comparable<N>>, Mutate1D.SortableNested classes/interfaces inherited from interface org.ojalgo.structure.Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S extends Structure1D,B extends Structure1D.Logical<S, B>>, Structure1D.LongIndex, Structure1D.LoopCallback -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int index, double addend) voidadd(long index, double addend) voidadd(long index, float addend) voidadd(long index, Comparable<?> addend) voidaxpy(double a, Mutate1D.Modifiable<?> y) Will calculate y = y + a x, will add "a" times "this" to "y"longcount()The total number of elements in this structure.intlongdoubleWill calculate and return the dot product of this 1D-structure and another input 1D-vector.doubledoubleValue(int index) doubledoubleValue(long index) voidexchange(int indexA, int indexB) Efficiently exchanges two elements in the sparse array.protected voidexchange(long firstA, long firstB, long step, long count) static <N extends Comparable<N>>
SparseArray.SparseFactory<N> factory(PlainArray.Factory<N, ?> denseFactory) protected voidprotected voidfill(long first, long limit, long step, NullaryFunction<?> supplier) voidvoidfillAll(NullaryFunction<?> supplier) voidvoidfillRange(long first, long limit, NullaryFunction<?> supplier) longfirstInRange(long rangeFirst, long rangeLimit) get(long index) longprotected longindexOfLargest(long first, long limit, long step) longlimitOfRange(long rangeFirst, long rangeLimit) protected voidmodify(long first, long limit, long step, BinaryFunction<N> function, Access1D<N> right) protected voidmodify(long first, long limit, long step, UnaryFunction<N> function) protected voidmodify(long first, long limit, long step, Access1D<N> left, BinaryFunction<N> function) voidmodifyAll(UnaryFunction<N> modifier) voidmodifyOne(long index, UnaryFunction<N> modifier) nonzeros()Similar toAccess1D.elements()but avoids elements that are structurally known to be zero.voidputLast(int index, double value) Efficiently appends a new nonzero element at the end of this sparse array.voidremoveShiftAndInsert(int first, int last, double newValue) All elements with indices in the range [first,last] should be shifted one step to the left (their indices decreased by 1).voidreset()Reset this mutable structure to some standard (all zeros) initial state.voidset(int index, double value) voidset(long index, double value) voidset(long index, float value) voidset(long index, Comparable<?> value) intsize()The total number of elements in this structure.voidsupplyNonZerosTo(double[] receiver) Does NOT first reset the receiver!voidsupplyNonZerosTo(Mutate1D receiver) Does NOT first reset the receiver!voidsupplyTo(double[] receiver) voidprotected voidvisit(long first, long limit, long step, VoidFunction<N> visitor) voidvisitOne(long index, VoidFunction<N> visitor) voidvisitPrimitiveNonzerosInRange(long first, long limit, SparseArray.NonzeroPrimitiveCallback visitor) voidvisitRange(long first, long limit, VoidFunction<N> visitor) voidvisitReferenceTypeNonzerosInRange(long first, long limit, SparseArray.NonzeroReferenceTypeCallback<N> visitor) Methods inherited from class org.ojalgo.array.BasicArray
aggregateRange, equals, getMathType, hashCode, isPrimitive, modifyMatching, modifyMatching, modifyRange, toString, visitAll, wrapInArray1D, wrapInArray2D, wrapInArrayAnyDMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.ojalgo.structure.Access1D
asCollectable1D, asKeyed1D, asList, byteValue, byteValue, elements, floatValue, floatValue, intValue, intValue, longValue, longValue, select, shortValue, shortValue, toList, toRawCopy1DMethods inherited from interface org.ojalgo.structure.Access1D.Aggregatable
aggregateAllMethods inherited from interface org.ojalgo.structure.Access1D.Collectable
collectMethods inherited from interface org.ojalgo.structure.Mutate1D
set, set, set, set, set, set, set, set, setMethods inherited from interface org.ojalgo.structure.Mutate1D.Fillable
fillCompatible, fillMatching, fillMatching, fillMatching, fillMatching
-
Method Details
-
factory
public static <N extends Comparable<N>> SparseArray.SparseFactory<N> factory(PlainArray.Factory<N, ?> denseFactory) -
add
public void add(int index, double addend) -
add
-
add
public void add(long index, double addend) -
add
public void add(long index, float addend) -
axpy
Description copied from interface:Access1DWill calculate y = y + a x, will add "a" times "this" to "y"- Parameters:
a- The scaley- The "vector" to update
-
count
public long count()Description copied from interface:Structure1DThe total number of elements in this structure.You only need to implement this method if the structure can contain more than Integer.MAX_VALUE elements.
-
countNonzeros
public int countNonzeros() -
countZeros
public long countZeros() -
dot
Description copied from interface:Access1DWill calculate and return the dot product of this 1D-structure and another input 1D-vector.- Parameters:
vector- Another 1D-structure- Returns:
- The dot product
-
doubleValue
public double doubleValue(int index) -
doubleValue
public double doubleValue(long index) -
exchange
public void exchange(int indexA, int indexB) Efficiently exchanges two elements in the sparse array.This method is optimized for sparse arrays and handles all cases efficiently:
- Both elements are nonzero (direct swap)
- One element is zero, other is nonzero (remove one, add other)
- Both elements are zero (no operation needed)
- Parameters:
indexA- the first index to exchangeindexB- the second index to exchange
-
fillAll
-
fillAll
-
fillRange
-
fillRange
-
firstInRange
public long firstInRange(long rangeFirst, long rangeLimit) -
get
-
indexOfLargest
public long indexOfLargest()- Specified by:
indexOfLargestin interfaceAccess1D.Aggregatable<N extends Comparable<N>>- Overrides:
indexOfLargestin classBasicArray<N extends Comparable<N>>
-
limitOfRange
public long limitOfRange(long rangeFirst, long rangeLimit) -
modifyAll
- Specified by:
modifyAllin interfaceMutate1D.Modifiable<N extends Comparable<N>>- Overrides:
modifyAllin classBasicArray<N extends Comparable<N>>
-
modifyOne
-
nonzeros
Description copied from interface:Access1DSimilar toAccess1D.elements()but avoids elements that are structurally known to be zero. (That does not eliminate all zero-values from this view.) With an arbitrary (dense) unstructured implementation theAccess1D.nonzeros()andAccess1D.elements()methods do the same thing! Only some specific implementations are able to actually exploit structure/sparsity to view fewer elements. -
putLast
public void putLast(int index, double value) Efficiently appends a new nonzero element at the end of this sparse array.This method assumes that the supplied
indexis strictly greater than all existing indices in the array. No search is performed; the value is simply appended. If the ascending order of indices is broken, future behavior is unspecified. If the value is zero, nothing is stored.- Parameters:
index- the index at which to insert the new value (must be after all existing indices)value- the value to insert (only nonzero values are actually stored)
-
removeShiftAndInsert
public void removeShiftAndInsert(int first, int last, double newValue) All elements with indices in the range [first,last] should be shifted one step to the left (their indices decreased by 1). It is safe to assume that there is currently nothing stored at 'from'. The new value 'newValue' should be placed at position 'last'. That position is typically freed by the shift. If 'newValue' is zero it doesn't have to stored. The case where the range [first,last] was originally empty, but the new value is non-zero requires special logic. -
reset
public void reset()Description copied from interface:Mutate1DReset this mutable structure to some standard (all zeros) initial state. It must still be usuable after this call, and the structure/size/shape must not change. -
set
public void set(int index, double value) -
set
-
set
public void set(long index, double value) -
set
public void set(long index, float value) -
size
public int size()Description copied from interface:Structure1DThe total number of elements in this structure. -
supplyNonZerosTo
public void supplyNonZerosTo(double[] receiver) Does NOT first reset the receiver! That means the elements in the receiver corresponding to zeros in this sparse array are not zero:ed or modified in any way. -
supplyNonZerosTo
Does NOT first reset the receiver! That means the elements in the receiver corresponding to zeros in this sparse array are not zero:ed or modified in any way. -
supplyTo
public void supplyTo(double[] receiver) -
supplyTo
- Specified by:
supplyToin interfaceAccess1D.Collectable<N extends Comparable<N>,Mutate1D> - Overrides:
supplyToin classBasicArray<N extends Comparable<N>>
-
visitOne
-
visitPrimitiveNonzerosInRange
public void visitPrimitiveNonzerosInRange(long first, long limit, SparseArray.NonzeroPrimitiveCallback visitor) -
visitRange
- Specified by:
visitRangein interfaceAccess1D.Visitable<N extends Comparable<N>>- Overrides:
visitRangein classBasicArray<N extends Comparable<N>>
-
visitReferenceTypeNonzerosInRange
public void visitReferenceTypeNonzerosInRange(long first, long limit, SparseArray.NonzeroReferenceTypeCallback<N> visitor) -
exchange
protected void exchange(long firstA, long firstB, long step, long count) - Overrides:
exchangein classBasicArray<N extends Comparable<N>>
-
fill
- Overrides:
fillin classBasicArray<N extends Comparable<N>>
-
fill
- Overrides:
fillin classBasicArray<N extends Comparable<N>>
-
indexOfLargest
protected long indexOfLargest(long first, long limit, long step) - Overrides:
indexOfLargestin classBasicArray<N extends Comparable<N>>
-
modify
protected void modify(long first, long limit, long step, Access1D<N> left, BinaryFunction<N> function) - Overrides:
modifyin classBasicArray<N extends Comparable<N>>
-
modify
protected void modify(long first, long limit, long step, BinaryFunction<N> function, Access1D<N> right) - Overrides:
modifyin classBasicArray<N extends Comparable<N>>
-
modify
- Overrides:
modifyin classBasicArray<N extends Comparable<N>>
-
visit
- Overrides:
visitin classBasicArray<N extends Comparable<N>>
-