Computes the 1-norm of a sparse matrix = max (sum (abs (A))), largest
column sum.

@param A
column-compressed matrix
@return the 1-norm if successful, -1 on error
760075
public static double cs_norm(Dcs A) {
        int p, j, n, Ap[];
        double Ax[], norm = 0, s;
        if (!Dcs_util.CS_CSC(A) || A.x == null)
            return (-1); /* check inputs */
        n = A.n;
        Ap = A.p;
        Ax = A.x;
        for (j = 0; j < n; j++) {
            for (s = 0, p = Ap[j]; p < Ap[j + 1]; p++)
                s += Math.abs(Ax[p]);
            norm = Math.max(norm, s);
        }
        return (norm);
    }
933955
public static double norm_inf(float[] a) {
    double max = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < a.length; i++) {
      if (Math.abs(a[i]) > max) {
        max = Math.abs(a[i]);
      }
    }
    return max;
  }
1025283
private static double getNorm(double[] w)
  {
    double norm = 0;
    for (int i = 0; i < w.length; i++) {
      norm += w[i]*w[i];
    }
    return norm;
  }
465032
public static double elementMaxAbs( DMatrix2x2 a ) {
        double max = Math.abs(a.a11);
        double tmp = Math.abs(a.a12); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a21); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a22); if( tmp > max ) max = tmp;

        return max;
    }
548827
public static double elementMax( DMatrix6 a ) {
        double max = a.a1;
        if( a.a2 > max ) max = a.a2;
        if( a.a3 > max ) max = a.a3;
        if( a.a4 > max ) max = a.a4;
        if( a.a5 > max ) max = a.a5;
        if( a.a6 > max ) max = a.a6;

        return max;
    }
989132
public static final DoubleMatrix2D diagonalMatrixMult(final DoubleMatrix1D diagonalU, DoubleMatrix2D A, final DoubleMatrix1D diagonalV){
		int r = A.rows();
		int c = A.columns();
		final DoubleMatrix2D ret;
		if (A instanceof SparseDoubleMatrix2D) {
			ret = DoubleFactory2D.sparse.make(r, c);
			A.forEachNonZero(new IntIntDoubleFunction() {
				@Override
				public double apply(int i, int j, double aij) {
					ret.setQuick(i, j, aij * diagonalU.getQuick(i) * diagonalV.getQuick(j));
					return aij;
				}
			});
		} else {
			ret = DoubleFactory2D.dense.make(r, c);
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					ret.setQuick(i, j, A.getQuick(i, j) * diagonalU.getQuick(i)	* diagonalV.getQuick(j));
				}
			}
		}

		return ret;
	}
1194710
@Override
    public double compute(double a, double b) {
        if (Op.isLt(a + b, 1.0)) {
            return Op.max(a, b);
        }
        return 1.0;
    }
16331
def safe_unit_norm(a):
    
    if 1 == len(a.shape):
        n = np.linalg.norm(a)
        if n:
            return a / n
        return a

    norm = np.sum(np.abs(a) ** 2, axis=-1) ** (1. / 2)

    # Dividing by a norm of zero will cause a warning to be issued. Set those
    # values to another number. It doesn't matter what, since we'll be dividing
    # a vector of zeros by the number, and 0 / N always equals 0.
    norm[norm == 0] = -1e12
    return a / norm[:, np.newaxis]
91599
public static SparseMatrix from1DArray(int rows, int columns, double[] array) {
        return CRSMatrix.from1DArray(rows, columns, array);
    }
524604
public static double elementMax( DMatrixSparseCSC A ) {
        if( A.nz_length == 0)
            return 0;

        // if every element is assigned a value then the first element can be a max.
        // Otherwise zero needs to be considered
        double max = A.isFull() ? A.nz_values[0] : 0;
        for(int i = 0; i < A.nz_length; i++ ) {
            double val = A.nz_values[i];
            if( val > max ) {
                max = val;
            }
        }

        return max;
    }
531852
public static double elementMaxAbs( DMatrix5 a ) {
        double max = Math.abs(a.a1);
        double tmp = Math.abs(a.a2); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a2); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a3); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a4); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a5); if( tmp > max ) max = tmp;

        return max;
    }
1266825
public static double elementMaxAbs( DMatrix6 a ) {
        double max = Math.abs(a.a1);
        double tmp = Math.abs(a.a2); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a2); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a3); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a4); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a5); if( tmp > max ) max = tmp;
        tmp = Math.abs(a.a6); if( tmp > max ) max = tmp;

        return max;
    }
500504
public static double normInf(double[] x) {
        int n = x.length;

        double f = Math.abs(x[0]);
        for (int i = 1; i < n; i++) {
            f = Math.max(f, Math.abs(x[i]));
        }

        return f;
    }
741886
public function norm1()
    {
        $r = 0;
 
        for ($j = 0; $j < $this->n; $j++) {
            $s = 0;
 
            for ($i = 0; $i < $this->m; $i++) {
                $s += abs($this->A[$i][$j]);
            }
 
            $r = ($r > $s) ? $r : $s;
        }
 
        return $r;
    }
612135
public static DMatrixSparseCSC extractColumn(DMatrixSparseCSC A , int column , @Nullable DMatrixSparseCSC out ) {

        if( out == null )
            out = new DMatrixSparseCSC(1,1,1);

        int idx0 = A.col_idx[column];
        int idx1 = A.col_idx[column+1];

        out.reshape(A.numRows,1,idx1-idx0);
        out.nz_length = idx1-idx0;

        out.col_idx[0] = 0;
        out.col_idx[1] = out.nz_length;

        System.arraycopy(A.nz_values,idx0,out.nz_values,0,out.nz_length);
        System.arraycopy(A.nz_rows,idx0,out.nz_rows,0,out.nz_length);

        return out;
    }
419301
public static double normP2( DMatrixRMaj A ) {
        if( MatrixFeatures_DDRM.isVector(A)) {
            return normF(A);
        } else {
            return inducedP2(A);
        }
    }
709904
public static double[] normalizeL1(double[] vector) {
		// compute vector 1-norm
		double norm1 = 0;
		for (int i = 0; i < vector.length; i++) {
			norm1 += Math.abs(vector[i]);
		}

		if (norm1 == 0) {
			Arrays.fill(vector, 1.0 / vector.length);
		} else {
			for (int i = 0; i < vector.length; i++) {
				vector[i] = vector[i] / norm1;
			}
		}
		return vector;
	}