Class: Hornetseye::COMPLEX_
- Defined in:
- lib/multiarray/complex.rb
Defined Under Namespace
Modules: Match
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.
-
.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
-
#dup ⇒ COMPLEX_
Duplicate object.
-
#initialize(value = self.class.default) ⇒ COMPLEX_
constructor
A new instance of COMPLEX_.
-
#store(value) ⇒ Object
Store new value in this object.
-
#values ⇒ Array<Object>
Get array with components of this value.
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
Methods included from OBJECT::Match
Methods included from Match
Methods included from Sequence_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
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
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
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
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
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 |
.default ⇒ Object, InternalComplex
Get default value for elements of this type
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
569 570 571 |
# File 'lib/multiarray/complex.rb', line 569 def eql?( other ) self == other end |
.float ⇒ Class
Convert to type based on floating point numbers
505 506 507 |
# File 'lib/multiarray/complex.rb', line 505 def float Hornetseye::COMPLEX element_type.float end |
.hash ⇒ Fixnum
Compute hash value for this class.
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 |
.inspect ⇒ String
Display information about this class
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 |
.maxint ⇒ Class
Get corresponding maximal integer type
496 497 498 |
# File 'lib/multiarray/complex.rb', line 496 def maxint Hornetseye::COMPLEX element_type.maxint end |
Instance Method Details
#dup ⇒ COMPLEX_
Duplicate object
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
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 |