Re: [go-nuts] how to write methods for a generic Matrix[float64 constrained by Addable]?

2023-09-09 Thread 'Jakob Borg' via golang-nuts
Two minor issues; you can’t declare func (m *Matrix[float64]) NanToZero() because we don’t have specialisation, it needs to be func (m *Matrix[T]) NanToZero(), and you can’t have complex as one of the possible types because it’s impossible to convert a complex to a float.

[go-nuts] Generic function for types with common method name but different return type

2023-09-09 Thread Oleh Lomaka
Hello everybody, Gophers' superpower is required and highly appreciated. I have two types, A and B, each of which has a method named "M". This method accepts a string and returns an instance of the type it is declared on. ```go type A struct {} func (a A) M (string) A { return a } type B

Re: [go-nuts] how to write methods for a generic Matrix[float64 constrained by Addable]?

2023-09-09 Thread Jason E. Aten
I made a playground if anyone wants to play with it and figure out how to test their ideas. https://go.dev/play/p/h1nqHJAdVG8 On Sunday, September 10, 2023 at 12:24:54 AM UTC+1 Jason E. Aten wrote: > Like how, specifically? > > func (m *Matrix[float64]) NanToZero() { > for i := 0; i <

Re: [go-nuts] how to write methods for a generic Matrix[float64 constrained by Addable]?

2023-09-09 Thread Jason E. Aten
Like how, specifically? func (m *Matrix[float64]) NanToZero() { for i := 0; i < m.Nrow; i++ { for j := 0; j < m.Ncol; j++ { v := m.At(i, j).(float64) if math.IsNaN(v) { m.Set(i, j, 0) } } } } gives ./slurp1.go:944:9:

Re: [go-nuts] how to write methods for a generic Matrix[float64 constrained by Addable]?

2023-09-09 Thread 'Dan Kortschak' via golang-nuts
On Sat, 2023-09-09 at 15:39 -0700, Jason E. Aten wrote: > New to generics... how can I write a method for a Matrix[float64] > that uses a math function that expects a float64?   I get: > > ./slurp1.go:936:18: cannot use m.At(i, j) (value of type float64 > constrained by Addable) as float64 value

[go-nuts] how to write methods for a generic Matrix[float64 constrained by Addable]?

2023-09-09 Thread Jason E. Aten
New to generics... how can I write a method for a Matrix[float64] that uses a math function that expects a float64? I get: ./slurp1.go:936:18: cannot use m.At(i, j) (value of type float64 constrained by Addable) as float64 value in argument to math.IsNaN Casting it to float64() does not

Re: [go-nuts] x/mobile: avoid to catch sigabort signal

2023-09-09 Thread TheDiveO
You seem to be barking up the wrong tree, at least for the moment. Maybe your team may want to learn more about cgo and by sheer coincidence there's a blog post https://shane.ai/posts/cgo-performance-in-go1.21/ that might serve as a starting point, with one or two pointers to go further. I