Skip to content
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

FromScalar makes no sense with mask #7

Open
chewxy opened this issue Sep 17, 2017 · 5 comments
Open

FromScalar makes no sense with mask #7

chewxy opened this issue Sep 17, 2017 · 5 comments
Assignees

Comments

@chewxy
Copy link
Member

chewxy commented Sep 17, 2017

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: gorgonia/gorgonia#132

@chewxy
Copy link
Member Author

chewxy commented Sep 17, 2017

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' (numpy/numpy#4332)

@chewxy
Copy link
Member Author

chewxy commented Sep 17, 2017

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())

@chewxy
Copy link
Member Author

chewxy commented Sep 17, 2017

OK. Thanks. Very helpful. Can you craft a documentation for this? Thanks

@chewxy
Copy link
Member Author

chewxy commented Sep 17, 2017

From @kabaka0 on July 3, 2017 23:35

Sure, I will do!

On Jul 3, 2017 7:34 PM, "Chewxy" notifications@github.com wrote:

Assigned #132 gorgonia/gorgonia#132 to @kabaka0
https://github.com/kabaka0.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
gorgonia/gorgonia#132 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AKCdJZZW5CUcJW2137B8dlmxgQ-Ga3XNks5sKXqegaJpZM4OMv1h
.

@chewxy
Copy link
Member Author

chewxy commented Sep 17, 2017

(btw, just send a PR, I'll merge your documentation before #127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants