-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
MaxBetween panics on a view and scalar #145
Comments
I think the following patch fixes the issue. Could you please check if I am not missing anything: diff --git a/defaultengine_minmax.go b/defaultengine_minmax.go
index 56ac432..a8383da 100644
--- a/defaultengine_minmax.go
+++ b/defaultengine_minmax.go
@@ -169,7 +169,7 @@ func (e StdEng) MinBetweenScalar(t Tensor, s interface{}, leftTensor bool, opts
}
// check to see if anything needs to be created
- if reuse == nil {
+ if safe && reuse == nil {
reuse = NewDense(a.Dtype(), a.Shape().Clone(), WithEngine(e))
dataReuse = reuse.hdr()
if useIter {
@@ -275,7 +275,7 @@ func (e StdEng) MaxBetweenScalar(t Tensor, s interface{}, leftTensor bool, opts
}
// check to see if anything needs to be created
- if reuse == nil {
+ if safe && reuse == nil {
reuse = NewDense(a.Dtype(), a.Shape().Clone(), WithEngine(e))
dataReuse = reuse.hdr()
if useIter { |
Explanation of the fix: // check to see if anything needs to be created
if reuse == nil {
reuse = NewDense(a.Dtype(), a.Shape().Clone(), WithEngine(e))
dataReuse = reuse.hdr()
if useIter {
iit = IteratorFromDense(reuse)
}
} Which is not true for the case when there is an unsafe option. If the unsafe option is given then we should output into the first Tensor. Otherwise the following switch fails to pick the first case: switch {
case !safe && reuse == nil:
err = e.E.MaxBetweenIter(typ, dataA, dataB, ait, bit)
retVal = a
case safe && reuse != nil && !leftTensor:
storage.CopyIter(typ, dataReuse, dataB, iit, bit)
bit.Reset()
iit.Reset()
err = e.E.MaxBetweenIter(typ, dataA, dataReuse, ait, bit)
retVal = reuse
case safe && reuse != nil && leftTensor:
storage.CopyIter(typ, dataReuse, dataA, iit, ait)
ait.Reset()
iit.Reset()
err = e.E.MaxBetweenIter(typ, dataReuse, dataB, iit, bit)
retVal = reuse
default: // safe && bool
panic("Unreachable")
} |
Here is a minimal demonstration code:
The text was updated successfully, but these errors were encountered: