Module: Hornetseye

Defined in:
lib/multiarray.rb,
lib/multiarray/int.rb,
lib/multiarray/lut.rb,
lib/multiarray/rgb.rb,
lib/multiarray/rgb.rb,
lib/multiarray/bool.rb,
lib/multiarray/list.rb,
lib/multiarray/node.rb,
lib/multiarray/float.rb,
lib/multiarray/index.rb,
lib/multiarray/store.rb,
lib/multiarray/inject.rb,
lib/multiarray/lambda.rb,
lib/multiarray/lookup.rb,
lib/multiarray/malloc.rb,
lib/multiarray/object.rb,
lib/multiarray/complex.rb,
lib/multiarray/complex.rb,
lib/multiarray/element.rb,
lib/multiarray/gcctype.rb,
lib/multiarray/methods.rb,
lib/multiarray/pointer.rb,
lib/multiarray/diagonal.rb,
lib/multiarray/gcccache.rb,
lib/multiarray/gccvalue.rb,
lib/multiarray/integral.rb,
lib/multiarray/sequence.rb,
lib/multiarray/variable.rb,
lib/multiarray/composite.rb,
lib/multiarray/histogram.rb,
lib/multiarray/shortcuts.rb,
lib/multiarray/gcccontext.rb,
lib/multiarray/multiarray.rb,
lib/multiarray/operations.rb,
lib/multiarray/elementwise.rb,
lib/multiarray/gccfunction.rb

Overview

Namespace of Hornetseye computer vision library

Defined Under Namespace

Modules: Methods, MultiArrayConstructor, MultiArrayConversion, Operations Classes: BOOL, COMPLEX_, Composite, Diagonal, Element, ElementWise_, FLOAT_, GCCCache, GCCContext, GCCFunction, GCCType, GCCValue, Histogram, INDEX_, INT_, Inject, Integral, InternalComplex, Lambda, List, Lookup, Lut, Malloc, MultiArray, Node, OBJECT, Pointer_, RGB, RGB_, Sequence, Sequence_, Store, Variable

Constant Summary collapse

SINGLE =
false
DOUBLE =
true
SFLOAT =
FLOAT SINGLE
DFLOAT =
FLOAT DOUBLE
SCOMPLEX =
COMPLEX SFLOAT
DCOMPLEX =
COMPLEX DFLOAT
BYTERGB =
RGB BYTE
UBYTERGB =
RGB UBYTE
SINTRGB =
RGB SINT
USINTRGB =
RGB USINT
INTRGB =
RGB INT
UINTRGB =
RGB UINT
LONGRGB =
RGB LONG
ULONGRGB =
RGB ULONG
SFLOATRGB =
RGB SFLOAT
DFLOATRGB =
RGB DFLOAT
UNSIGNED =

Boolean constant to use as a parameter for creating integer classes

The value is false.

See Also:

  • #INT
false
SIGNED =

Boolean constant to use as a parameter for creating integer classes

The value is true.

See Also:

  • #INT
true
BYTE =

8-bit signed integer

INT  8, SIGNED
UBYTE =

8-bit unsigned integer

INT  8, UNSIGNED
SINT =

16-bit signed integer

INT 16, SIGNED
USINT =

16-bit unsigned integer

INT 16, UNSIGNED
INT =

32-bit signed integer

INT 32, SIGNED
UINT =

32-bit unsigned integer

INT 32, UNSIGNED
LONG =

64-bit signed integer

INT 64, SIGNED
ULONG =

64-bit unsigned integer

INT 64, UNSIGNED

Class Method Summary collapse

Class Method Details

.BOOL(value) ⇒ BOOL

Shortcut for constructor

The method calls BOOL.new.

Parameters:

  • value (Boolean)

    Boolean value.

Returns:

  • (BOOL)

    The wrapped boolean value.



148
149
150
# File 'lib/multiarray/bool.rb', line 148

def BOOL( value )
  BOOL.new value
end

.BYTE(value) ⇒ BYTE

Shortcut for constructor

The method calls BYTE.new.

Parameters:

  • value (Integer)

    Integer value.

Returns:

  • (BYTE)

    The wrapped integer value.



319
320
321
# File 'lib/multiarray/int.rb', line 319

def BYTE( value )
  BYTE.new value
end

.BYTERGB(value) ⇒ BYTERGB

Shortcut for constructor

The method calls BYTERGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:

  • (BYTERGB)

    The wrapped RGB value.



