Module: Hornetseye::COMPLEX_::Match

Included in:
Node
Defined in:
lib/multiarray/complex.rb

Instance Method Summary collapse

Instance Method Details

#align(context) ⇒ Object

Perform type alignment

Align this type to another. This is used to prefer single-precision floating point in certain cases.

Parameters:

  • context (Class)

    Other type to align with.



678
679
680
681
682
683
684
# File 'lib/multiarray/complex.rb', line 678

def align( context )
  if self < COMPLEX_
    Hornetseye::COMPLEX element_type.align( context )
  else
    super context
  end
end

#fit(*values) ⇒ Class

Method for matching elements of type COMPLEX_

Parameters:

  • *values (Array<Object>)

    Values to find matching native element type for.

Returns:

  • (Class)

    Native type fitting all values.

See Also:



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/multiarray/complex.rb', line 645

def fit( *values )
  if values.all? { |value| value.is_a? InternalComplex or value.is_a? Complex or
                           value.is_a? Float or value.is_a? Integer }
    if values.any? { |value| value.is_a? InternalComplex or value.is_a? Complex }
      elements = values.inject( [] ) do |arr,value|
        if value.is_a? InternalComplex or value.is_a? Complex
          arr + [ value.real, value.imag ]
        else
          arr + [ value ]
        end
      end
      element_fit = fit *elements
      if element_fit == OBJECT
        super *values
      else
        Hornetseye::COMPLEX element_fit
      end
    else
      super *values
    end
  else
    super *values
  end
end