gonum / matrix

Matrix packages for the Go language [DEPRECATED]
446 stars 51 forks source link

Support for n-dimensional matrices #400

Closed j6k4m8 closed 7 years ago

j6k4m8 commented 7 years ago

Hi all — want to start this off by saying that this is a very impressive codebase...and caveating the following with the fact that I'm both new(ish) to Go and very new to gonum/matrix, so I apologize if this has been addressed previously.

I'm curious if there was a conscious design-decision to only support 2D matrices, and if there has been any work toward n-dimensional matrices. It looks like this package was quite intentionally designed around a 2D structure, and I'm curious if this is because few gophers are working in higher-dimensional data, or if there is a clever workaround I'm not understanding.

kortschak commented 7 years ago

We have had various private discussions about the addition of a tensor package; it is something that I would like to see for some work I want to do, though its priority is low.

Having said that, the design discussion that will be needed before we could start this is not trivial; efficient tensor calculation is complicated - the underlying representation of tensors maximising efficiency is highly dependent on the work that is being done, and the API for an n-dimensional layout is more complicated than that for 2-D (it may be more obvious after an n-dimensional slice proposal/change has been added to the language).

If you would like to start discussion on this (particularly if you have domain knowledge that would bring experience to the discussion), please start a thread at gonum-dev.

j6k4m8 commented 7 years ago

Very interesting — glad to hear there was a lot of thought behind this decision, and I'm looking forward to seeing (and hopefully being part of) where the package heads next. I'm closing this issue for now, and I'll do some more research on implementation before heading over to gonum-dev.

Thanks!

btracey commented 7 years ago

One issue to consider is supporting an particular sized structure for n >2, or a single structure that can support for any n. They are both useful, but it's generally more efficient to have a specially designed structure if the dimension is known ahead of time. gonum/matrix is that for the n = 2 case.

kortschak commented 7 years ago

There is worthwhile discussion in this document (C++ template library implementation of tensors) and the associated PDF dealing with efficiency.

The problem of API design is possibly more complicated, particularly since it needs to fit in with the general design principles that already exist in gonum/matrix. Although it is reasonable to treat these two problems as orthogonal, with the implementation having some opinions about what to do in various cases. The glue between the API and those choices though is what is really complicated.

j6k4m8 commented 7 years ago

I may have closed this prematurely — would love to be part of this discussion if we're planning on re-opening..?