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_no_bound_checks.go.
11 // At returns the element at row i, column j.
12 func (m *Dense) At(i, j int) float64 {
16 func (m *Dense) at(i, j int) float64 {
17 if uint(i) >= uint(m.mat.Rows) {
20 if uint(j) >= uint(m.mat.Cols) {
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) {
31 func (m *Dense) set(i, j int, v float64) {
32 if uint(i) >= uint(m.mat.Rows) {
35 if uint(j) >= uint(m.mat.Cols) {
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 {
50 // AtVec returns the element at row i.
51 // It panics if i is out of bounds.
52 func (v *VecDense) AtVec(i int) float64 {
56 func (v *VecDense) at(i int) float64 {
57 if uint(i) >= uint(v.n) {
60 return v.mat.Data[i*v.mat.Inc]
63 // SetVec sets the element at row i to the value val.
64 // It panics if i is out of bounds.
65 func (v *VecDense) SetVec(i int, val float64) {
69 func (v *VecDense) setVec(i int, val float64) {
70 if uint(i) >= uint(v.n) {
71 panic(ErrVectorAccess)
73 v.mat.Data[i*v.mat.Inc] = val
76 // At returns the element at row i and column j.
77 func (t *SymDense) At(i, j int) float64 {
81 func (t *SymDense) at(i, j int) float64 {
82 if uint(i) >= uint(t.mat.N) {
85 if uint(j) >= uint(t.mat.N) {
91 return t.mat.Data[i*t.mat.Stride+j]
94 // SetSym sets the elements at (i,j) and (j,i) to the value v.
95 func (t *SymDense) SetSym(i, j int, v float64) {
99 func (t *SymDense) set(i, j int, v float64) {
100 if uint(i) >= uint(t.mat.N) {
103 if uint(j) >= uint(t.mat.N) {
109 t.mat.Data[i*t.mat.Stride+j] = v
112 // At returns the element at row i, column j.
113 func (t *TriDense) At(i, j int) float64 {
117 func (t *TriDense) at(i, j int) float64 {
118 if uint(i) >= uint(t.mat.N) {
121 if uint(j) >= uint(t.mat.N) {
124 isUpper := t.isUpper()
125 if (isUpper && i > j) || (!isUpper && i < j) {
128 return t.mat.Data[i*t.mat.Stride+j]
131 // SetTri sets the element of the triangular matrix at row i, column j to the value v.
132 // It panics if the location is outside the appropriate half of the matrix.
133 func (t *TriDense) SetTri(i, j int, v float64) {
137 func (t *TriDense) set(i, j int, v float64) {
138 if uint(i) >= uint(t.mat.N) {
141 if uint(j) >= uint(t.mat.N) {
144 isUpper := t.isUpper()
145 if (isUpper && i > j) || (!isUpper && i < j) {
146 panic(ErrTriangleSet)
148 t.mat.Data[i*t.mat.Stride+j] = v
151 // At returns the element at row i, column j.
152 func (b *BandDense) At(i, j int) float64 {
156 func (b *BandDense) at(i, j int) float64 {
157 if uint(i) >= uint(b.mat.Rows) {
160 if uint(j) >= uint(b.mat.Cols) {
163 pj := j + b.mat.KL - i
164 if pj < 0 || b.mat.KL+b.mat.KU+1 <= pj {
167 return b.mat.Data[i*b.mat.Stride+pj]
170 // SetBand sets the element at row i, column j to the value v.
171 // It panics if the location is outside the appropriate region of the matrix.
172 func (b *BandDense) SetBand(i, j int, v float64) {
176 func (b *BandDense) set(i, j int, v float64) {
177 if uint(i) >= uint(b.mat.Rows) {
180 if uint(j) >= uint(b.mat.Cols) {
183 pj := j + b.mat.KL - i
184 if pj < 0 || b.mat.KL+b.mat.KU+1 <= pj {
187 b.mat.Data[i*b.mat.Stride+pj] = v
190 // At returns the element at row i, column j.
191 func (s *SymBandDense) At(i, j int) float64 {
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) {
209 return s.mat.Data[i*s.mat.Stride+pj]
212 // SetSymBand sets the element at row i, column j to the value v.
213 // It panics if the location is outside the appropriate region of the matrix.
214 func (s *SymBandDense) SetSymBand(i, j int, v float64) {
218 func (s *SymBandDense) set(i, j int, v float64) {
219 if uint(i) >= uint(s.mat.N) {
222 if uint(j) >= uint(s.mat.N) {
232 s.mat.Data[i*s.mat.Stride+pj] = v