TriBandDense examples

22 views
Skip to first unread message

Aron Sogor

unread,
Jun 16, 2022, 8:51:47 PM6/16/22
to gonum-dev
Hi,

I have questions about the use of TriBandDense:
model := mat.NewTriBandDense(10, 5, mat.Upper, []float64{
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,

10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0,
10.0, 9.0, 8.0, 7.0, 6.0, 5.0})

Resulting in:

a = ⎡10   9   8   7   6   5   0   0   0   0⎤
    ⎢ 0  10   9   8   7   6   5   0   0   0⎥
    ⎢ 0   0  10   9   8   7   6   5   0   0⎥
    ⎢ 0   0   0  10   9   8   7   6   5   0⎥
    ⎢ 0   0   0   0  10   9   8   7   6   5⎥
    ⎢ 0   0   0   0   0  10   9   8   7   6⎥
    ⎢ 0   0   0   0   0   0  10   9   8   7⎥
    ⎢ 0   0   0   0   0   0   0  10   9   8⎥
    ⎢ 0   0   0   0   0   0   0   0  10   9⎥
    ⎣ 0   0   0   0   0   0   0   0   0  10⎦

with only non-zero values:
a = ⎡10   9   8   7   6   5   .   .   .   .⎤
    ⎢ .  10   9   8   7   6   5   .   .   .⎥
    ⎢ .   .  10   9   8   7   6   5   .   .⎥
    ⎢ .   .   .  10   9   8   7   6   5   .⎥
    ⎢ .   .   .   .  10   9   8   7   6   5⎥
    ⎢ .   .   .   .   .  10   9   8   7   6⎥
    ⎢ .   .   .   .   .   .  10   9   8   7⎥
    ⎢ .   .   .   .   .   .   .  10   9   8⎥
    ⎢ .   .   .   .   .   .   .   .  10   9⎥
    ⎣ .   .   .   .   .   .   .   .   .  10⎦


Do you have any pointers or examples on how I can get the Sum() of each row and column?

If there are any better places to learn, please point me there.

Aron

Dan Kortschak

unread,
Jun 16, 2022, 11:55:07 PM6/16/22
to gonu...@googlegroups.com
I was going to suggest using DoRowNonZero and DoColNonZero, but we have
not put them on that type. In their absence, you can do something that
is less efficient like `floats.Sum(mat.Row(nil, r, model))` to get the
sum of row `r` of `model`. (This will allocate a slice for each call;
this can be amortised by preallocating the destination and reusing it.

Please file an issue to add the methods I mentioned above.

https://go.dev/play/p/o7f8I0xZbzW

Dan

Vladimír Chalupecký

unread,
Jul 18, 2022, 3:48:03 AM7/18/22
to gonum-dev
Dan, I have checked now (sorry for the delay) and I see that TriBandDense does have DoRowNonZero and DoColNonZero. Are we looking at the same type?

Dan Kortschak

unread,
Jul 18, 2022, 4:08:34 AM7/18/22
to gonu...@googlegroups.com
On Mon, 2022-07-18 at 00:48 -0700, Vladimír Chalupecký wrote:
> Dan, I have checked now (sorry for the delay) and I see that
> TriBandDense does have DoRowNonZero and DoColNonZero. Are we looking
> at the same type?

Yes, we are. I didn't wait for the issue and added them in
https://github.com/gonum/gonum/pull/1810.

Dan

Vladimír Chalupecký

unread,
Jul 18, 2022, 4:27:51 AM7/18/22
to gonum-dev
Omg, I completely missed that PR (facepalm) :-)
Reply all
Reply to author
Forward
0 new messages