Class: Hornetseye::COMPLEX_
- Defined in:
- lib/multiarray/complex.rb
Overview
Class for representing native complex values
Defined Under Namespace
Modules: Match
Constant Summary collapse
Class Method Summary collapse
-
.==(other) ⇒ Boolean
Test equality of classes.
-
.coerce(other) ⇒ Array<Class>
Type coercion for native elements.
-
.coercion(other) ⇒ Class
Compute balanced type for binary operation.
-
.construct(real, imag) ⇒ Complex, InternalComplex
Construct new object from arguments.
-
.default ⇒ Object, InternalComplex
Get default value for elements of this type.
-
.eql?(other) ⇒ Boolean
Equality for hash operations.
-
.float ⇒ Class
Convert to type based on floating point numbers.
-
.hash ⇒ Fixnum
Compute hash value for this class.
- .inherit(element_type) ⇒ Object
-
.inherited(subclass) ⇒ Object
Set base class attribute.
-
.inspect ⇒ String
Display information about this class.
-
.maxint ⇒ Class
Get corresponding maximal integer type.
Instance Method Summary collapse
-
#assign(value) ⇒ Object
Store new value in this object.
-
#dup ⇒ COMPLEX_
Duplicate object.
-
#initialize(value = self.class.default) ⇒ COMPLEX_
constructor
Constructor for native complex number.
-
#values ⇒ Array<Object>
Get array with components of this value.
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
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
Constructor Details
#initialize(value = self.class.default) ⇒ COMPLEX_
Constructor for native complex number
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
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
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
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
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 |
.default ⇒ Object, InternalComplex
Get default value for elements of this type
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
848 849 850 |
# File 'lib/multiarray/complex.rb', line 848 def eql?(other) self == other end |
.float ⇒ Class
Convert to type based on floating point numbers
784 785 786 |
# File 'lib/multiarray/complex.rb', line 784 def float Hornetseye::COMPLEX element_type.float end |
.hash ⇒ Fixnum
Compute hash value for this class
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.
712 713 714 |
# File 'lib/multiarray/complex.rb', line 712 def inherited(subclass) subclass.num_elements = 2 end |
.inspect ⇒ String
Display information about this class
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 |
.maxint ⇒ Class
Get corresponding maximal integer type
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
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 |
#dup ⇒ COMPLEX_
Duplicate object
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 |