573
574
575
# File 'lib/multiarray/rgb.rb', line 573

def BYTERGB( value )
  BYTERGB.new value
end

.COMPLEX(arg) ⇒ Object



747
748
749
750
751
# File 'lib/multiarray/complex.rb', line 747

def COMPLEX( arg )
  retval = Class.new COMPLEX_
  retval.element_type = arg
  retval
end

.DCOMPLEX(value) ⇒ DCOMPLEX

Shortcut for constructor

The method calls DCOMPLEX.new.

Parameters:

  • value (Complex)

    Complex value.

Returns:

  • (DCOMPLEX)

    The wrapped Complex value.



781
782
783
# File 'lib/multiarray/complex.rb', line 781

def DCOMPLEX( value )
  DCOMPLEX.new value
end

.DFLOAT(value) ⇒ DFLOAT

Shortcut for constructor

The method calls DFLOAT.new.

Parameters:

  • value (Float)

    Floating point value.

Returns:

  • (DFLOAT)

    The wrapped floating point value.



238
239
240
# File 'lib/multiarray/float.rb', line 238

def DFLOAT( value )
  DFLOAT.new value
end

.DFLOATRGB(value) ⇒ DFLOATRGB

Shortcut for constructor

The method calls DFLOATRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:



690
691
692
# File 'lib/multiarray/rgb.rb', line 690

def DFLOATRGB( value )
  DFLOATRGB.new value
end

.eager(*shape) { ... } ⇒ Object, Node

Method for performing computations in eager mode

attempts to infer the shape if not specified.

Parameters:

  • *shape (Array<Integer>)

    Optional shape of result. The method

Yields:

  • Operation computing array elements.

Returns:



595
596
597
598
599
600
601
602
603
604
# File 'lib/multiarray.rb', line 595

def eager( *shape, &action )
  previous = Thread.current[ :lazy ]
  Thread.current[ :lazy ] = false
  begin
    retval = lazy *shape, &action
    retval.is_a?( Node ) ? retval.force : retval
  ensure
    Thread.current[ :lazy ] = previous
  end
end

.ElementWise(operation, key, conversion = lambda { |t| t.send :contiguous }) ⇒ Class

Create a class deriving from ElementWise_

Parameters:

  • operation (Proc)

    A closure with the operation to perform.

  • key (Symbol, String)

    A unique descriptor to identify this operation.

  • conversion (Proc) (defaults to: lambda { |t| t.send :contiguous })

    A closure for performing the type conversion.

Returns:

  • (Class)

    A class deriving from ElementWise_.

See Also:



225
226
227
228
229
230
231
# File 'lib/multiarray/elementwise.rb', line 225

def ElementWise( operation, key, conversion = lambda { |t| t.send :contiguous } )
  retval = Class.new ElementWise_
  retval.operation = operation
  retval.key = key
  retval.conversion = conversion
  retval
end

.FLOAT(double) ⇒ Object



203
204
205
206
207
# File 'lib/multiarray/float.rb', line 203

def FLOAT( double )
  retval = Class.new FLOAT_
  retval.double = double
  retval
end

.INDEX(size) ⇒ Object



105
106
107
108
109
110
# File 'lib/multiarray/index.rb', line 105

def INDEX( size )
  retval = Class.new INDEX_
  size = INT.new( size ) unless size.is_a? Node
  retval.size = size
  retval
end

.INT(bits, signed) ⇒ Class .INT(value) ⇒ INT

Create a class deriving from INT_ or instantiate an INT object

Overloads:

  • .INT(bits, signed) ⇒ Class

    Create a class deriving from INT_. The aprameters bits and signed are assigned to the corresponding attributes of the resulting class.

    Parameters:

    • bits (Integer)

      Number of bits of native integer.

    • signed (Boolean)

      Specify UNSIGNED or SIGNED here.

    Returns:

    • (Class)

      A class deriving from INT_.

  • .INT(value) ⇒ INT

    This is a shortcut for INT.new( value ).

    Parameters:

    • value (Integer)

      Initial value for integer object.

    Returns:

    • (INT)

      Wrapped integer value.

See Also:



273
274
275
276
277
278
279
280
281
282
# File 'lib/multiarray/int.rb', line 273

def INT( arg, signed = nil )
  if signed.nil?
    INT.new arg
  else
    retval = Class.new INT_
    retval.bits = arg
    retval.signed = signed
    retval
  end
end

