Search in sources :

Example 16 with ND4JIllegalStateException

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;
}
Also used : lombok.val(lombok.val) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Example 17 with ND4JIllegalStateException

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());
}
Also used : lombok.val(lombok.val) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Example 18 with ND4JIllegalStateException

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;
}
Also used : ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Example 19 with ND4JIllegalStateException

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;
}
Also used : ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Example 20 with ND4JIllegalStateException

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;
}
Also used : ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Aggregations

ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)116 lombok.val (lombok.val)26 INDArray (org.nd4j.linalg.api.ndarray.INDArray)23 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)21 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)19 DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)17 CudaPointer (org.nd4j.jita.allocator.pointers.CudaPointer)15 PagedPointer (org.nd4j.linalg.api.memory.pointers.PagedPointer)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 BaseDataBuffer (org.nd4j.linalg.api.buffer.BaseDataBuffer)7 IComplexNDArray (org.nd4j.linalg.api.complex.IComplexNDArray)6 Pointer (org.bytedeco.javacpp.Pointer)5 ArrayList (java.util.ArrayList)4 DifferentialFunction (org.nd4j.autodiff.functions.DifferentialFunction)4 Aeron (io.aeron.Aeron)3 FragmentAssembler (io.aeron.FragmentAssembler)3 MediaDriver (io.aeron.driver.MediaDriver)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Slf4j (lombok.extern.slf4j.Slf4j)3 CloseHelper (org.agrona.CloseHelper)3