github.com/gonum/matrix@v0.0.0-20181209220409-c518dec07be9/cmat128/matrix.go (about) 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. 4 5 package cmat128 6 7 // Matrix is the basic matrix interface type. 8 type Matrix interface { 9 // Dims returns the dimensions of a Matrix. 10 Dims() (r, c int) 11 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 15 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. 20 H() Matrix 21 } 22 23 var ( 24 _ Matrix = Conjugate{} 25 _ Unconjugator = Conjugate{} 26 ) 27 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 { 32 Matrix Matrix 33 } 34 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.Matrix.At(j, i) 39 return complex(real(z), -imag(z)) 40 } 41 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.Matrix.Dims() 47 return r, c 48 } 49 50 // H performs an implicit conjugate transpose by returning the Matrix field. 51 func (t Conjugate) H() Matrix { 52 return t.Matrix 53 } 54 55 // Unconjugate returns the Matrix field. 56 func (t Conjugate) Unconjugate() Matrix { 57 return t.Matrix 58 } 59 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 66 // triangular matrix. 67 68 // Unconjugate returns the underlying Matrix stored for the implicit 69 // conjugate transpose. 70 Unconjugate() Matrix 71 }