.INTRGB(value) ⇒ INTRGB

Shortcut for constructor

The method calls INTRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:

  • (INTRGB)

    The wrapped RGB value.



625
626
627
# File 'lib/multiarray/rgb.rb', line 625

def INTRGB( value )
  INTRGB.new value
end

.lazy(*shape) { ... } ⇒ Object, Node

Method for performing computations in lazy mode

attempts to infer the shape if not specified.

Parameters:

  • *shape (Array<Integer>)

    Optional shape of result. The method

Yields:

  • Operation to compute array elements lazily.

Returns:



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/multiarray.rb', line 564

def lazy( *shape, &action )
  previous = Thread.current[ :lazy ]
  Thread.current[ :lazy ] = true
  begin
    options = shape.last.is_a?( Hash ) ? shape.pop : {}
    arity = options[ :arity ] || [ action.arity, shape.size ].max
    if arity <= 0
      action.call
    else
      index = Variable.new shape.empty? ? Hornetseye::INDEX( nil ) :
                                          Hornetseye::INDEX( shape.pop )
      term = lazy *( shape + [ :arity => arity - 1 ] ) do |*args|
        action.call *( args + [ index ] )
      end
      term = Node.match( term ).new term unless term.is_a? Node
      Lambda.new index, term
    end
  ensure
    Thread.current[ :lazy ] = previous
  end
end

.LONG(value) ⇒ LONG

Shortcut for constructor

The method calls LONG.new.

Parameters:

  • value (Integer)

    Integer value.

Returns:

  • (LONG)

    The wrapped integer value.



384
385
386
# File 'lib/multiarray/int.rb', line 384

def LONG( value )
  LONG.new value
end

.LONGRGB(value) ⇒ LONGRGB

Shortcut for constructor

The method calls LONGRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:

  • (LONGRGB)

    The wrapped RGB value.



651
652
653
# File 'lib/multiarray/rgb.rb', line 651

def LONGRGB( value )
  LONGRGB.new value
end

.MultiArray(element_type, *shape) ⇒ Class

Create multi-dimensional array type

Parameters:

  • element_type (Class)

    Type of elements.

  • *shape (Array<Integer>)

    Shape of array type.

Returns:

  • (Class)

    The array type.



82
83
84
85
86
87
88
89
# File 'lib/multiarray/multiarray.rb', line 82

def MultiArray( element_type, *shape )
  if shape.empty?
    element_type
  else
    Hornetseye::Sequence MultiArray( element_type, *shape[ 0 ... -1 ] ),
                         shape.last
  end
end

.OBJECT(value) ⇒ OBJECT

Shortcut for constructor

The method calls OBJECT.new.

Parameters:

  • value (Object)

    Ruby object.

Returns:

  • (OBJECT)

    The wrapped Ruby object.



169
170
171
# File 'lib/multiarray/object.rb', line 169

def OBJECT( value )
  OBJECT.new value
end

.Pointer(target) ⇒ Object



231
232
233
234
235
# File 'lib/multiarray/pointer.rb', line 231

def Pointer( target )
  p = Class.new Pointer_
  p.target = target
  p
end

.RGB(arg, g = nil, b = nil) ⇒ Object



532
533
534
535
536
537
538
539
540
# File 'lib/multiarray/rgb.rb', line 532

def RGB( arg, g = nil, b = nil )
  if g.nil? and b.nil?
    retval = Class.new RGB_
    retval.element_type = arg
    retval
  else
    RGB.new arg, g, b
  end
end

.SCOMPLEX(value) ⇒ SCOMPLEX

Shortcut for constructor

The method calls SCOMPLEX.new.

Parameters:

  • value (Complex)

    Complex value.

Returns:

  • (SCOMPLEX)

    The wrapped Complex value.



768
769
770
# File 'lib/multiarray/complex.rb', line 768

def SCOMPLEX( value )
  SCOMPLEX.new value
end

.Sequence(element_type, num_elements) ⇒ Object



383
384
385
386
387
388
# File 'lib/multiarray/sequence.rb', line 383

def Sequence( element_type, num_elements )
  retval = Class.new Sequence_
  retval.element_type = element_type
  retval.num_elements = num_elements
  retval
end

.SFLOAT(value) ⇒ SFLOAT

Shortcut for constructor

The method calls SFLOAT.new.

Parameters:

  • value (Float)

    Floating point value.

Returns:

  • (SFLOAT)

    The wrapped floating point value.



