@Override
    public double dot(SGDVector other) {
        if (other.size() != size) {
            throw new IllegalArgumentException("Can't dot two vectors of different lengths, this = " + size + ", other = " + other.size());
        } else if (other instanceof SparseVector) {
            double score = 0.0;

            // If there are elements, calculate the dot product.
            if ((other.numActiveElements() != 0) && (indices.length != 0)) {
                Iterator<VectorTuple> itr = iterator();
                Iterator<VectorTuple> otherItr = other.iterator();
                VectorTuple tuple = itr.next();
                VectorTuple otherTuple = otherItr.next();
                while (itr.hasNext() && otherItr.hasNext()) {
                    if (tuple.index == otherTuple.index) {
                        score += tuple.value * otherTuple.value;
                        tuple = itr.next();
                        otherTuple = otherItr.next();
                    } else if (tuple.index < otherTuple.index) {
                        tuple = itr.next();
                    } else {
                        otherTuple = otherItr.next();
                    }
                }
                while (itr.hasNext()) {
                    if (tuple.index == otherTuple.index) {
                        score += tuple.value * otherTuple.value;
                    }
                    tuple = itr.next();
                }
                while (otherItr.hasNext()) {
                    if (tuple.index == otherTuple.index) {
                        score += tuple.value * otherTuple.value;
                    }
                    otherTuple = otherItr.next();
                }
                if (tuple.index == otherTuple.index) {
                    score += tuple.value * otherTuple.value;
                }
            }

            return score;
        } else if (other instanceof DenseVector) {
            double score = 0.0;

            for (int i = 0; i < indices.length; i++) {
                score += other.get(indices[i]) * values[i];
            }

            return score;
        } else {
            throw new IllegalArgumentException("Unknown vector subclass " + other.getClass().getCanonicalName() + " for input");
        }
    }
@Test
    public void dot() {
        SparseVector a = generateVectorA();
        SparseVector c = generateVectorC();

        assertEquals(a.dot(c),c.dot(a),1e-10);
        assertEquals(16.0, a.dot(c),1e-10);
    }