-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix passing a float for appropriate MXNet operations #22
base: v0.x.x
Are you sure you want to change the base?
Fix passing a float for appropriate MXNet operations #22
Conversation
When assigning each element of an n-dimensional array from a scalar, the scalar should be of type float according to the MXNet documentation for the operator `_set_value`. Also the operations with a scalar right-hand side like `_plus_scalar`, `_minus_scalar`, `_mul_scalar`, `_div_scalar`, etc. require the scalar to be of type float. This change replaces the general type `T` with `float` for these cases.
I need to fix the |
Probably I'll split it into two commits. |
This change needs a bit more explanation and justification, I think. |
Specifically:
|
Blocking while these design questions remain unanswered. |
The former.
I assume they are converted. The documentation doesn't say anything specific here.
We should look into enabling non- |
Probably best not to assume anything. Going by experience it seems more likely that this is simply wrong and is not a use-case they support in practice. As a starting point, can you check what happens when |
You cannot have |
Apparently, the passed value is converted to the element type. |
On closer inspection it turns out that you cannot call |
That's in line with what I was suspecting, i.e. that whole parts of the NDArray functionality just do not exist for certain element types. Now, that said, I'm not sure that it's our responsibility to sugarcoat the MXNet API by hardcoding in our D wrapper constraints from the upstream implementation (which we should distinguish from the upstream API). Anyone attempting to perform these operations with the wrong element type will get a runtime error from the C API (which we convert to an exception), right? |
Let me rephrase what the problem is. Whenever we allow passing a scope array = new NDArray!(int)(cpuContext(), [1u]);
array = int.max; looks unsuspicious to the user. Because the signature of What is true that we don't want to have these cases scope array = new NDArray!(int)(cpuContext(), [1u]);
array = 1.5f; // sets the element to 1 scope array = new NDArray!(ubyte)(cpuContext(), [1u]);
array = 256f; // sets the element to 0 as well. |
All fair enough. So I'm a bit confused why you think the appropriate solution is to rewrite the methods to accept |
(That's assuming that we can't alternatively fix things by updating |
So we decided to leave this alone for now. Fundamentally the issue is about MXNet only accepting |
Yup, we can distinguish here between our own internal issues ( |
When assigning each element of an n-dimensional array from a scalar, the
scalar should be of type float according to the MXNet documentation for
the operator
_set_value
. Also the operations with a scalar right-handside like
_plus_scalar
,_minus_scalar
,_mul_scalar
,_div_scalar
,etc. require the scalar to be of type float. This change replaces the
general type
T
withfloat
for these cases.