Java Code Examples for org.nd4j.linalg.api.ndarray.INDArray#lengthLong()

The following examples show how to use org.nd4j.linalg.api.ndarray.INDArray#lengthLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseBroadcastOp.java    From nd4j with Apache License 2.0 5 votes vote down vote up
public BaseBroadcastOp(INDArray x, INDArray y, INDArray z, int... dimension) {
    super(x, y, z, x.lengthLong());
    this.dimension = dimension;
    for (int i = 0; i < dimension.length; i++)
        if (dimension[i] < 0)
            dimension[i] += x.rank();

}
 
Example 2
Source File: NativeOpExecutioner.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public long bitmapEncode(INDArray indArray, INDArray target, double threshold) {
    long length = indArray.lengthLong();
    long tLen = target.data().length();

    if (tLen != (length / 16 + 5))
        throw new ND4JIllegalStateException("Length of target array should be " + (length / 16 + 5));

    if (target.data().dataType() != DataBuffer.Type.INT)
        throw new ND4JIllegalStateException("Target array should have INT dataType");

    DataBuffer buffer = target.data();

    buffer.put(0, (int) length);
    buffer.put(1, (int) length);
    buffer.put(2, Float.floatToIntBits((float) threshold));

    // format id
    buffer.put(3, ThresholdCompression.BITMAP_ENCODING);

    long affected = 0;

    if (indArray.data().dataType() == DataBuffer.Type.FLOAT) {
        affected = loop.encodeBitmapFloat(null, (FloatPointer) indArray.data().addressPointer(), length, (IntPointer) buffer.addressPointer(), (float) threshold);
    } else if (indArray.data().dataType() == DataBuffer.Type.DOUBLE) {
        affected = loop.encodeBitmapDouble(null, (DoublePointer) indArray.data().addressPointer(), length, (IntPointer) buffer.addressPointer(), (float) threshold);
    } else
        throw new UnsupportedOperationException("HALF precision isn't supported on CPU yet");

    return affected;
}
 
Example 3
Source File: And.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public And(@NonNull INDArray x, @NonNull INDArray y, INDArray z) {
    this(x, y, z, z.lengthLong());
}
 
Example 4
Source File: BaseIndexAccumulation.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public BaseIndexAccumulation(INDArray x) {
    this(x, null, x, x.lengthLong());
}
 
Example 5
Source File: OldFloorDivOp.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public OldFloorDivOp(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, x.lengthLong());
}
 
Example 6
Source File: TanhDerivative.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public TanhDerivative(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, z.lengthLong());
}
 
Example 7
Source File: BinaryRelativeError.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public BinaryRelativeError(INDArray x, INDArray y, double threshold) {
    super(x, y, x, x.lengthLong());
    this.threshold = threshold;
}
 
Example 8
Source File: SigmoidDerivative.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public SigmoidDerivative(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, z.lengthLong());
}
 
Example 9
Source File: HardSigmoid.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public HardSigmoid(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, x.lengthLong());
}
 
Example 10
Source File: AMean.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public AMean(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, x.lengthLong());
}
 
Example 11
Source File: Relu6.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public Relu6(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, x.lengthLong());
}
 
Example 12
Source File: EuclideanDistance.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public EuclideanDistance(INDArray x, INDArray y, INDArray z, boolean allDistances) {
    this(x, y, z, x.lengthLong());
    this.isComplex = allDistances;
}
 
Example 13
Source File: LogSigmoid.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public LogSigmoid(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, x.lengthLong());
}
 
Example 14
Source File: AlphaDropOut.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public AlphaDropOut(@NonNull INDArray x, double p, double alpha, double alphaPrime, double beta) {
    this(x, x, p, alpha, alphaPrime, beta, x.lengthLong());
}
 
Example 15
Source File: Or.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public Or(@NonNull INDArray x, @NonNull INDArray y, Number comparable) {
    this(x, y, x, comparable, x.lengthLong());
}
 
Example 16
Source File: Not.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public Not(@NonNull INDArray x, Number comparable) {
    this(x, x, comparable, x.lengthLong());
}
 
Example 17
Source File: RelativeError.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public RelativeError(INDArray x, INDArray y, INDArray z) {
    super(x, y, z, x.lengthLong());
}
 
Example 18
Source File: RelativeError.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public RelativeError(INDArray x, INDArray y) {
    super(x, y, x, x.lengthLong());
}
 
Example 19
Source File: CompareAndSet.java    From nd4j with Apache License 2.0 3 votes vote down vote up
/**
 * With this constructor, op will check each X element against given Condition, and if condition met, element will be replaced with Set value
 *
 * Pseudocode:
 * z[i] = condition(x[i]) ? set : x[i];
 *
 * @param x
 * @param set
 * @param condition
 */
public CompareAndSet(INDArray x, INDArray z, double set, Condition condition) {
    super(x, null, z, x.lengthLong());
    this.compare = condition.getValue();
    this.set = set;
    this.eps = condition.epsThreshold();
    this.mode = condition.condtionNum();
    init(x, null, z, x.lengthLong());
}
 
Example 20
Source File: CudaExecutioner.java    From nd4j with Apache License 2.0 2 votes vote down vote up
@Override
public INDArray thresholdDecode(INDArray encoded, INDArray target) {
    DataBuffer buffer = encoded.data();

    if (buffer.dataType() != DataBuffer.Type.INT)
        throw new UnsupportedOperationException();

    long compressedLength = buffer.getInt(0);
    long originalLength = buffer.getInt(1);

    if (target.lengthLong() != originalLength)
        throw new ND4JIllegalStateException("originalLength ["+ originalLength+"] stored in encoded array doesn't match target length ["+ target.lengthLong()+"]");

    DataBuffer result = target.data();



    CudaContext context = (CudaContext) AtomicAllocator.getInstance().getDeviceContext().getContext();
    //nativeOps.memsetAsync(AtomicAllocator.getInstance().getPointer(result), 0,result.length(), 0, context.getOldStream());

    if (extraz.get() == null)
        extraz.set(new PointerPointer(32));

    PointerPointer extras = extraz.get().put(1, context.getOldStream());

    //log.info("DEC Source length: {}", buffer.length());
    //log.info("DEC Source: {}", Arrays.toString(buffer.asInt()));

    if (Nd4j.dataType() == DataBuffer.Type.FLOAT) {
        nativeOps.decodeThresholdFloat(extras, AtomicAllocator.getInstance().getPointer(buffer), compressedLength, (FloatPointer) AtomicAllocator.getInstance().getPointer(result));
    } else if (Nd4j.dataType() == DataBuffer.Type.DOUBLE) {
        nativeOps.decodeThresholdDouble(extras, AtomicAllocator.getInstance().getPointer(buffer), compressedLength, (DoublePointer) AtomicAllocator.getInstance().getPointer(result));
    } else if (Nd4j.dataType() == DataBuffer.Type.HALF) {
        nativeOps.decodeThresholdHalf(extras, AtomicAllocator.getInstance().getPointer(buffer), compressedLength, (ShortPointer) AtomicAllocator.getInstance().getPointer(result));
    }

    AtomicAllocator.getInstance().getAllocationPoint(result).tickDeviceWrite();


    //DataBuffer result = Nd4j.getNDArrayFactory().convertDataEx(DataBuffer.TypeEx.THRESHOLD, buffer, getGlobalTypeEx());

    return target;
}