@Override public INDArray nextFloat(char order, int[] shape) { INDArray array = Nd4j.createUninitialized(shape, order); UniformDistribution op = new UniformDistribution(array, 0.0, 1.0); Nd4j.getExecutioner().exec(op, this); return array; }
/** * Sin function * @param in * @param copy * @return */ public static INDArray sin(INDArray in, boolean copy) { return Nd4j.getExecutioner().execAndReturn(new Sin((copy ? in.dup() : in))); }
@Override public INDArray getActivation(INDArray in, boolean training) { Nd4j.getExecutioner().execAndReturn(new SoftSign(in)); return in; }
/** * Returns non-normalized Shannon entropy along dimension * @param dimension * @return */ @Override public INDArray shannonEntropy(int... dimension) { return Nd4j.getExecutioner().exec(new ShannonEntropy(this), dimension); }
public static void checkForInf(INDArray z) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.INF_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; int match = 0; if (!z.isScalar()) { MatchCondition condition = new MatchCondition(z, Conditions.isInfinite()); match = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); } else { if (z.data().dataType() == DataBuffer.Type.DOUBLE) { if (Double.isInfinite(z.getDouble(0))) match = 1; } else { if (Float.isInfinite(z.getFloat(0))) match = 1; } } if (match > 0) throw new ND4JIllegalStateException("P.A.N.I.C.! Op.Z() contains " + match + " Inf value(s)"); }
@Override public INDArray compress(INDArray array) { INDArray dup = array.dup(array.ordering()); Nd4j.getExecutioner().commit(); dup.setData(compress(dup.data())); dup.markAsCompressed(true); return dup; }
/** * Log on arbitrary base * * @param ndArray * @param base * @return */ public static INDArray log(INDArray ndArray, double base, boolean duplicate) { return Nd4j.getExecutioner().exec(new LogX(duplicate ? ndArray.dup(ndArray.ordering()) : ndArray, base)).z(); }
@Override public int iamax(long n, INDArray arr, int stride) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); if (arr.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, arr); return idamax(n, arr, stride); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, arr); return isamax(n, arr, stride); } }
/** * Atan2 operation, new INDArray instance will be returned * Note the order of x and y parameters is opposite to that of java.lang.Math.atan2 * * @param x the abscissa coordinate * @param y the ordinate coordinate * @return the theta from point (r, theta) when converting (x,y) from to cartesian to polar coordinates */ public static INDArray atan2(@NonNull INDArray x, @NonNull INDArray y) { return Nd4j.getExecutioner() .execAndReturn(new OldAtan2Op(x, y, Nd4j.createUninitialized(x.shape(), x.ordering()))); }
/** * Sin function * @param in * @param copy * @return */ public static INDArray atanh(INDArray in, boolean copy) { return Nd4j.getExecutioner().execAndReturn(new ATanh((copy ? in.dup() : in))); }
/** * Negate each element (in-place). */ @Override public INDArray negi() { Nd4j.getExecutioner().exec(new Negative(this)); return this; }
@Override public INDArray nextGaussian(char order, int[] shape) { INDArray array = Nd4j.createUninitialized(shape, order); GaussianDistribution op = new GaussianDistribution(array, 0.0, 1.0); Nd4j.getExecutioner().exec(op, this); return array; }
@Override public INDArray getActivation(INDArray in, boolean training) { Nd4j.getExecutioner().execAndReturn(new RectifiedTanh(in)); return in; }
public static void checkForNaN(INDArray z) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.NAN_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; int match = 0; if (!z.isScalar()) { MatchCondition condition = new MatchCondition(z, Conditions.isNan()); match = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); } else { if (z.data().dataType() == DataBuffer.Type.DOUBLE) { if (Double.isNaN(z.getDouble(0))) match = 1; } else { if (Float.isNaN(z.getFloat(0))) match = 1; } } if (match > 0) throw new ND4JIllegalStateException("P.A.N.I.C.! Op.Z() contains " + match + " NaN value(s): "); }
/** * swaps a vector with another vector. * * @param x * @param y */ @Override public void copy(INDArray x, INDArray y) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, x, y); if (x.isSparse() || y.isSparse()) { Nd4j.getSparseBlasWrapper().level1().copy(x, y); return; } if (x.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, x, y); dcopy(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, x, y); scopy(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); } }
/** * * @param in * @param copy * @return */ public static INDArray cos(INDArray in, boolean copy) { return Nd4j.getExecutioner().execAndReturn(new Cos((copy ? in.dup() : in))); }
/** * Returns the product along a given dimension * * @param dimension the dimension to getScalar the product along * @return the product along the specified dimension */ @Override public INDArray prod(int... dimension) { return Nd4j.getExecutioner().exec(new Prod(this), dimension); }
@Override public INDArray nextGaussian(char order, long[] shape) { INDArray array = Nd4j.createUninitialized(shape, order); GaussianDistribution op = new GaussianDistribution(array, 0.0, 1.0); Nd4j.getExecutioner().exec(op, this); return array; }
@Override public INDArray getActivation(INDArray in, boolean training) { Nd4j.getExecutioner().execAndReturn(new Swish(in)); return in; }
/** * computes a vector by a scalar product. * * @param N * @param alpha * @param X */ @Override public void scal(long N, double alpha, INDArray X) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, X); if (X.isSparse()) { Nd4j.getSparseBlasWrapper().level1().scal(N, alpha, X); } else if (X.data().dataType() == DataBuffer.Type.DOUBLE) dscal(N, alpha, X, BlasBufferUtil.getBlasStride(X)); else if (X.data().dataType() == DataBuffer.Type.FLOAT) sscal(N, (float) alpha, X, BlasBufferUtil.getBlasStride(X)); else if (X.data().dataType() == DataBuffer.Type.HALF) Nd4j.getExecutioner().exec(new ScalarMultiplication(X, alpha)); }