1 // Copyright ©2013 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.
7 // CMatrix is the basic matrix interface type for complex matrices.
8 type CMatrix interface {
9 // Dims returns the dimensions of a Matrix.
12 // At returns the value of a matrix element at row i, column j.
13 // It will panic if i or j are out of bounds for the matrix.
14 At(i, j int) complex128
16 // H returns the conjugate transpose of the Matrix. Whether H
17 // returns a copy of the underlying data is implementation dependent.
18 // This method may be implemented using the Conjugate type, which
19 // provides an implicit matrix conjugate transpose.
24 _ CMatrix = Conjugate{}
25 _ Unconjugator = Conjugate{}
28 // Conjugate is a type for performing an implicit matrix conjugate transpose.
29 // It implements the Matrix interface, returning values from the conjugate
30 // transpose of the matrix within.
31 type Conjugate struct {
35 // At returns the value of the element at row i and column j of the transposed
36 // matrix, that is, row j and column i of the Matrix field.
37 func (t Conjugate) At(i, j int) complex128 {
38 z := t.CMatrix.At(j, i)
39 return complex(real(z), -imag(z))
42 // Dims returns the dimensions of the transposed matrix. The number of rows returned
43 // is the number of columns in the Matrix field, and the number of columns is
44 // the number of rows in the Matrix field.
45 func (t Conjugate) Dims() (r, c int) {
46 c, r = t.CMatrix.Dims()
50 // H performs an implicit conjugate transpose by returning the Matrix field.
51 func (t Conjugate) H() CMatrix {
55 // Unconjugate returns the Matrix field.
56 func (t Conjugate) Unconjugate() CMatrix {
60 // Unconjugator is a type that can undo an implicit conjugate transpose.
61 type Unconjugator interface {
62 // Note: This interface is needed to unify all of the Conjugate types. In
63 // the cmat128 methods, we need to test if the Matrix has been implicitly
64 // transposed. If this is checked by testing for the specific Conjugate type
65 // then the behavior will be different if the user uses H() or HTri() for a
68 // Unconjugate returns the underlying Matrix stored for the implicit
69 // conjugate transpose.