223
224
225
# File 'lib/multiarray/float.rb', line 223

def SFLOAT( value )
  SFLOAT.new value
end

.SFLOATRGB(value) ⇒ SFLOATRGB

Shortcut for constructor

The method calls SFLOATRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:



677
678
679
# File 'lib/multiarray/rgb.rb', line 677

def SFLOATRGB( value )
  SFLOATRGB.new value
end

.SINT(value) ⇒ SINT

Shortcut for constructor

The method calls SINT.new.

Parameters:

  • value (Integer)

    Integer value.

Returns:

  • (SINT)

    The wrapped integer value.



345
346
347
# File 'lib/multiarray/int.rb', line 345

def SINT( value )
  SINT.new value
end

.SINTRGB(value) ⇒ SINTRGB

Shortcut for constructor

The method calls SINTRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:

  • (SINTRGB)

    The wrapped RGB value.



599
600
601
# File 'lib/multiarray/rgb.rb', line 599

def SINTRGB( value )
  SINTRGB.new value
end

.sum(*shape) { ... } ⇒ Object, Node

Method for summing values

attempts to infer the shape if not specified.

Parameters:

  • *shape (Array<Integer>)

    Optional shape of result. The method

Yields:

  • Operation returning array elements.

Returns:



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/multiarray.rb', line 615

def sum( *shape, &action )
  options = shape.last.is_a?( Hash ) ? shape.pop : {}
  arity = options[ :arity ] || [ action.arity, shape.size ].max
  if arity <= 0
    action.call
  else
    index = Variable.new shape.empty? ? Hornetseye::INDEX( nil ) :
                         Hornetseye::INDEX( shape.pop )
    term = sum *( shape + [ :arity => arity - 1 ] ) do |*args|
      action.call *( args + [ index ] )
    end
    var1 = Variable.new term.typecode
    var2 = Variable.new term.typecode
    Inject.new( term, index, nil, var1 + var2, var1, var2 ).force
  end
end

.UBYTE(value) ⇒ UBYTE

Shortcut for constructor

The method calls UBYTE.new.

Parameters:

  • value (Integer)

    Integer value.

Returns:

  • (UBYTE)

    The wrapped integer value.



332
333
334
# File 'lib/multiarray/int.rb', line 332

def UBYTE( value )
  UBYTE.new value
end

.UBYTERGB(value) ⇒ UBYTERGB

Shortcut for constructor

The method calls UBYTERGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:



586
587
588
# File 'lib/multiarray/rgb.rb', line 586

def UBYTERGB( value )
  UBYTERGB.new value
end

.UINT(value) ⇒ UINT

Shortcut for constructor

The method calls UINT.new.

Parameters:

  • value (Integer)

    Integer value.

Returns:

  • (UINT)

    The wrapped integer value.



371
372
373
# File 'lib/multiarray/int.rb', line 371

def UINT( value )
  UINT.new value
end

.UINTRGB(value) ⇒ UINTRGB

Shortcut for constructor

The method calls UINTRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:

  • (UINTRGB)

    The wrapped RGB value.



638
639
640
# File 'lib/multiarray/rgb.rb', line 638

def UINTRGB( value )
  UINTRGB.new value
end

.ULONG(value) ⇒ ULONG

Shortcut for constructor

The method calls ULONG.new.

Parameters:

  • value (Integer)

    Integer value.

Returns:

  • (ULONG)

    The wrapped integer value.



397
398
399
# File 'lib/multiarray/int.rb', line 397

def ULONG( value )
  ULONG.new value
end

.ULONGRGB(value) ⇒ ULONGRGB

Shortcut for constructor

The method calls ULONGRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:



664
665
666
# File 'lib/multiarray/rgb.rb', line 664

def ULONGRGB( value )
  ULONGRGB.new value
end

.USINT(value) ⇒ USINT

Shortcut for constructor

The method calls USINT.new.

Parameters:

  • value (Integer)

    Integer value.

Returns:

  • (USINT)

    The wrapped integer value.



358
359
360
# File 'lib/multiarray/int.rb', line 358

def USINT( value )
  USINT.new value
end

.USINTRGB(value) ⇒ USINTRGB

Shortcut for constructor

The method calls USINTRGB.new.

Parameters:

  • value (RGB)

    RGB value.

Returns:



612
613
614
# File 'lib/multiarray/rgb.rb', line 612

def USINTRGB( value )
  USINTRGB.new value
end