Class: Hornetseye::COMPLEX_

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

Overview

Class for representing native complex values

Defined Under Namespace

Modules: Match

Constant Summary collapse

IDENTIFIER =

Identifier array used internally

{ SFLOAT => 'SCOMPLEX',
DFLOAT => 'DCOMPLEX' }

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Composite

basetype, #decompose, descriptor, directive, memory_type, scalar, storage_size, typecodes

Methods inherited from Element

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

Methods inherited from Node

#+@, #<=>, ===, #[], #[]=, #allocate, #b=, #b_with_decompose, #basetype, basetype, #between?, bool, byte, #check_shape, #clip, #coerce, coercion_bool, coercion_byte, coercion_maxint, #collect, #compilable?, compilable?, #components, cond, #conditional, #convolve, #decompose, define_binary_op, define_unary_op, #demand, #descriptor, descriptor, #diagonal, #dilate, #dimension, dimension, #downsample, #each, #empty?, #eq_with_multiarray, #erode, #fill!, finalised?, #finalised?, #flip, float_scalar, floating, #fmod_with_float, #force, #g=, #g_with_decompose, #gauss_blur, #gauss_gradient, #get, #height, #histogram, #histogram_with_rgb, identity, #if, #if_else, #imag=, #imag_with_decompose, indgen, #inject, #inspect, #integral, #lut, #lut_with_rgb, #malloc, #mask, match, #matched?, #max, #mean, #memorise, #memory, #min, #normalise, #prod, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, #shape, shape, #shift, #simplify, #size, #sobel, #stretch, #stride, #strides, #strip, strip, #subst, subst, #sum, #swap_rgb_with_scalar, #table, #to_a, #to_s, to_s, #to_type, to_type, #to_type_with_identity, #to_type_with_rgb, #transpose, #typecode, typecode, typecodes, #unmask, #unroll, #variables, variables, #warp, #width

Methods included from Field_::Match

#align, #fit

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

Constructor Details

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

Constructor for native complex number

Parameters:



857
858
859
860
861
862
863
864
865
866
# File 'lib/multiarray/complex.rb', line 857

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.



827
828
829
830
# File 'lib/multiarray/complex.rb', line 827

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.



812
813
814
815
816
817
818
819
820
# File 'lib/multiarray/complex.rb', line 812

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.



795
796
797
798
799
800
801
802
803
# File 'lib/multiarray/complex.rb', line 795

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:



730
731
732
733
734
735
736
# File 'lib/multiarray/complex.rb', line 730

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:



744
745
746
747
748
749
750
# File 'lib/multiarray/complex.rb', line 744

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.



848
849
850
# File 'lib/multiarray/complex.rb', line 848

def eql?(other)
  self == other
end

.floatClass

Convert to type based on floating point numbers

Returns:

  • (Class)

    Corresponding type based on floating point numbers.



784
785
786
# File 'lib/multiarray/complex.rb', line 784

def float
  Hornetseye::COMPLEX element_type.float
end

.hashFixnum

Compute hash value for this class

Returns:



837
838
839
# File 'lib/multiarray/complex.rb', line 837

def hash
  [ :COMPLEX_, element_type ].hash
end

.inherit(element_type) ⇒ Object



716
717
718
719
720
# File 'lib/multiarray/complex.rb', line 716

def inherit(element_type)
  retval = Class.new self
  retval.element_type = element_type
  retval
end

.inherited(subclass) ⇒ Object

Set base class attribute

Sets number of elements to two.

Parameters:

  • subclass (Class)

    The class inheriting from COMPLEX_.

Returns:

  • The return value should be ignored.



712
713
714
# File 'lib/multiarray/complex.rb', line 712

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”).



762
763
764
765
766
767
768
# File 'lib/multiarray/complex.rb', line 762

def inspect
  unless element_type.nil?
    IDENTIFIER[ element_type ] || "COMPLEX(#{element_type.inspect})"
  else
    super
  end
end

.maxintClass

Get corresponding maximal integer type

Returns:

  • (Class)

    Corresponding type based on integers.



775
776
777
# File 'lib/multiarray/complex.rb', line 775

def maxint
  Hornetseye::COMPLEX element_type.maxint
end

Instance Method Details

#assign(value) ⇒ Object

Store new value in this object

Parameters:

  • value (Object)

    New value for this object.

Returns:



890
891
892
893
894
895
896
897
898
899
900
901
902
903
# File 'lib/multiarray/complex.rb', line 890

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

#dupCOMPLEX_

Duplicate object

Returns:



871
872
873
874
875
876
877
878
879
880
881
# File 'lib/multiarray/complex.rb', line 871

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.assign @value.real
    imag.assign @value.imag
    self.class.new InternalComplex.new( real, imag )
  else
    self.class.new get
  end
end

#valuesArray<Object>

Get array with components of this value

Returns:

  • (Array<Object>)

    Returns array with real and imaginary component as elements.



911
912
913
# File 'lib/multiarray/complex.rb', line 911

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