-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtri.go
88 lines (79 loc) · 2.37 KB
/
tri.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Harri Rautila, 2013
// This file is part of github.com/hrautila/matops package. It is free software,
// distributed under the terms of GNU Lesser General Public License Version 3, or
// any later version. See the COPYING tile included in this archive.
package matops
import (
"github.com/hrautila/matrix"
)
// Make A tridiagonal, upper, non-unit matrix by clearing the strictly lower part
// of the matrix.
func TriU(A *matrix.FloatMatrix) *matrix.FloatMatrix {
var Ac matrix.FloatMatrix
var k int
mlen := imin(A.Rows(), A.Cols())
for k = 0; k < mlen; k++ {
Ac.SubMatrixOf(A, k+1, k, A.Rows()-k-1, 1)
Ac.SetIndexes(0.0)
}
if A.Cols() < A.Rows() {
Ac.SubMatrixOf(A, A.Cols(), 0)
Ac.SetIndexes(0.0)
}
return A
}
// Make A tridiagonal, upper, unit matrix by clearing the strictly lower part
// of the matrix and setting diagonal elements to one.
func TriUU(A *matrix.FloatMatrix) *matrix.FloatMatrix {
var Ac matrix.FloatMatrix
var k int
mlen := imin(A.Rows(), A.Cols())
for k = 0; k < mlen; k++ {
Ac.SubMatrixOf(A, k+1, k, A.Rows()-k-1, 1)
Ac.SetIndexes(0.0)
A.SetAt(k, k, 1.0)
}
// last element on diagonal
A.SetAt(k, k, 1.0)
if A.Cols() < A.Rows() {
Ac.SubMatrixOf(A, A.Cols(), 0)
Ac.SetIndexes(0.0)
}
return A
}
// Make A tridiagonal, lower, unit matrix by clearing the strictly upper part
// of the matrix and setting diagonal elements to one.
func TriLU(A *matrix.FloatMatrix) *matrix.FloatMatrix {
var Ac matrix.FloatMatrix
mlen := imin(A.Rows(), A.Cols())
A.SetAt(0, 0, 1.0)
for k := 1; k < mlen; k++ {
A.SetAt(k, k, 1.0)
Ac.SubMatrixOf(A, 0, k, k, 1)
Ac.SetIndexes(0.0)
}
if A.Cols() > A.Rows() {
Ac.SubMatrixOf(A, 0, A.Rows())
Ac.SetIndexes(0.0)
}
return A
}
// Make A tridiagonal, lower, non-unit matrix by clearing the strictly upper part
// of the matrix.
func TriL(A *matrix.FloatMatrix) *matrix.FloatMatrix {
var Ac matrix.FloatMatrix
mlen := imin(A.Rows(), A.Cols())
for k := 1; k < mlen; k++ {
Ac.SubMatrixOf(A, 0, k, k, 1)
Ac.SetIndexes(0.0)
}
if A.Cols() > A.Rows() {
Ac.SubMatrixOf(A, 0, A.Rows())
Ac.SetIndexes(0.0)
}
return A
}
// Local Variables:
// tab-width: 4
// indent-tabs-mode: nil
// End: