-
Notifications
You must be signed in to change notification settings - Fork 214
TensorFlow type system refactoring #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I love the direction! I think you've created a package |
Oh, it looks like the whole generated source folder was missing, I've just pushed it back |
Perhaps it would be worthwhile to carefully write down the intended semantics in the javadocs for a few cornerstone classes like // in class Output<T>
public <U extends TType> Output<U> expect(Class<U> tensorType) {
if (tensorType != type()) {
throw new IllegalArgumentException(
"Cannot cast from output of " + type().getSimpleName() + " to output of type " + tensorType.getSimpleName());
}
return ((Output<U>) this);
} At compile time, would it be reasonable to have an Now suppose I have an We have a method whose implementation looks at it exactly that way, but whose javadoc does not: // in class TypeRegistry
/**
* Find a type registration from a type class
*
* @param typeClass class implementing {@link Tensor}
* @return type registration
* @throws IllegalArgumentException if the code matches no registered data type
*/
public static <T extends TType> Type<T> find(Class<T> typeClass) {
Type<?> entry = TYPES_BY_CLASS.get(typeClass);
if (entry == null) {
throw new IllegalArgumentException("Class \"" + typeClass.getName() + "\" is not a valid datatype class");
}
return (Type<T>)entry;
} The javadoc accurately describes Perhaps if we carefully write down the intended semantics in the javadocs for a few cornerstone classes like |
Hi @deansher , this PR is still a draft and the Javadoc is something I did not went through yet, as I wanted to collect more comments and have a common agreement that we want to move in that direction before completing it. So right now, please only look at it at a high-level. For example, I think what you mentioned about supporting |
Yeah, I'm just poking around for interesting corner cases to see if I can spot any reasons that using a Java class as the runtime representation of a tensor type is going to go badly. |
91da1d2
to
4740bd4
Compare
Is there anything left in this PR that hasn't landed in the others? As otherwise we should close this one. |
I think we are good to close it, yes |
This is another attempt to refactor and simplify the type system of TensorFlow Java, in reflection to what was previously discussed in the preview pull request #92 plus the ongoing discussion on #115 .
I think this new version supports most of the optimizations we were targeting and I plan to clean it up and, if possible, make smaller PR out of it for merging in our current snapshot, if everyone agrees with this approach. Breaking changes compared to the actual version (0.2.0) include:
org.tensorflow.types
tensor.data()
to convert a tensor handle to a data structure is no longer requiredDataType
has been removed and theDataType
proto, which is just an enum, is now used whenever neededTensorList
andTensorMap
that also supports tensor type auto-casting (in progress)Here are a few before&after examples:
CC\ @deansher , @Craigacp