/** {@inheritDoc} */ @Override protected double bnorm() { return dataset.computeWithCtx((ctx, data) -> { ctx.setU(Arrays.copyOf(data.getLabels(), data.getLabels().length)); return BLAS.getInstance().dnrm2(data.getLabels().length, data.getLabels(), 1); }, (a, b) -> a == null ? b : b == null ? a : Math.sqrt(a * a + b * b)); }
/** {@inheritDoc} */ @Override protected double beta(double[] x, double alfa, double beta) { return dataset.computeWithCtx((ctx, data) -> { if (data.getFeatures() == null) return null; int cols = data.getFeatures().length / data.getRows(); BLAS.getInstance().dgemv("N", data.getRows(), cols, alfa, data.getFeatures(), Math.max(1, data.getRows()), x, 1, beta, ctx.getU(), 1); return BLAS.getInstance().dnrm2(ctx.getU().length, ctx.getU(), 1); }, (a, b) -> a == null ? b : b == null ? a : Math.sqrt(a * a + b * b)); }
@Override protected double dnrm2(int N, INDArray X, int incX) { return BLAS.getInstance().dnrm2(N, getDoubleData(X), getBlasOffset(X), incX); }
/** * Calculate the 2 norm of the ndarray * * @param A * @return */ public static double nrm2(IComplexNDArray A) { if (A.data().dataType() == DataBuffer.Type.FLOAT) { float s = BLAS.getInstance().snrm2(A.length(), A.data().asFloat(), 2, 1); return s; } else if (A.data().dataType() == DataBuffer.Type.DOUBLE) { double s = BLAS.getInstance().dnrm2(A.length(), A.data().asDouble(), 2, 1); return s; } throw new IllegalArgumentException("Illegal data type"); }
/** * Calculate the 2 norm of the ndarray * * @param A * @return */ public static double nrm2(IComplexNDArray A) { if (A.data().dataType() == DataBuffer.Type.FLOAT) { float s = BLAS.getInstance().snrm2(A.length(), A.data().asFloat(), 2, 1); return s; } else if (A.data().dataType() == DataBuffer.Type.DOUBLE) { double s = BLAS.getInstance().dnrm2(A.length(), A.data().asDouble(), 2, 1); return s; } throw new IllegalArgumentException("Illegal data type"); }
/** * Returns the norm2 of the given ndarray * * @param x * @return */ public static double nrm2(INDArray x) { if (x.data().dataType() == DataBuffer.Type.FLOAT) { float normal2 = BLAS.getInstance().snrm2(x.length(), x.data().asFloat(), x.offset(), x.majorStride()); return normal2; } else { double normal2 = BLAS.getInstance().dnrm2(x.length(), x.data().asDouble(), x.offset(), x.majorStride()); return normal2; } }
/** * Returns the norm2 of the given ndarray * * @param x * @return */ public static double nrm2(INDArray x) { if (x.data().dataType() == DataBuffer.Type.FLOAT) { float normal2 = BLAS.getInstance().snrm2(x.length(), x.data().asFloat(), x.offset(), x.majorStride()); return normal2; } else { double normal2 = BLAS.getInstance().dnrm2(x.length(), x.data().asDouble(), x.offset(), x.majorStride()); return normal2; } }