-
Notifications
You must be signed in to change notification settings - Fork 72
/
dense_data.go
72 lines (62 loc) · 1.5 KB
/
dense_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2009 The GoMatrix Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package matrix
//returns a copy of the row (not a slice)
func (A *DenseMatrix) RowCopy(i int) []float64 {
row := make([]float64, A.cols)
for j := 0; j < A.cols; j++ {
row[j] = A.Get(i, j)
}
return row
}
//returns a copy of the column (not a slice)
func (A *DenseMatrix) ColCopy(j int) []float64 {
col := make([]float64, A.rows)
for i := 0; i < A.rows; i++ {
col[i] = A.Get(i, j)
}
return col
}
//returns a copy of the diagonal (not a slice)
func (A *DenseMatrix) DiagonalCopy() []float64 {
span := A.rows
if A.cols < span {
span = A.cols
}
diag := make([]float64, span)
for i := 0; i < span; i++ {
diag[i] = A.Get(i, i)
}
return diag
}
func (A *DenseMatrix) BufferRow(i int, buf []float64) {
for j := 0; j < A.cols; j++ {
buf[j] = A.Get(i, j)
}
}
func (A *DenseMatrix) BufferCol(j int, buf []float64) {
for i := 0; i < A.rows; i++ {
buf[i] = A.Get(i, j)
}
}
func (A *DenseMatrix) BufferDiagonal(buf []float64) {
for i := 0; i < A.rows && i < A.cols; i++ {
buf[i] = A.Get(i, i)
}
}
func (A *DenseMatrix) FillRow(i int, buf []float64) {
for j := 0; j < A.cols; j++ {
A.Set(i, j, buf[j])
}
}
func (A *DenseMatrix) FillCol(j int, buf []float64) {
for i := 0; i < A.rows; i++ {
A.Set(i, j, buf[i])
}
}
func (A *DenseMatrix) FillDiagonal(buf []float64) {
for i := 0; i < A.rows && i < A.cols; i++ {
A.Set(i, i, buf[i])
}
}