Scale by 1 / norm2 of the matrix

@param toScale the ndarray to scale
@return the scaled ndarray
770512
public static INDArray unitVec(INDArray toScale) {
        double length = toScale.norm2Number().doubleValue();

        if (length > 0) {
            if (toScale.data().dataType() == (DataType.FLOAT))
                return Nd4j.getBlasWrapper().scal(1.0f / (float) length, toScale);
            else
                return Nd4j.getBlasWrapper().scal(1.0 / length, toScale);

        }
        return toScale;
    }
1043657
public static LinearScale[] calcScales(Relation<? extends SpatialComparable> rel) {
    int dim = RelationUtil.dimensionality(rel);
    DoubleMinMax[] minmax = DoubleMinMax.newArray(dim);
    LinearScale[] scales = new LinearScale[dim];

    // analyze data
    for(DBIDIter iditer = rel.iterDBIDs(); iditer.valid(); iditer.advance()) {
      SpatialComparable v = rel.get(iditer);
      if(v instanceof NumberVector) {
        for(int d = 0; d < dim; d++) {
          final double mi = v.getMin(d);
          if(mi != mi) { // NaN
            continue;
          }
          minmax[d].put(mi);
        }
      }
      else {
        for(int d = 0; d < dim; d++) {
          final double mi = v.getMin(d);
          if(mi == mi) { // No NaN
            minmax[d].put(mi);
          }
          final double ma = v.getMax(d);
          if(ma == ma) { // No NaN
            minmax[d].put(ma);
          }
        }
      }
    }

    // generate scales
    for(int d = 0; d < dim; d++) {
      scales[d] = new LinearScale(minmax[d].getMin(), minmax[d].getMax());
    }
    return scales;
  }
509307
public static BigDecimal setScale(final BigDecimal bd, final int scale) {
        return setScale(bd, scale, BigDecimal.ROUND_HALF_UP);
    }
1040154
def scale(arr, mn=0, mx=1):
    
    amn = arr.min()
    amx = arr.max()
    # normalize:
    arr = (arr - amn) / (amx - amn)
    # scale:
    if amn != mn or amx != mx:
        arr *= mx - mn
        arr += mn
    return arr
965016
public static double calculateScaledResidual(DoubleMatrix2D A, DoubleMatrix2D X, DoubleMatrix2D B){
		double residual = -Double.MAX_VALUE;
		double niX = Algebra.DEFAULT.normInfinity(X);
		double niB = Algebra.DEFAULT.normInfinity(B);
		if(Double.compare(niX, 0.)==0 && Double.compare(niB, 0.)==0){
			return 0;
		}else{
			double num = Algebra.DEFAULT.normInfinity(Algebra.DEFAULT.mult(A, X).assign(B,	Functions.minus));
			double den = Algebra.DEFAULT.normInfinity(A) * niX + niB;
			residual =  num / den;
			//log.debug("scaled residual: " + residual);
			
			return residual;
		}
	}
452828
private static void scaleDownFive(Slice decimal, int fiveScale, Slice result)
    {
        while (true) {
            int powerFive = Math.min(fiveScale, MAX_POWER_OF_FIVE_INT);
            fiveScale -= powerFive;

            int divisor = POWERS_OF_FIVES_INT[powerFive];
            divide(decimal, divisor, result);
            decimal = result;

            if (fiveScale == 0) {
                return;
            }
        }
    }
683435
public static final Function<Number,Float> toFloat(final int scale, final RoundingMode roundingMode) {
        return new ToFloat(scale, roundingMode);
    }
1209243
public static double calculateScaledResidual(DoubleMatrix2D A, DoubleMatrix1D x, DoubleMatrix1D b){
		double residual = -Double.MAX_VALUE;
		double nix = Algebra.DEFAULT.normInfinity(x);
		double nib = Algebra.DEFAULT.normInfinity(b);
		if(Double.compare(nix, 0.)==0 && Double.compare(nib, 0.)==0){
			return 0;
		}else{
			double num = Algebra.DEFAULT.normInfinity(ColtUtils.zMult(A, x, b, -1));
			double den = Algebra.DEFAULT.normInfinity(A) * nix + nib;
			residual =  num / den;
			//log.debug("scaled residual: " + residual);
			
			return residual;
		}
	}
317253
public static void scaleMinMax(double min, double max, INDArray toScale) {
        //X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0)) X_scaled = X_std * (max - min) + min

        INDArray min2 = toScale.min(0);
        INDArray max2 = toScale.max(0);

        INDArray std = toScale.subRowVector(min2).diviRowVector(max2.sub(min2));

        INDArray scaled = std.mul(max - min).addi(min);
        toScale.assign(scaled);
    }
