code: private void normalize(DoubleVector v) {
          double magnitude = 0;
          for (int i = 0; i < v.length(); ++i)
              magnitude += Math.pow(v.get(i), 2);
          if (magnitude == 0)
              return;
  
          magnitude = Math.sqrt(magnitude);
          for (int i = 0; i < v.length(); ++i)
              v.set(i, v.get(i)/magnitude);
      }
docs: Performs l2-normalization on the vector in place.  If the magnitude of
  the vector is 0, the values are left unchanged.