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

The following examples show how to use org.nd4j.linalg.api.ndarray.INDArray#setData() . 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: JCublasNDArrayFactory.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts Single/Double precision databuffer to Half-precision databuffer
 *
 * @param typeSrc
 * @param source
 * @param typeDst @return
 */
@Override
public INDArray convertDataEx(DataBuffer.TypeEx typeSrc, INDArray source, DataBuffer.TypeEx typeDst) {
    if (source.isView())
        throw new UnsupportedOperationException("Impossible to compress View. Consider using dup() before. ");

    DataBuffer buffer = convertDataEx(typeSrc, source.data(), typeDst);
    source.setData(buffer);

    if (buffer instanceof CompressedDataBuffer)
        source.markAsCompressed(true);
    else
        source.markAsCompressed(false);

    return source;
}
 
Example 2
Source File: CpuNDArrayFactory.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts Single/Double precision databuffer to Half-precision databuffer
 *
 * @param typeSrc
 * @param source
 * @param typeDst @return
 */
@Override
public INDArray convertDataEx(DataBuffer.TypeEx typeSrc, INDArray source, DataBuffer.TypeEx typeDst) {
    if (source.isView())
        throw new UnsupportedOperationException("Impossible to compress View. Consider using dup() before. ");

    DataBuffer buffer = convertDataEx(typeSrc, source.data(), typeDst);
    source.setData(buffer);

    if (buffer instanceof CompressedDataBuffer)
        source.markAsCompressed(true);
    else
        source.markAsCompressed(false);

    return source;
}
 
Example 3
Source File: JCublasNDArrayFactory.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts Single/Double precision databuffer to Half-precision databuffer
 *
 * @param typeSrc
 * @param source
 * @param typeDst @return
 */
@Override
public INDArray convertDataEx(DataTypeEx typeSrc, INDArray source, DataTypeEx typeDst) {
    if (source.isView())
        throw new UnsupportedOperationException("Impossible to compress View. Consider using dup() before. ");

    DataBuffer buffer = convertDataEx(typeSrc, source.data(), typeDst);
    source.setData(buffer);

    if (buffer instanceof CompressedDataBuffer)
        source.markAsCompressed(true);
    else
        source.markAsCompressed(false);

    return source;
}
 
Example 4
Source File: CpuNDArrayFactory.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * This method converts Single/Double precision databuffer to Half-precision databuffer
 *
 * @param typeSrc
 * @param source
 * @param typeDst @return
 */
@Override
public INDArray convertDataEx(DataTypeEx typeSrc, INDArray source, DataTypeEx typeDst) {
    if (source.isView())
        throw new UnsupportedOperationException("Impossible to compress View. Consider using dup() before. ");

    DataBuffer buffer = convertDataEx(typeSrc, source.data(), typeDst);
    if (nativeOps.lastErrorCode() != 0)
        throw new RuntimeException(nativeOps.lastErrorMessage());

    source.setData(buffer);

    if (buffer instanceof CompressedDataBuffer)
        source.markAsCompressed(true);
    else
        source.markAsCompressed(false);

    return source;
}
 
Example 5
Source File: AbstractCompressor.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: AbstractCompressor.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Inplace compression of INDArray
 *
 * @param array
 */
@Override
public void compressi(INDArray array) {
    // TODO: lift this restriction
    if (array.isView())
        throw new UnsupportedOperationException("Impossible to apply inplace compression on View");

    array.setData(compress(array.data()));
    array.markAsCompressed(true);
}
 
Example 7
Source File: AbstractCompressor.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public void decompressi(INDArray array) {
    if (!array.isCompressed())
        return;

    array.markAsCompressed(false);
    array.setData(decompress(array.data()));
}
 
Example 8
Source File: TensorflowConversionTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testNullArray() {
    INDArray array = Nd4j.create(2,2);
    array.setData(null);
    TensorflowConversion conversion =TensorflowConversion.getInstance();
    TF_Tensor tf_tensor = conversion.tensorFromNDArray(array);
    fail();
}
 
Example 9
Source File: AbstractCompressor.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: AbstractCompressor.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Inplace compression of INDArray
 *
 * @param array
 */
@Override
public void compressi(INDArray array) {
    // TODO: lift this restriction
    if (array.isView())
        throw new UnsupportedOperationException("Impossible to apply inplace compression on View");

    array.setData(compress(array.data()));
    array.markAsCompressed(true);
}
 
Example 11
Source File: AbstractCompressor.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void decompressi(INDArray array) {
    if (!array.isCompressed())
        return;

    array.markAsCompressed(false);
    array.setData(decompress(array.data(), ((CompressedDataBuffer)array.data()).getCompressionDescriptor().getOriginalDataType()));
}