mat: Add CDense type and basic methods
* mat: Add CDense type and basic methods
Updates
MODIFY
mat/cmatrix.go
mat/cmatrix.go
package mat
+import "math/cmplx"
+
// CMatrix is the basic matrix interface type for complex matrices.
type CMatrix interface {
// Dims returns the dimensions of a Matrix.
@@ -32,11 +34,11 @@ type Conjugate struct {
CMatrix CMatrix
}
-// At returns the value of the element at row i and column j of the transposed
-// matrix, that is, row j and column i of the Matrix field.
+// At returns the value of the element at row i and column j of the conjugate
+// transposed matrix, that is, row j and column i of the Matrix field.
func (t Conjugate) At(i, j int) complex128 {
z := t.CMatrix.At(j, i)
- return complex(real(z), -imag(z))
+ return cmplx.Conj(z)
}
// Dims returns the dimensions of the transposed matrix. The number of rows returned

MODIFY
mat/index_bound_checks.go
mat/index_bound_checks.go
@@ -38,6 +38,36 @@ func (m *Dense) set(i, j int, v float64) {
m.mat.Data[i*m.mat.Stride+j] = v
}
+// At returns the element at row i, column j.
+func (m *CDense) At(i, j int) complex128 {
+ return m.at(i, j)
+}
+
+func (m *CDense) at(i, j int) complex128 {
+ if uint(i) >= uint(m.mat.Rows) {
+ panic(ErrRowAccess)
+ }
+ if uint(j) >= uint(m.mat.Cols) {
+ panic(ErrColAccess)
+ }
+ return m.mat.Data[i*m.mat.Stride+j]
+}
+
+// Set sets the element at row i, column j to the value v.
+func (m *CDense) Set(i, j int, v complex128) {
+ m.set(i, j, v)
+}
+
+func (m *CDense) set(i, j int, v complex128) {
+ if uint(i) >= uint(m.mat.Rows) {
+ panic(ErrRowAccess)
+ }
+ if uint(j) >= uint(m.mat.Cols) {
+ panic(ErrColAccess)
+ }
+ m.mat.Data[i*m.mat.Stride+j] = v
+}
+
// At returns the element at row i.
// It panics if i is out of bounds or if j is not zero.
func (v *VecDense) At(i, j int) float64 {

MODIFY
mat/index_no_bound_checks.go
mat/index_no_bound_checks.go
@@ -38,6 +38,36 @@ func (m *Dense) set(i, j int, v float64) {
m.mat.Data[i*m.mat.Stride+j] = v
}
+// At returns the element at row i, column j.
+func (m *CDense) At(i, j int) complex128 {
+ if uint(i) >= uint(m.mat.Rows) {
+ panic(ErrRowAccess)
+ }
+ if uint(j) >= uint(m.mat.Cols) {
+ panic(ErrColAccess)
+ }
+ return m.at(i, j)
+}
+
+func (m *CDense) at(i, j int) complex128 {
+ return m.mat.Data[i*m.mat.Stride+j]
+}
+
+// Set sets the element at row i, column j to the value v.
+func (m *CDense) Set(i, j int, v complex128) {
+ if uint(i) >= uint(m.mat.Rows) {
+ panic(ErrRowAccess)
+ }
+ if uint(j) >= uint(m.mat.Cols) {
+ panic(ErrColAccess)
+ }
+ m.set(i, j, v)
+}
+
+func (m *CDense) set(i, j int, v complex128) {
+ m.mat.Data[i*m.mat.Stride+j] = v
+}
+
// At returns the element at row i.
// It panics if i is out of bounds or if j is not zero.
func (v *VecDense) At(i, j int) float64 {

mat: Add CDense type and basic methods (#846)

* mat: Add CDense type and basic methods

Updates #738.