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.
5 // This file must be kept in sync with index_bound_checks.go.
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) {
16 if uint(j) >= uint(m.mat.Cols) {
22 func (m *Dense) at(i, j int) float64 {
23 return m.mat.Data[i*m.mat.Stride+j]
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) {
31 if uint(j) >= uint(m.mat.Cols) {
37 func (m *Dense) set(i, j int, v float64) {
38 m.mat.Data[i*m.mat.Stride+j] = v
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) {
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) {
62 func (v *VecDense) at(i int) float64 {
63 return v.mat.Data[i*v.mat.Inc]
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)
75 func (v *VecDense) setVec(i int, val float64) {
76 v.mat.Data[i*v.mat.Inc] = val
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) {
84 if uint(j) >= uint(s.mat.N) {
90 func (s *SymDense) at(i, j int) float64 {
94 return s.mat.Data[i*s.mat.Stride+j]
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) {
102 if uint(j) >= uint(s.mat.N) {
108 func (s *SymDense) set(i, j int, v float64) {
112 s.mat.Data[i*s.mat.Stride+j] = v
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) {
120 if uint(j) >= uint(t.mat.N) {
126 func (t *TriDense) at(i, j int) float64 {
127 isUpper := t.triKind()
128 if (isUpper && i > j) || (!isUpper && i < j) {
131 return t.mat.Data[i*t.mat.Stride+j]
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) {
140 if uint(j) >= uint(t.mat.N) {
143 isUpper := t.isUpper()
144 if (isUpper && i > j) || (!isUpper && i < j) {
145 panic(ErrTriangleSet)
150 func (t *TriDense) set(i, j int, v float64) {
151 t.mat.Data[i*t.mat.Stride+j] = v
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) {
159 if uint(j) >= uint(b.mat.Cols) {
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 {
170 return b.mat.Data[i*b.mat.Stride+pj]
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) {
179 if uint(j) >= uint(b.mat.Cols) {
182 pj := j + b.mat.KL - i
183 if pj < 0 || b.mat.KL+b.mat.KU+1 <= pj {
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
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) {
199 if uint(j) >= uint(s.mat.N) {
205 func (s *SymBandDense) at(i, j int) float64 {
213 return s.mat.Data[i*s.mat.Stride+pj]
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) {
222 if uint(j) >= uint(s.mat.N) {
228 func (s *SymBandDense) set(i, j int, v float64) {
236 s.mat.Data[i*s.mat.Stride+pj] = v