code: public static double sum(DoubleVector v) {
          double sum = 0;
          if (v instanceof SparseVector) {
              for (int nz : ((SparseVector)v).getNonZeroIndices())
                  sum += v.get(nz);
          }
          else {
              int len = v.length();
              for (int i = 0; i < len; ++i)
                  sum += v.get(i);
          }
          return sum;
      }
docs: Sums the values in the vector, returning the result.