use of org.apache.ignite.ml.math.impls.storage.vector.SparseDistributedVectorStorage in project ignite by apache.
the class SparseDistributedMatrix method times.
/**
* {@inheritDoc}
*/
@Override
public Vector times(Vector vec) {
if (vec == null)
throw new IllegalArgumentException("The vector should be not null.");
if (columnSize() != vec.size())
throw new CardinalityException(columnSize(), vec.size());
SparseDistributedMatrix matrixA = this;
SparseDistributedVector vectorB = (SparseDistributedVector) vec;
String cacheName = storage().cacheName();
int rows = this.rowSize();
SparseDistributedVector vectorC = (SparseDistributedVector) likeVector(rows);
CacheUtils.bcast(cacheName, () -> {
Ignite ignite = Ignition.localIgnite();
Affinity<RowColMatrixKey> affinity = ignite.affinity(cacheName);
ClusterNode locNode = ignite.cluster().localNode();
SparseDistributedVectorStorage storageC = vectorC.storage();
Map<ClusterNode, Collection<RowColMatrixKey>> keysCToNodes = affinity.mapKeysToNodes(storageC.getAllKeys());
Collection<RowColMatrixKey> locKeys = keysCToNodes.get(locNode);
if (locKeys == null)
return;
// compute Cij locally on each node
// TODO: IGNITE:5114, exec in parallel
locKeys.forEach(key -> {
int idx = key.index();
Vector Aik = matrixA.getRow(idx);
vectorC.set(idx, Aik.times(vectorB).sum());
});
});
return vectorC;
}
Aggregations