Java Code Examples for org.nd4j.linalg.factory.Nd4j#writeComplex()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#writeComplex() . 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: BaseLoader.java    From nd4j with Apache License 2.0 6 votes vote down vote up
private void doSave(INDArray save, String id) throws SQLException, IOException {
    Connection c = dataSource.getConnection();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    if (save instanceof IComplexNDArray) {
        IComplexNDArray c2 = (IComplexNDArray) save;
        Nd4j.writeComplex(c2, dos);
    } else {
        BinarySerde.writeArrayToOutputStream(save,bos);
    }

    byte[] bytes = bos.toByteArray();

    PreparedStatement preparedStatement = c.prepareStatement(insertStatement());
    preparedStatement.setString(1, id);
    preparedStatement.setBytes(2, bytes);
    preparedStatement.executeUpdate();


}
 
Example 2
Source File: BaseLoader.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Convert an ndarray to a blob
 *
 * @param toConvert the complex ndarray to convert
 * @return the converted complex ndarray
 */
@Override
public Blob convert(IComplexNDArray toConvert) throws IOException, SQLException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);

    Nd4j.writeComplex(toConvert, dos);

    byte[] bytes = bos.toByteArray();
    Connection c = dataSource.getConnection();
    Blob b = c.createBlob();
    b.setBytes(1, bytes);
    return b;
}