How to find the index of maximum element in ojalgo?
To find maximum I can use double res = mat.aggregateAll(Aggregator.MAXIMUM);, but how to find the maximum's indices?
PS: the mat is type of SparseStore<Double>
How to find the index of maximum element in ojalgo?
To find maximum I can use double res = mat.aggregateAll(Aggregator.MAXIMUM);, but how to find the maximum's indices?
PS: the mat is type of SparseStore<Double>
Copyright © 2021 Jogjafile Inc.
You don't specify what type
matis?There is a method
indexOfLargest()defined in theAccess1D.Aggregatableinterface – implemented by a lot of different classes. But, this corresponds toAggregator.LARGESTrather thanAggregator.MAXIMUM.Since you tagged the question with sparse-matrix I assume the type is
SparseStore, and that could be problematic, usingindexOfLargest(), as I believe its implementation of that method does not exploit sparsity. (It's just some inherited default method that would perform terribly on a sparse matrix.)You can, quite efficiently, iterate over all nonzero elements in a
SparseStore: