tensor
tensor copied to clipboard
FromScalar makes no sense with mask
From @chewxy on July 3, 2017 23:12
// FromScalar is a construction option for representing a scalar value as a Tensor
func FromScalar(x interface{}, argMask ...[]bool) ConsOpt {
var mask []bool
if len(argMask) > 0 {
mask = argMask[0]
}
f := func(t Tensor) {
switch tt := t.(type) {
case *Dense:
xt := reflect.TypeOf(x)
xv := reflect.New(xt)
xvi := reflect.Indirect(xv)
xvi.Set(reflect.ValueOf(x))
ptr := xv.Pointer()
uptr := unsafe.Pointer(ptr)
tt.ptr = uptr
tt.l = 1
tt.c = 1
tt.v = x
tt.t = Dtype{xt}
tt.mask = mask
tt.shape =
default:
panic("Unsupported Tensor Type")
}
}
return f
}
A scalar value should not be masked. Is there a reason why a scalar value is maskable? @kabaka0
There are various instances where retVal = New(FromScalar(argmaxI(t.Ints(), t.mask))) or something similar is called, but I cannot for rhyme or reason figure out why.
Copied from original issue: chewxy/gorgonia#132
From @kabaka0 on July 3, 2017 23:20
My reasoning was that there could be cases in which a scalar is masked, such as, say, a reduction operation from a masked array (say all elements invalid) that results in an invalid scalar. I opted as a result to include the option of creating a scalar with a mask, given that it is not forbidden. I believe that numpy also supports masked 'scalars' (https://github.com/numpy/numpy/issues/4332)
From @kabaka0 on July 3, 2017 23:26
Also in the case you quote, retVal = New(FromScalar(argmaxI(t.Ints(), t.mask))), the return value is a regular (unmasked) scalar, the mask is only used in argmask. In fact, I should have modified those lines to be something like retVal = New(FromScalar(argmaxI(t.Ints(), t.mask), t.maskedAll())
OK. Thanks. Very helpful. Can you craft a documentation for this? Thanks
From @kabaka0 on July 3, 2017 23:35
Sure, I will do!
On Jul 3, 2017 7:34 PM, "Chewxy" [email protected] wrote:
Assigned #132 https://github.com/chewxy/gorgonia/issues/132 to @kabaka0 https://github.com/kabaka0.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chewxy/gorgonia/issues/132#event-1148786789, or mute the thread https://github.com/notifications/unsubscribe-auth/AKCdJZZW5CUcJW2137B8dlmxgQ-Ga3XNks5sKXqegaJpZM4OMv1h .
(btw, just send a PR, I'll merge your documentation before #127