VectorView extends AbstractVector { @Override public double dot(Vector x) { if (size() != x.size()) { throw new CardinalityException(size(), x.size()); } double result = 0; for (int i = 0; i < size(); i++) { result += getQuick(i) * x.getQuick(i); } return result; } VectorView();  VectorView(Vector vector, int offset, int cardinality); @Override Vector clone(); @Override boolean isDense(); @Override boolean isSequentialAccess(); @Override VectorView like(); @Override double getQuick(int index); @Override void setQuick(int index, double value); @Override int getNumNondefaultElements(); @Override Vector viewPart(int offset, int length); @Override Iterator<Element> iterateNonZero(); @Override Iterator<Element> iterator(); @Override double dot(Vector x); @Override double getLengthSquared(); @Override double getDistanceSquared(Vector v); @Override void addTo(Vector v);  }
@Test public void testDot() throws Exception { double res = test.dot(test); assertEquals("dot", 1.1 * 1.1 + 2.2 * 2.2 + 3.3 * 3.3, res, EPSILON); }
@Test(expected = CardinalityException.class) public void testDotCardinality() { test.dot(new DenseVector(test.size() + 1)); }