Class: GSL::Matrix::Complex
- Inherits:
-
Object
- Object
- GSL::Matrix::Complex
- Defined in:
- lib/gs2crmod/astrogk/gsl_tools.rb,
lib/gs2crmod/gsl_tools.rb
Class Method Summary collapse
Instance Method Summary collapse
- #backward_cols_c2c(normalise = false) ⇒ Object
- #backward_rows_c2c(normalise = false) ⇒ Object
- #backward_rows_cc2r(normalise = false) ⇒ Object
- #forward_cols_c2c ⇒ Object
Class Method Details
.re_im(re, im) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gs2crmod/astrogk/gsl_tools.rb', line 48 def self.re_im(re, im) raise "Shape of real and imaginary matrices must match" unless re.shape == im.shape rows, cols = re.shape mat = alloc(rows, cols) for i in 0...rows for j in 0...cols mat[i,j] = GSL::Complex.alloc([re[i,j], im[i,j]]) end end return mat end |
Instance Method Details
#backward_cols_c2c(normalise = false) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gs2crmod/astrogk/gsl_tools.rb', line 61 def backward_cols_c2c(normalise = false) gm = self.dup rows, cols = gm.shape table = GSL.cache[[:fft_table, :complex, rows]] ||= GSL::FFT::ComplexWavetable.alloc(rows) work = GSL.cache[[:fft_work, :complex, rows]] ||= GSL::FFT::ComplexWorkspace.alloc(rows) for i in 0...cols vec = gm.col(i) vec.backward!(table, work) for j in 0...rows gm[j,i] = vec[j] end end gm = gm / rows if normalise gm end |
#backward_rows_c2c(normalise = false) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/gs2crmod/gsl_tools.rb', line 88 def backward_rows_c2c(normalise = false) gm = self.dup rows, cols = gm.shape table = GSL.cache[[:fft_table, :complex, cols]] ||= GSL::FFT::ComplexWavetable.alloc(cols) work = GSL.cache[[:fft_work, :complex, cols]] ||= GSL::FFT::ComplexWorkspace.alloc(cols) for i in 0...rows vec = gm.row(i) vec.backward!(table, work) for j in 0...cols gm[i,j] = vec[j] end end gm = gm / cols if normalise gm end |
#backward_rows_cc2r(normalise = false) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gs2crmod/astrogk/gsl_tools.rb', line 92 def backward_rows_cc2r(normalise = false) gm = self.dup rows, cols = gm.shape # if cols%2 == 0 # newcols = cols*2 # else # newcols = cols*2 - 1 # end was_even = rows.times.inject(true) do |bool, i| bool and (gm[i, cols - 1].imag == 0.0) end # ep was_even if was_even newcols = cols * 2 - 2 else newcols = cols * 2 - 1 end gm_re = GSL::Matrix.alloc(rows, newcols) table = GSL.cache[[:fft_table, :real, newcols]] ||= GSL::FFT::RealWavetable.alloc(newcols) work = GSL.cache[[:fft_work, :real, newcols]] ||= GSL::FFT::RealWorkspace.alloc(newcols) row = GSL::Vector::Complex.alloc(cols) # p rows for i in 0...rows # p i # row = gm.row(i) (0...cols).each{|j| row[j] = gm[i,j]} if was_even vec = row.concat(row.subvector(1, row.size - 2).reverse.conjugate) if cols > 2 else vec = row.concat(row.subvector(1, row.size - 1).reverse.conjugate) if cols > 1 end vec.backward!(table, work) for j in 0...newcols gm_re[i,j] = vec[j].real end end gm_re = gm_re / newcols.to_f if normalise gm_re end |
#forward_cols_c2c ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gs2crmod/astrogk/gsl_tools.rb', line 77 def forward_cols_c2c gm = self.dup rows, cols = gm.shape table = GSL.cache[[:fft_table, :complex, rows]] ||= GSL::FFT::ComplexWavetable.alloc(rows) work = GSL.cache[[:fft_work, :complex, rows]] ||= GSL::FFT::ComplexWorkspace.alloc(rows) for i in 0...cols vec = gm.col(i) vec.forward!(table, work) for j in 0...rows gm[j,i] = vec[j] end end gm end |