Weird syntax to sum matrix

49 views
Skip to first unread message

michel perez

unread,
Nov 9, 2016, 10:17:31 PM11/9/16
to gonum-dev
This syntax https://godoc.org/github.com/gonum/matrix/mat64#Dense.Add is so weird why there is not just a function that sums a and b and returns a new  matrix instead?

Brendan Tracey

unread,
Nov 9, 2016, 10:32:27 PM11/9/16
to gonum-dev
The main reason is that an Add method has to exist. There are many reasons to store the result into an existing matrix, for example reducing memory allocations, or reducing the number of variable names, as in a.Add(a,b). The question is if an Add function is worth it on top of the add method. I don't think

var c mat64.Dense
c.Add(a,b)

is all that much more trouble than

c := mat64.Add(a,b)

Simplicity argues against providing both, especially since for consistency essentially every method would have to be duplicated.

Dan Kortschak

unread,
Nov 9, 2016, 10:40:00 PM11/9/16
to michel perez, gonum-dev

It makes allocation pressure reduction easier.

--
afk
Dan


From: gonu...@googlegroups.com <gonu...@googlegroups.com> on behalf of michel perez <michel....@gmail.com>
Sent: Thursday, November 10, 2016 1:47:31 PM
To: gonum-dev
Subject: [gonum-dev] Weird syntax to sum matrix
 
This syntax https://godoc.org/github.com/gonum/matrix/mat64#Dense.Add is so weird why there is not just a function that sums a and b and returns a new  matrix instead?

--
You received this message because you are subscribed to the Google Groups "gonum-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gonum-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages