Matrix Multiplication java 1.8

Do you find it possible to implement sparse matrix operations using the new Stream interface in Java 1.8? If so, how do we need to implement matrices and operations. It’s clear that I’m looking for it in order to eventually use “automatic” parallelization.

+4
source share
1 answer

It can be done. How about something like below for a simple SPMV (vector matrix multiplication), with a sparse matrix presented in COO format (the simplest rare format):

class COO {
    int x, y, value;
}

public static ArrayList<Integer> spmv(List<COO> values, ArrayList<Integer> v) {
    final ArrayList<Integer> result = new ArrayList<>(Collections.nCopies(v.size(), 0));
    values.stream().forEach(
            coo -> result.set(coo.x, result.get(coo.x) + coo.value * v.get(coo.y))
    );
    return result;
}

- , 3 . /, , ( ):

, . , :

, , - la4j .

+2

Source: https://habr.com/ru/post/1523408/


All Articles