Class: Hornetseye::COMPLEX_

Inherits:
Composite show all
Defined in:
lib/multiarray/complex.rb

Defined Under Namespace

Modules: Match

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Composite

basetype, descriptor, directive, memory, scalar, storage_size, typecodes

Methods inherited from Element

#compilable?, #descriptor, fetch, #get, #skip, #strip, #write

Methods inherited from Node

===, #[], #[]=, #array_type, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, #compilable?, compilable?, cond, contiguous, #decompose, #demand, descriptor, #descriptor, dimension, #dimension, empty?, #empty?, #finalised?, finalised?, float_scalar, floating, #force, #get, #height, height, indgen, #inspect, match, #memory, pointer_type, #pointer_type, #rgb?, rgb?, scalar, #shape, shape, #simplify, size, #size, #storage_size, #strip, strip, subst, #subst, #to_a, to_s, #to_s, to_type, #typecode, typecode, typecodes, variables, #variables, #width, width

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from Match

#align, #fit

Methods included from Sequence_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

Methods included from Operations

#+@, #<=>, #b=, #b_with_decompose, #collect, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #eq_with_multiarray, #fill!, #g=, #g_with_decompose, #histogram, #histogram_with_composite, #imag=, #imag_with_decompose, #inject, #integral, #lut, #lut_with_composite, #max, #min, #normalise, #product, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #roll, #sum, #to_type, #to_type_with_rgb, #transpose, #unroll

Constructor Details

#initialize(value = self.class.default) ⇒ COMPLEX_

Returns a new instance of COMPLEX_.



575
576
577
578
579
580
581
582
583
584
# File 'lib/multiarray/complex.rb', line 575

def initialize( value = self.class.default )
  if Thread.current[ :function ].nil? or
    [ value.real, value.imag ].all? { |c| c.is_a? GCCValue }
    @value = value
  else
    real = GCCValue.new Thread.current[ :function ], value.real.to_s
    imag = GCCValue.new Thread.current[ :function ], value.imag.to_s
    @value = InternalComplex.new real, imag
  end
end

Class Method Details

.==(other) ⇒ Boolean

Test equality of classes

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Boolean indicating whether classes are equal.



548
549
550
551
# File 'lib/multiarray/complex.rb', line 548

def ==( other )
  other.is_a? Class and other < COMPLEX_ and
    element_type == other.element_type
end

.coerce(other) ⇒ Array<Class>

Type coercion for native elements

Parameters:

  • other (Class)

    Other type to coerce with.

Returns:

  • (Array<Class>)

    Result of coercion.



533
534
535
536
537
538
539
540
541
# File 'lib/multiarray/complex.rb', line 533

def coerce( other )
  if other < COMPLEX_
    return other, self
  elsif other < INT_ or other < FLOAT_
    return Hornetseye::COMPLEX( other ), self
  else
    super other
  end        
end

.coercion(other) ⇒ Class

Compute balanced type for binary operation

Parameters:

  • other (Class)

    Other native datatype to coerce with.

Returns:

  • (Class)

    Result of coercion.



516
517
518
519
520
521
522
523
524
# File 'lib/multiarray/complex.rb', line 516

def coercion( other )
  if other < COMPLEX_
    Hornetseye::COMPLEX element_type.coercion( other.element_type )
  elsif other < INT_ or other < FLOAT_
    Hornetseye::COMPLEX element_type.coercion( other )
  else
    super other
  end
end

.construct(real, imag) ⇒ Complex, InternalComplex

Construct new object from arguments

Parameters:

  • real (Object)

    Real component of complex number.

  • imag (Object)

    Imaginary component of complex number.

Returns:



455
456
457
458
459
460
461
# File 'lib/multiarray/complex.rb', line 455

def construct( real, imag )
  if Thread.current[ :function ]
    new InternalComplex.new( real, imag )
  else
    new Complex( real, imag )
  end
end

.defaultObject, InternalComplex

Get default value for elements of this type

Returns:



469
470
471
472
473
474
475
# File 'lib/multiarray/complex.rb', line 469

def default
  if Thread.current[ :function ]
    InternalComplex.new 0, 0
  else
    Complex 0, 0
  end
end

.eql?(other) ⇒ Boolean

Equality for hash operations

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Returns true if objects are equal.



569
570
571
# File 'lib/multiarray/complex.rb', line 569

def eql?( other )
  self == other
end

.floatClass

Convert to type based on floating point numbers

Returns:

  • (Class)

    Corresponding type based on floating point numbers.



505
506
507
# File 'lib/multiarray/complex.rb', line 505

def float
  Hornetseye::COMPLEX element_type.float
end

.hashFixnum

Compute hash value for this class.

Returns:



558
559
560
# File 'lib/multiarray/complex.rb', line 558

def hash
  [ :COMPLEX_, element_type ].hash
end

.inherited(subclass) ⇒ Object

Set base class attribute

Sets number of elements to two.



443
444
445
# File 'lib/multiarray/complex.rb', line 443

def inherited( subclass )
  subclass.num_elements = 2
end

.inspectString

Display information about this class

Returns:

  • (String)

    Returns string with information about this class (e.g. “SCOMPLEX”).



481
482
483
484
485
486
487
488
489
# File 'lib/multiarray/complex.rb', line 481

def inspect
  unless element_type.nil?
    { SFLOAT => 'SCOMPLEX',
      DFLOAT => 'DCOMPLEX' }[ element_type ] ||
    "COMPLEX(#{element_type.inspect})"
  else
    super
  end
end

.maxintClass

Get corresponding maximal integer type

Returns:

  • (Class)

    Corresponding type based on integers.



496
497
498
# File 'lib/multiarray/complex.rb', line 496

def maxint
  Hornetseye::COMPLEX element_type.maxint
end

Instance Method Details

#dupCOMPLEX_

Duplicate object

Returns:



589
590
591
592
593
594
595
596
597
598
599
# File 'lib/multiarray/complex.rb', line 589

def dup
  if Thread.current[ :function ]
    real = Thread.current[ :function ].variable self.class.element_type, 'v'
    imag = Thread.current[ :function ].variable self.class.element_type, 'v'
    real.store @value.real
    imag.store @value.imag
    self.class.new InternalComplex.new( real, imag )
  else
    self.class.new get
  end
end

#store(value) ⇒ Object

Store new value in this object

Parameters:

  • value (Object)

    New value for this object.

Returns:



608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/multiarray/complex.rb', line 608

def store( value )
  value = value.simplify
  if @value.real.respond_to? :store
    @value.real.store value.get.real
  else
    @value.real = value.get.real
  end
  if @value.imag.respond_to? :store
    @value.imag.store value.get.imag
  else
    @value.imag = value.get.imag
  end
  value
end

#valuesArray<Object>

Get array with components of this value

Returns:

  • (Array<Object>)

    Returns array with real and imaginary component as elements.



629
630
631
# File 'lib/multiarray/complex.rb', line 629

def values
  [ @value.real, @value.imag ]
end