Gonum for types other than float64

319 views
Skip to first unread message

Jacob Hansson

unread,
Nov 24, 2016, 2:51:02 PM11/24/16
to gonum-dev
Hi!

I was super happy to find an actively maintained set of packages for linear algebra in Go, and I'm hoping to use gonum for a machine vision application. As such, a lot of the matrix operations I'm interested in deal with 8-bit grayscale images (eg. matrixes of `byte`). 

I was wondering if there are plans to expand the gonum packages to support other types outside of float64? 

I created a small POC that rewrites a tiny bit of the matrix.go library, to support any go number type, to explore the code generation route of doing this: https://github.com/jakewins/gonum-gen

Have you guys considered something in this direction?

Dan Kortschak

unread,
Nov 24, 2016, 3:58:58 PM11/24/16
to Jacob Hansson, gonum-dev
I'm not entirely sure what you want to get from doing this; the core
API (essentially what you have used in the code generation) is only a
very minor component of the gonum/matrix packages and is backed by
substantial amounts of code in the gonum/blas and gonum/lapack repos.
These contain specifically float-handling routines.

If you are using gonum for vision processing that's great, but I don't
think you need to do what you are suggesting here. What you would want
to do is grab the greyscale data, convert to floats (float64 will work
out of the box, float32 would require code generation of the entirety
of mat64), and then do your work in float space. If you then need to
output greyscale again, convert the float representations to 8 bit
values.

I hope this helps
Dan

Jake

unread,
Nov 24, 2016, 4:41:03 PM11/24/16
to Dan Kortschak, gonum-dev
Oh, right - I should have been more clear: I mean to do this for the entire mat64 library (as well as the upstream gonum dependencies it has), at least whatever portions of it are applicable to integer math; doing it for the core API was just a small experiment.

You're absolutely right I could convert my bytes to float space - though I was hoping to avoid it if I could. The use case is near-real time and cache-bound, so the value of fitting 8x more pixels per cache line is high.

I suppose I was curious if there are plans to expand gonum to support eg. float32 and the integer types, to make sure I'm not spending a bunch of time on a solved problem.

I'll keep poking around in that git repo, and we'll see how it goes :)

Cheers,
jake

Dan Kortschak

unread,
Nov 24, 2016, 7:03:28 PM11/24/16
to Jake, gonum-dev
OK. We do generate the float32 blas from the float64 blas code. In
principle you can do this for any numerical type (with care). In
practice the tests may (will) behave differently - for this reason we
don't test the float32 code. I imagine that we will do the same for the
lapack code in the longer term, though that would not work for integral
types.

We do have partial support for float32 matrices (blas only). Input into
broadening that by someone who cares would be appreciated (this might
also include test massaging). Integers, I can't see a role for in gonum
matrices.

To achieve what you want you would need to differentiate the parts that
depend on lapack and those that don't and only generate for those that
don't.

I think you would be better off either writing your own domain-specific
routines and interfacing the values from them to gonum/matrix if you
need the functions we provide. What do you anticipate you would
actually need, both in the 8 bit space and in the deeper linear algebra
space?

Dan

On Thu, 2016-11-24 at 21:40 +0000, Jake wrote:
> Oh, right - I should have been more clear: I mean to do this for the
> entire
> mat64 library (as well as the upstream gonum dependencies it has), at
> least
> whatever portions of it are applicable to integer math; doing it for
> the
> core API was just a small experiment.
>
> You're absolutely right I could convert my bytes to float space -
> though I
> was hoping to avoid it if I could. The use case is near-real time and
> cache-bound, so the value of fitting 8x more pixels per cache line is
> high.
>
> I suppose I was curious if there are plans to expand gonum to support
> eg.
> float32 and the integer types, to make sure I'm not spending a bunch
> of
> time on a solved problem.
>
> I'll keep poking around in that git repo, and we'll see how it goes
> :)
>
> Cheers,
> jake
>
> On Thu, Nov 24, 2016 at 2:58 PM Dan Kortschak <dan.kortschak@adelaide
--
Omnes mundum facimus.

Dan Kortschak <dan.ko...@adelaide.edu.au>
F9B3 3810 C4DD E214 347C B8DA D879 B7A7 EECC 5A40
10C7 EEF4 A467 89C9 CA00 70DF C18F 3421 A744 607C


Reply all
Reply to author
Forward
0 new messages