Java Code Examples for org.bytedeco.javacpp.DoublePointer#capacity()

The following examples show how to use org.bytedeco.javacpp.DoublePointer#capacity() . 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: GymEnv.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Override
public OBSERVATION reset() {
    int gstate = PyGILState_Ensure();
    try {
        Py_DecRef(PyRun_StringFlags("state = env.reset()", Py_single_input, globals, locals, null));
        checkPythonError();

        PyArrayObject state = new PyArrayObject(PyDict_GetItemString(locals, "state"));
        DoublePointer stateData = new DoublePointer(PyArray_BYTES(state)).capacity(PyArray_Size(state));
        SizeTPointer stateDims = PyArray_DIMS(state).capacity(PyArray_NDIM(state));
        checkPythonError();

        done = false;

        double[] data = new double[(int)stateData.capacity()];
        stateData.get(data);
        return (OBSERVATION) new Box(data);
    } finally {
        PyGILState_Release(gstate);
    }
}
 
Example 2
Source File: DefaultDataBufferFactory.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * @param doublePointer
 * @param length
 * @return
 */
@Override
public DataBuffer create(DoublePointer doublePointer, long length) {
    doublePointer.capacity(length);
    doublePointer.limit(length);
    doublePointer.position(0);
    return new DoubleBuffer(doublePointer, DoubleIndexer.create(doublePointer), length);
}
 
Example 3
Source File: GymEnv.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public StepReply<OBSERVATION> step(A action) {
    int gstate = PyGILState_Ensure();
    try {
        if (render) {
            Py_DecRef(PyRun_StringFlags("env.render()", Py_single_input, globals, locals, null));
            checkPythonError();
        }
        Py_DecRef(PyRun_StringFlags("state, reward, done, info = env.step(" + (Integer)action +")", Py_single_input, globals, locals, null));
        checkPythonError();

        PyArrayObject state = new PyArrayObject(PyDict_GetItemString(locals, "state"));
        DoublePointer stateData = new DoublePointer(PyArray_BYTES(state)).capacity(PyArray_Size(state));
        SizeTPointer stateDims = PyArray_DIMS(state).capacity(PyArray_NDIM(state));

        double reward = PyFloat_AsDouble(PyDict_GetItemString(locals, "reward"));
        done = PyLong_AsLong(PyDict_GetItemString(locals, "done")) != 0;
        checkPythonError();

        double[] data = new double[(int)stateData.capacity()];
        stateData.get(data);

        return new StepReply(new Box(data), reward, done, null);
    } finally {
        PyGILState_Release(gstate);
    }
}
 
Example 4
Source File: DefaultDataBufferFactory.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * @param doublePointer
 * @param length
 * @return
 */
@Override
public DataBuffer create(DoublePointer doublePointer, long length) {
    doublePointer.capacity(length);
    doublePointer.limit(length);
    doublePointer.position(0);
    return new DoubleBuffer(doublePointer, DoubleIndexer.create(doublePointer), length);
}