Module: Hornetseye::Field_::Match

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

Overview

Namespace containing method for matching elements of type Field_

See Also:

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.



365
366
367
368
369
370
371
# File 'lib/multiarray/field.rb', line 365

def align(context)
  if self < Field_
    Hornetseye::MultiArray typecode.align(context), dimension
  else
    super context
  end
end

#fit(*values) ⇒ Class

Method for matching elements of type Field_

Parameters:

  • *values (Array<Object>)

    Values to find matching native element type for.

Returns:

  • (Class)

    Native type fitting all values.

See Also:



343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/multiarray/field.rb', line 343

def fit( *values )
  n = values.inject 0 do |size,value|
    value.is_a?(Array) ? [size, value.size].max : size
  end
  if n > 0
    elements = values.inject [] do |flat,value|
      flat + (value.is_a?(Array) ? value : [value])
    end
    Hornetseye::MultiArray fit( *elements ), 1
  else
    super *values
  end
end