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

Method dot

JSAT/src/jsat/linear/SparseVector.java:487–514  ·  view source on GitHub ↗
(Vec v)

Source from the content-addressed store, hash-verified

485 }
486
487 @Override
488 public double dot(Vec v)
489 {
490 double dot = 0;
491
492 if(v instanceof SparseVector)
493 {
494 SparseVector b = (SparseVector) v;
495 int p1 = 0, p2 = 0;
496 while (p1 < used && p2 < b.used)
497 {
498 int a1 = indexes[p1], a2 = b.indexes[p2];
499 if (a1 == a2)
500 dot += values[p1++] * b.values[p2++];
501 else if (a1 > a2)
502 p2++;
503 else
504 p1++;
505 }
506 }
507 else if(v.isSparse())
508 return super.dot(v);
509 else// it is dense
510 for (int i = 0; i < used; i++)
511 dot += values[i] * v.get(indexes[i]);
512
513 return dot;
514 }
515
516 @Override
517 public String toString()

Callers 2

multiplyMethod · 0.95
computePhiMethod · 0.95

Calls 2

isSparseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected