@Override
    public DenseVector add(SGDVector other) {
        if (other.size() != elements.length) {
            throw new IllegalArgumentException("Can't add two vectors of different dimension, this = " + elements.length + ", other = " + other.size());
        }
        double[] newValues = toArray();
        for (VectorTuple tuple : other) {
            newValues[tuple.index] += tuple.value;
        }
        return new DenseVector(newValues);
    }
@Test
    public void add() {
        DenseVector a = generateVectorA();
        DenseVector b = generateVectorB();
        DenseVector c = generateVectorC();
        DenseVector empty = generateEmptyVector();

        assertEquals(a,a.add(empty), "A + empty");
        assertEquals(b,b.add(empty), "B + empty");
        assertEquals(c,c.add(empty), "C + empty");

        assertEquals(scale(a,2.0),a.add(a), "A * 2");
        assertEquals(scale(b,2.0),b.add(b), "B * 2");
        assertEquals(scale(c,2.0),c.add(c), "C * 2");

        DenseVector aAddB = generateVectorAAddB();
        DenseVector aAddC = generateVectorAAddC();
        DenseVector bAddC = generateVectorBAddC();

        assertEquals(aAddB, a.add(b), "A + B");
        assertEquals(aAddC, a.add(c), "A + C");
        assertEquals(aAddB, b.add(a), "B + A");
        assertEquals(bAddC, b.add(c), "B + C");
        assertEquals(aAddC, c.add(a), "C + A");
        assertEquals(bAddC, c.add(b), "C + B");
    }