MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / multiplyTranspose

Method multiplyTranspose

JSAT/src/jsat/linear/SparseMatrix.java:450–515  ·  view source on GitHub ↗
(Matrix B, Matrix C)

Source from the content-addressed store, hash-verified

448 }
449
450 @Override
451 public void multiplyTranspose(Matrix B, Matrix C)
452 {
453 if(this.cols() != B.cols())
454 throw new ArithmeticException("Matrix dimensions do not agree");
455 else if (this.rows() != C.rows() || B.rows() != C.cols())
456 throw new ArithmeticException("Target Matrix is no the correct size");
457
458 for (int i = 0; i < this.rows(); i++)
459 {
460 final SparseVector A_i = this.rows[i];
461 for (int j = 0; j < B.rows(); j++)
462 {
463 final Vec B_j = B.getRowView(j);
464 double C_ij = 0;
465
466 if(!B_j.isSparse())//B is dense, lets do this the easy way
467 {
468 for (IndexValue iv : A_i)
469 C_ij += iv.getValue() * B_j.get(iv.getIndex());
470 C.increment(i, j, C_ij);
471 continue;//Skip early, we did it!
472 }
473 //else, sparse
474 Iterator<IndexValue> A_iter = A_i.getNonZeroIterator();
475 Iterator<IndexValue> B_iter = B_j.getNonZeroIterator();
476 if(!B_iter.hasNext() || !A_iter.hasNext())//one is all zeros, nothing to do
477 continue;
478
479 IndexValue A_val = A_iter.next();
480 IndexValue B_val = B_iter.next();
481
482 while(A_val != null && B_val != null)//go add everything together!
483 {
484 if(A_val.getIndex() == B_val.getIndex())//inc and bump both
485 {
486 C_ij += A_val.getValue()*B_val.getValue();
487 if(A_iter.hasNext())
488 A_val = A_iter.next();
489 else
490 A_val = null;
491 if(B_iter.hasNext())
492 B_val = B_iter.next();
493 else
494 B_val = null;
495 }
496 else if(A_val.getIndex() < B_val.getIndex())//A is behind, bump it
497 {
498 if(A_iter.hasNext())
499 A_val = A_iter.next();
500 else
501 A_val = null;
502 }
503 else//B is behind, bump it
504 {
505 if(B_iter.hasNext())
506 B_val = B_iter.next();
507 else

Callers

nothing calls this directly

Calls 15

colsMethod · 0.95
rowsMethod · 0.95
isSparseMethod · 0.95
getValueMethod · 0.95
getMethod · 0.95
getIndexMethod · 0.95
getNonZeroIteratorMethod · 0.95
getNonZeroIteratorMethod · 0.95
submitMethod · 0.80
logMethod · 0.80
getNameMethod · 0.65
getRowViewMethod · 0.45

Tested by

no test coverage detected