File: oper.rb

package info (click to toggle)
ruby-gsl 2.1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,892 kB
  • ctags: 5,459
  • sloc: ansic: 61,660; ruby: 15,656; sh: 19; makefile: 10
file content (43 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module GSL::Oper

  def self.included(base)
    base.class_eval {
      alias_method :_gsl_oper_original_mul, :*
      alias_method :_gsl_oper_original_div, :/

      def *(other)
        case other
          when Numeric
            _gsl_oper_original_mul(other)
          when GSL::Matrix,          GSL::Vector,
               GSL::Matrix::Int,     GSL::Vector::Int,
               GSL::Vector::Complex, GSL::Matrix::Complex,
               *GSL.have_tensor? ? [GSL::Tensor, GSL::Tensor::Int] : []
            other.scale(self)
          else
            _gsl_oper_original_mul(other)
        end
      end

      def /(other)
        case other
          when Numeric
            _gsl_oper_original_div(other)
          when GSL::Poly, GSL::Poly::Int
            a = GSL::Poly[1]; a[0] = self
            GSL::Rational.new(a, other)
          when GSL::Vector::Col
            other.scale(self / GSL.pow_2(other.dnrm2))
          when GSL::Vector::Int::Col
            v = other.to_f
            v.scale(self / GSL.pow_2(v.dnrm2))
          else
            _gsl_oper_original_div(other)
        end
      end
    }
  end

end

[Fixnum, Float].each { |klass| klass.send(:include, GSL::Oper) }