JNI fixes from PR review
This commit is contained in:
parent
95e2134c01
commit
4a41a19378
@ -16,9 +16,10 @@ limitations under the License.
|
||||
package org.tensorflow;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* An {@link OperationBuilder} for building {@link Operation}s that are executed eagerly.
|
||||
* An {@link OperationBuilder} for building {@link Operation Operations} that are executed eagerly.
|
||||
*/
|
||||
final class EagerOperationBuilder implements OperationBuilder {
|
||||
|
||||
@ -64,12 +65,12 @@ final class EagerOperationBuilder implements OperationBuilder {
|
||||
|
||||
@Override
|
||||
public OperationBuilder setAttr(String name, String value) {
|
||||
return setAttr(name, value.getBytes(Charset.forName("UTF-8")));
|
||||
return setAttr(name, value.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationBuilder setAttr(String name, String[] values) {
|
||||
Charset utf8 = Charset.forName("UTF-8");
|
||||
Charset utf8 = StandardCharsets.UTF_8;
|
||||
Object[] objects = new Object[values.length];
|
||||
for (int i = 0; i < values.length; ++i) {
|
||||
objects[i] = values[i].getBytes(utf8);
|
||||
|
@ -116,6 +116,8 @@ JNIEXPORT void JNICALL Java_org_tensorflow_EagerOperationBuilder_setDevice(
|
||||
const char* cname = env->GetStringUTFChars(device_name, nullptr);
|
||||
TF_Status* status = TF_NewStatus();
|
||||
TFE_OpSetDevice(op, cname, status);
|
||||
throwExceptionIfNotOK(env, status);
|
||||
TF_DeleteStatus(status);
|
||||
env->ReleaseStringUTFChars(device_name, cname);
|
||||
}
|
||||
|
||||
@ -140,6 +142,10 @@ JNIEXPORT void JNICALL Java_org_tensorflow_EagerOperationBuilder_addInputList(
|
||||
TFE_TensorHandle* tensor_handles[num_inputs];
|
||||
for (int i = 0; i < num_inputs; ++i) {
|
||||
tensor_handles[i] = requireTensorHandle(env, cinput_handles[i]);
|
||||
if (tensor_handles[i] == nullptr) {
|
||||
env->ReleaseLongArrayElements(input_handles, cinput_handles, JNI_ABORT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
env->ReleaseLongArrayElements(input_handles, cinput_handles, JNI_ABORT);
|
||||
TF_Status* status = TF_NewStatus();
|
||||
@ -277,6 +283,7 @@ JNIEXPORT void JNICALL Java_org_tensorflow_EagerOperationBuilder_setAttrShape(
|
||||
TFE_OpSetAttrShape(op, cname, cvalue.get(), static_cast<int>(num_dims),
|
||||
status);
|
||||
throwExceptionIfNotOK(env, status);
|
||||
TF_DeleteStatus(status);
|
||||
env->ReleaseStringUTFChars(attr_name, cname);
|
||||
}
|
||||
|
||||
@ -315,5 +322,7 @@ Java_org_tensorflow_EagerOperationBuilder_setAttrShapeList(
|
||||
TF_Status* status = TF_NewStatus();
|
||||
TFE_OpSetAttrShapeList(op, cname, cdims.get(), cnum_dims.get(),
|
||||
num_dims_length, status);
|
||||
throwExceptionIfNotOK(env, status);
|
||||
TF_DeleteStatus(status);
|
||||
env->ReleaseStringUTFChars(attr_name, cname);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user