@Override
    public DenseVector subtract(SGDVector other) {
        if (other.size() != elements.length) {
            throw new IllegalArgumentException("Can't subtract 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 subtract() {
        DenseVector a = generateVectorA();
        DenseVector b = generateVectorB();
        DenseVector c = generateVectorC();
        DenseVector empty = generateEmptyVector();

        assertEquals(a,a.subtract(empty), "A - empty");
        assertEquals(invert(a),empty.subtract(a), "empty - A");
        assertEquals(b,b.subtract(empty), "B - empty");
        assertEquals(invert(b),empty.subtract(b), "empty - B");
        assertEquals(c,c.subtract(empty), "C - empty");
        assertEquals(invert(c),empty.subtract(c), "empty - C");

        assertEquals(zero(a),a.subtract(a), "A - A");
        assertEquals(zero(b),b.subtract(b), "B - B");
        assertEquals(zero(c),c.subtract(c), "C - C");

        DenseVector aSubB = generateVectorASubB();
        DenseVector aSubC = generateVectorASubC();
        DenseVector bSubA = generateVectorBSubA();
        DenseVector bSubC = generateVectorBSubC();
        DenseVector cSubA = generateVectorCSubA();
        DenseVector cSubB = generateVectorCSubB();

        assertEquals(aSubB, a.subtract(b), "A - B");
        assertEquals(aSubC, a.subtract(c), "A - C");
        assertEquals(bSubA, b.subtract(a), "B - A");
        assertEquals(bSubC, b.subtract(c), "B - C");
        assertEquals(cSubA, c.subtract(a), "C - A");
        assertEquals(cSubB, c.subtract(b), "C - B");
    }