Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #32945

parallel stream calculate matrix

Newsgroups comp.lang.java.programmer
Date 2015-10-27 14:44 -0700
Message-ID <a3f9f833-77dd-40d0-9711-e036928f4bf8@googlegroups.com> (permalink)
Subject parallel stream calculate matrix
From Philipp Kraus <philipp.kraus.flashpixx@gmail.com>

Show all headers | View raw


Hello,

I would like to calculate row-wise a matrix with a parallel stream. In a short excerpt of my code:

Map<myData, Double> x = new HashMap();
ArrayList<myData> y = new ArrayList( x.keySet() );

Matrix m = new Matrix( y.size(), y.size() );

for( int i=0; i < y.size(); i++)
{
      for( int j= i+1; j < y.size(); j++)
      {
            double v = calculate( y.get(i), y.get(j) );
            m.set(i,j) = v;
            m.set(j,i) = v;
      }

      m.normalize(i);
}

I would like to do the first loop in parallel, because each row is independed from the others, but the first element on x must be defined on the first row / column on my matrix. My problem is, that I need on one hand an index value to address the cells within the matrix and the key value to calculate the value. I'm searching for a solution like zip in Python:

for index, data in zip()

(How) Can I do this in Java?

Thanks

Phil

Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

parallel stream calculate matrix Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-10-27 14:44 -0700

csiph-web