847024
private ScalesResult run(Relation<? extends NumberVector> rel) {
    final int dim = RelationUtil.dimensionality(rel);
    LinearScale[] scales = new LinearScale[dim];
    if(minmax == null) {
      DoubleMinMax mm = new DoubleMinMax();
      for(DBIDIter iditer = rel.iterDBIDs(); iditer.valid(); iditer.advance()) {
        NumberVector vec = rel.get(iditer);
        for(int d = 0; d < dim; d++) {
          final double val = vec.doubleValue(d);
          if(val != val) {
            continue; // NaN
          }
          mm.put(val);
        }
      }
      LinearScale scale = new LinearScale(mm.getMin(), mm.getMax());
      for(int i = 0; i < dim; i++) {
        scales[i] = scale;
      }
    }
    else {
      // Use predefined.
      LinearScale scale = new LinearScale(minmax[0], minmax[1]);
      for(int i = 0; i < dim; i++) {
        scales[i] = scale;
      }
    }
    ScalesResult res = new ScalesResult(scales);
    return res;
  }
545036
public Matrix4f scaleAround(float sx, float sy, float sz, float ox, float oy, float oz, Matrix4f dest) {
        float nm30 = m00 * ox + m10 * oy + m20 * oz + m30;
        float nm31 = m01 * ox + m11 * oy + m21 * oz + m31;
        float nm32 = m02 * ox + m12 * oy + m22 * oz + m32;
        float nm33 = m03 * ox + m13 * oy + m23 * oz + m33;
        dest._m00(m00 * sx);
        dest._m01(m01 * sx);
        dest._m02(m02 * sx);
        dest._m03(m03 * sx);
        dest._m10(m10 * sy);
        dest._m11(m11 * sy);
        dest._m12(m12 * sy);
        dest._m13(m13 * sy);
        dest._m20(m20 * sz);
        dest._m21(m21 * sz);
        dest._m22(m22 * sz);
        dest._m23(m23 * sz);
        dest._m30(-m00 * ox - m10 * oy - m20 * oz + nm30);
        dest._m31(-m01 * ox - m11 * oy - m21 * oz + nm31);
        dest._m32(-m02 * ox - m12 * oy - m22 * oz + nm32);
        dest._m33(-m03 * ox - m13 * oy - m23 * oz + nm33);
        boolean one = Math.abs(sx) == 1.0f && Math.abs(sy) == 1.0f && Math.abs(sz) == 1.0f;
        dest._properties(properties & ~(PROPERTY_PERSPECTIVE | PROPERTY_IDENTITY | PROPERTY_TRANSLATION
                | (one ? 0 : PROPERTY_ORTHONORMAL)));
        return dest;
    }
946544
func ToScale(input, min, max float64) float64 {
	i := input*(math.Max(min, max)-math.Min(min, max)) + math.Min(min, max)
	if i < math.Min(min, max) {
		return math.Min(min, max)
	} else if i > math.Max(min, max) {
		return math.Max(min, max)
	} else {
		return i
	}
}
793887
public static BigDecimal setScale(final BigDecimal bd, final Integer scale, final int rounding) {
        if (bd != null && scale != null) {
            return bd.setScale(scale, rounding);
        }
        return null;
    }
247110
@SuppressWarnings("checkstyle:magicnumber")
	public void setScale(double scaleX, double scaleY) {
		final double[] tmpScale = new double[3];
		final double[] tmpRot = new double[9];
		getScaleRotate2x2(tmpScale, tmpRot);
		this.m00 = tmpRot[0] * scaleX;
		this.m01 = tmpRot[1] * scaleY;
		this.m10 = tmpRot[3] * scaleX;
		this.m11 = tmpRot[4] * scaleY;
	}
889891
@Pure
	@SuppressWarnings("checkstyle:magicnumber")
	public double getScale() {
		final double[] tmpScale = new double[3];
		final double[] tmpRot = new double[9];
		getScaleRotate2x2(tmpScale, tmpRot);
		return MathUtil.max(tmpScale);
	}
1229190
private ScalesResult run(Relation<? extends NumberVector> rel) {
    double[][] mms = RelationUtil.computeMinMax(rel);
    int dim = mms[0].length;
    double delta = 0.;
    for(int d = 0; d < dim; d++) {
      double del = mms[1][d] - mms[0][d];
      delta = del > delta ? del : delta;
    }
    if(delta < Double.MIN_NORMAL) {
      delta = 1.;
    }
    int log10res = (int) Math.ceil(Math.log10(delta / (LinearScale.MAXTICKS - 1)));
    double res = MathUtil.powi(10, log10res);
    double target = Math.ceil(delta / res) * res; // Target width
    LinearScale[] scales = new LinearScale[dim];
    for(int d = 0; d < dim; d++) {
      double mid = (mms[0][d] + mms[1][d] - target) * .5;
      double min = Math.floor(mid / res) * res;
      double max = Math.ceil((mid + target) / res) * res;
      scales[d] = new LinearScale(min, max);
    }
    return new ScalesResult(scales);
  }
950774
def get_scaled_v2(self, amount):
        """"""

        return Vec2(self.x * amount, self.y * amount)