Hi everyone,
First of all, happy new year to all of you, I'm sure we all agree that 2020, despite its bad reputation, has been a great year for SIG JVM with all the amazing achievements we have completed so far, which I'm really thankful to you. Let's continue this great community work for 2021!
Second point is that we have just completed the merge of an important refactoring of the tensors in the TensorFlow Java client to leverage even further the standard Java type system, now available in 0.3.0-SNAPSHOT. In a nutshell, here are the main differences that might break backward compatibility with your current code if you are using version 0.2.0:
// Before
Operand<TInt32> c = tf.dtypes.cast(node, TInt32.DTYPE);
// After
Operand<TInt32> c = tf.dtypes.cast(node, TInt32.class);
// Before
Tensor<TInt32> t = TInt32.scalarOf(10);
assertEquals(10, t.data().getInt());
// After
TInt32 t = TInt32.scalarOf(10);
assertEquals(10, t.getInt());
// Before
Tensor<?> t = ...;
if (t.dataType().equals(TInt32.DTYPE)) {
int value = ((TInt32)t.data()).getInt();
}
// After
Tensor t = ...;
if (t instanceof TInt32) {
int value = ((TInt32)t).getInt();
}
// Before
DataType<? extends TType> dtype = tensor.dataType();
if (dtype.isNumeric()) {
...
}
// After
if (TNumber.class.isAssignableFrom(tensor.type())) {
...
}
I invite you to please give it a try and give us your feedback before we make a new release including those changes. Again the idea for such refactoring was to get rid of the custom typing system we had in version 0.2.0 to benefit from the one exposed by the JVM, which can significantly improve the integration of our API with the future versions of Java and other JVM languages. I'll update the examples soon to reflect these changes to make it easier for you to adapt your code.
Cheers!
Karl