-
Notifications
You must be signed in to change notification settings - Fork 42
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
API and method return types unification by making Numo a tensor library [ex: Arithmetic overflow] #91
Comments
This issue is open for discussion. |
I would not suggest to add overflow checks. I agree on the purpose of speed. But if Here is my proposition: two separate methods.
Note that both implementations can still take an optional argument (e.g. |
With require 'numo/narray'
ary = Numo::UInt8[255, 1]
# => Numo::UInt8#shape=[2]
# [255, 1]
tot = ary.sum(keepdims:true)
# => Numo::UInt8#shape=[1]
# [0] I feel returned type and overflow check are separate issues. |
I would not check for overflow. What I wish: require 'numo/narray'
ary = Numo::UInt8[255, 1] # => Numo::UInt8#shape=[2] [255, 1]
ary.sum # => 256 (Integer)
ary.sum(keepdims:true) # => Numo::UInt8#shape=[1] [0] Discovering that |
IMO, every NArray method is "typed". If not so, the design of NArray is too complicated. Numo::RObject[255, 1].sum
# => 256 |
If it is "typed" it should return a This way I would know there is overflow, and I can do the cast to On methods typing Before taking a stand on whether "all methods should be typed", please consider whether you want the user to constantly think "I have a Instead, my "image":
Why is With my utmost respect, Tanaka-san, I have three questions for you:
Suggestion: regardless of the specialized
I believe this design would lead not to more complexity, but to a much simpler code, since many methods can share implementation and provide a consistent interface across data types. While one can always debate about pure-design choices, I believe these changes would make |
Thank you for raising issues that should be considered. I have not expected this behavior (i.e. bug): Numo::UInt8[1,2,4,5].median
# => Numo::UInt8#shape=[]
# 3 This is a zero-dimensional array to express a scalar and is not intended to be exposed to user. In current design, this should be converted to an Integer. If I still feel this issue is not related with overflow problem. Even if |
Thank you for taking this issue under consideration. I sincerely care for Numo, I hope my enthusiasm correctly transpires as my fullest and most serious support. I think using zero-dimensional arrays to express scalars is an elegant solution from a mathematical standpoint: it would make
With TensorFlow still growing in popularity, I believe adding Jokes aside, in my opinion it would fit well with the methods returning typed results, delegating the final casting to the user is explicit and nice. I understand it is a bug under the current design, but without knowing the underlying design, from a purely user perspective, I felt Now that you shared the whole design decision, I agree the (github-)issue has a larger scope than an overflow problem; the title is not relevant anymore. What would you suggest is a better one? Meanwhile I will change it to something closer to the heart of my suggestion. As per the number of implementations: my suggestion would be to
What do you think? |
[EDIT]: What I initially thought being an arithmetic overflow problem revealed itself to be a precise design choice (plus missing features/bugs) which led to the following discussion.
Using specialized data types leads to unexpected arithmetic overflow.
Which I would understand, expect and work with if (upon checking) I found
#sum
to return a type subject to such overflow, say aNumo::UInt8
(withshape=[1]
for example). But instead:I would suggest the behavior could be found more consistent if either
#sum
would return aNumo::UInt8
with overflow or anInteger
without.The text was updated successfully, but these errors were encountered: