use of org.nd4j.linalg.exception.ND4JIllegalStateException in project nd4j by deeplearning4j.
the class DynamicCustomOp method opHash.
/**
* This method returns LongHash of the opName()
*
* @return
*/
@Override
public long opHash() {
if (hash == 0) {
val map = Nd4j.getExecutioner().getCustomOperations();
val desc = map.get(opName());
if (desc == null) {
throw new ND4JIllegalStateException("Op name " + opName() + " is missing!");
}
hash = desc.getHash();
}
return hash;
}
use of org.nd4j.linalg.exception.ND4JIllegalStateException in project nd4j by deeplearning4j.
the class DynamicCustomOp method builder.
/**
* This method takes custom opname, and return Op DynamicCustomOpsBuilder instance
*
* @param opName
* @return
*/
public static DynamicCustomOpsBuilder builder(String opName) {
val map = Nd4j.getExecutioner().getCustomOperations();
val lcName = map.containsKey(opName) ? opName : opName.toLowerCase();
val desc = map.get(lcName);
if (desc == null)
throw new ND4JIllegalStateException("Unknown operations requested: [" + opName + "]");
return new DynamicCustomOpsBuilder(lcName, desc.getHash(), desc.getNumInputs(), desc.getNumOutputs(), desc.isAllowsInplace(), desc.getNumTArgs(), desc.getNumIArgs());
}
use of org.nd4j.linalg.exception.ND4JIllegalStateException in project nd4j by deeplearning4j.
the class BaseNDArray method percentile.
@Override
public INDArray percentile(Number quantile, int... dimension) {
if (quantile.doubleValue() < 0 || quantile.doubleValue() > 100)
throw new ND4JIllegalStateException("Percentile value should be in 0...100 range");
if (isScalar())
return Nd4j.scalar(this.getDouble(0));
INDArray sorted = Nd4j.getNDArrayFactory().sort(this.dup(this.ordering()), false, dimension);
// there's no practical sense doing this on GPU, stride will be just size of TAD.
INDArray ret = Nd4j.createUninitialized(sorted.tensorssAlongDimension(dimension));
for (int i = 0; i < ret.length(); i++) {
ret.putScalar(i, getPercentile(quantile, sorted.tensorAlongDimension(i, dimension)));
}
return ret;
}
use of org.nd4j.linalg.exception.ND4JIllegalStateException in project nd4j by deeplearning4j.
the class Nd4j method create.
/**
* Create an ndrray with the specified shape
*
* @param data the data to use with tne ndarray
* @param shape the shape of the ndarray
* @return the created ndarray
*/
public static INDArray create(float[] data, int[] shape, char ordering) {
shape = getEnsuredShape(shape);
if (shape.length == 1) {
if (shape[0] == data.length) {
shape = new int[] { 1, data.length };
} else
throw new ND4JIllegalStateException("Shape of the new array " + Arrays.toString(shape) + " doesn't match data length: " + data.length);
}
checkShapeValues(data.length, shape);
INDArray ret = INSTANCE.create(data, shape, ordering);
logCreationIfNecessary(ret);
return ret;
}
use of org.nd4j.linalg.exception.ND4JIllegalStateException in project nd4j by deeplearning4j.
the class Nd4j method create.
/**
* Create an ndrray with the specified shape
*
* @param data the data to use with tne ndarray
* @param shape the shape of the ndarray
* @return the created ndarray
*/
public static INDArray create(float[] data, int[] shape) {
if (shape.length == 0 && data.length == 1) {
return trueScalar(data[0]);
}
shape = getEnsuredShape(shape);
if (shape.length == 1) {
if (shape[0] != data.length)
throw new ND4JIllegalStateException("Shape of the new array doesn't match data length");
}
checkShapeValues(data.length, shape);
INDArray ret = INSTANCE.create(data, shape);
logCreationIfNecessary(ret);
return ret;
}
Aggregations