OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / mat / index_no_bound_checks.go
1 // Copyright ©2014 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // This file must be kept in sync with index_bound_checks.go.
6
7 //+build !bounds
8
9 package mat
10
11 // At returns the element at row i, column j.
12 func (m *Dense) At(i, j int) float64 {
13         if uint(i) >= uint(m.mat.Rows) {
14                 panic(ErrRowAccess)
15         }
16         if uint(j) >= uint(m.mat.Cols) {
17                 panic(ErrColAccess)
18         }
19         return m.at(i, j)
20 }
21
22 func (m *Dense) at(i, j int) float64 {
23         return m.mat.Data[i*m.mat.Stride+j]
24 }
25
26 // Set sets the element at row i, column j to the value v.
27 func (m *Dense) Set(i, j int, v float64) {
28         if uint(i) >= uint(m.mat.Rows) {
29                 panic(ErrRowAccess)
30         }
31         if uint(j) >= uint(m.mat.Cols) {
32                 panic(ErrColAccess)
33         }
34         m.set(i, j, v)
35 }
36
37 func (m *Dense) set(i, j int, v float64) {
38         m.mat.Data[i*m.mat.Stride+j] = v
39 }
40
41 // At returns the element at row i.
42 // It panics if i is out of bounds or if j is not zero.
43 func (v *VecDense) At(i, j int) float64 {
44         if uint(i) >= uint(v.n) {
45                 panic(ErrRowAccess)
46         }
47         if j != 0 {
48                 panic(ErrColAccess)
49         }
50         return v.at(i)
51 }
52
53 // AtVec returns the element at row i.
54 // It panics if i is out of bounds.
55 func (v *VecDense) AtVec(i int) float64 {
56         if uint(i) >= uint(v.n) {
57                 panic(ErrRowAccess)
58         }
59         return v.at(i)
60 }
61
62 func (v *VecDense) at(i int) float64 {
63         return v.mat.Data[i*v.mat.Inc]
64 }
65
66 // SetVec sets the element at row i to the value val.
67 // It panics if i is out of bounds.
68 func (v *VecDense) SetVec(i int, val float64) {
69         if uint(i) >= uint(v.n) {
70                 panic(ErrVectorAccess)
71         }
72         v.setVec(i, val)
73 }
74
75 func (v *VecDense) setVec(i int, val float64) {
76         v.mat.Data[i*v.mat.Inc] = val
77 }
78
79 // At returns the element at row i and column j.
80 func (s *SymDense) At(i, j int) float64 {
81         if uint(i) >= uint(s.mat.N) {
82                 panic(ErrRowAccess)
83         }
84         if uint(j) >= uint(s.mat.N) {
85                 panic(ErrColAccess)
86         }
87         return s.at(i, j)
88 }
89
90 func (s *SymDense) at(i, j int) float64 {
91         if i > j {
92                 i, j = j, i
93         }
94         return s.mat.Data[i*s.mat.Stride+j]
95 }
96
97 // SetSym sets the elements at (i,j) and (j,i) to the value v.
98 func (s *SymDense) SetSym(i, j int, v float64) {
99         if uint(i) >= uint(s.mat.N) {
100                 panic(ErrRowAccess)
101         }
102         if uint(j) >= uint(s.mat.N) {
103                 panic(ErrColAccess)
104         }
105         s.set(i, j, v)
106 }
107
108 func (s *SymDense) set(i, j int, v float64) {
109         if i > j {
110                 i, j = j, i
111         }
112         s.mat.Data[i*s.mat.Stride+j] = v
113 }
114
115 // At returns the element at row i, column j.
116 func (t *TriDense) At(i, j int) float64 {
117         if uint(i) >= uint(t.mat.N) {
118                 panic(ErrRowAccess)
119         }
120         if uint(j) >= uint(t.mat.N) {
121                 panic(ErrColAccess)
122         }
123         return t.at(i, j)
124 }
125
126 func (t *TriDense) at(i, j int) float64 {
127         isUpper := t.triKind()
128         if (isUpper && i > j) || (!isUpper && i < j) {
129                 return 0
130         }
131         return t.mat.Data[i*t.mat.Stride+j]
132 }
133
134 // SetTri sets the element at row i, column j to the value v.
135 // It panics if the location is outside the appropriate half of the matrix.
136 func (t *TriDense) SetTri(i, j int, v float64) {
137         if uint(i) >= uint(t.mat.N) {
138                 panic(ErrRowAccess)
139         }
140         if uint(j) >= uint(t.mat.N) {
141                 panic(ErrColAccess)
142         }
143         isUpper := t.isUpper()
144         if (isUpper && i > j) || (!isUpper && i < j) {
145                 panic(ErrTriangleSet)
146         }
147         t.set(i, j, v)
148 }
149
150 func (t *TriDense) set(i, j int, v float64) {
151         t.mat.Data[i*t.mat.Stride+j] = v
152 }
153
154 // At returns the element at row i, column j.
155 func (b *BandDense) At(i, j int) float64 {
156         if uint(i) >= uint(b.mat.Rows) {
157                 panic(ErrRowAccess)
158         }
159         if uint(j) >= uint(b.mat.Cols) {
160                 panic(ErrColAccess)
161         }
162         return b.at(i, j)
163 }
164
165 func (b *BandDense) at(i, j int) float64 {
166         pj := j + b.mat.KL - i
167         if pj < 0 || b.mat.KL+b.mat.KU+1 <= pj {
168                 return 0
169         }
170         return b.mat.Data[i*b.mat.Stride+pj]
171 }
172
173 // SetBand sets the element at row i, column j to the value v.
174 // It panics if the location is outside the appropriate region of the matrix.
175 func (b *BandDense) SetBand(i, j int, v float64) {
176         if uint(i) >= uint(b.mat.Rows) {
177                 panic(ErrRowAccess)
178         }
179         if uint(j) >= uint(b.mat.Cols) {
180                 panic(ErrColAccess)
181         }
182         pj := j + b.mat.KL - i
183         if pj < 0 || b.mat.KL+b.mat.KU+1 <= pj {
184                 panic(ErrBandSet)
185         }
186         b.set(i, j, v)
187 }
188
189 func (b *BandDense) set(i, j int, v float64) {
190         pj := j + b.mat.KL - i
191         b.mat.Data[i*b.mat.Stride+pj] = v
192 }
193
194 // At returns the element at row i, column j.
195 func (s *SymBandDense) At(i, j int) float64 {
196         if uint(i) >= uint(s.mat.N) {
197                 panic(ErrRowAccess)
198         }
199         if uint(j) >= uint(s.mat.N) {
200                 panic(ErrColAccess)
201         }
202         return s.at(i, j)
203 }
204
205 func (s *SymBandDense) at(i, j int) float64 {
206         if i > j {
207                 i, j = j, i
208         }
209         pj := j - i
210         if s.mat.K+1 <= pj {
211                 return 0
212         }
213         return s.mat.Data[i*s.mat.Stride+pj]
214 }
215
216 // SetSymBand sets the element at row i, column j to the value v.
217 // It panics if the location is outside the appropriate region of the matrix.
218 func (s *SymBandDense) SetSymBand(i, j int, v float64) {
219         if uint(i) >= uint(s.mat.N) {
220                 panic(ErrRowAccess)
221         }
222         if uint(j) >= uint(s.mat.N) {
223                 panic(ErrColAccess)
224         }
225         s.set(i, j, v)
226 }
227
228 func (s *SymBandDense) set(i, j int, v float64) {
229         if i > j {
230                 i, j = j, i
231         }
232         pj := j - i
233         if s.mat.K+1 <= pj {
234                 panic(ErrBandSet)
235         }
236         s.mat.Data[i*s.mat.Stride+pj] = v
237 }