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/mask.rb,
lib/multiarray/node.rb,
lib/multiarray/field.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/random.rb,
lib/multiarray/unmask.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/argument.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/components.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, ReaderConversion Classes: Argument, BOOL, COMPLEX_, Components, Composite, Diagonal, Element, ElementWise_, FLOAT_, Field_, GCCCache, GCCContext, GCCFunction, GCCType, GCCValue, Histogram, INDEX_, INT_, Inject, Integral, InternalComplex, Lambda, List, Lookup, Lut, Malloc, Mask, MultiArray, Node, OBJECT, Pointer_, RGB, RGB_, Random, Sequence, Store, Unmask, Variable
Constant Summary collapse
- SINGLE =
Boolean constant to use as a parameter for creating floating point classes
The value is
false
. false
- DOUBLE =
Boolean constant to use as a parameter for creating floating point classes
The value is
true
. true
- SFLOAT =
Single-precision floating-point number
FLOAT SINGLE
- DFLOAT =
Double-precision floating-point number
FLOAT DOUBLE
- SCOMPLEX =
Convenience shortcut for single-precision floating-point complex numbers
COMPLEX SFLOAT
- DCOMPLEX =
Convenience shortcut for double-precision floating-point complex numbers
COMPLEX DFLOAT
- BYTERGB =
24-bit unsigned RGB-triplet
RGB BYTE
- UBYTERGB =
24-bit signed RGB-triplet
RGB UBYTE
- SINTRGB =
48-bit unsigned RGB-triplet
RGB SINT
- USINTRGB =
48-bit signed RGB-triplet
RGB USINT
- INTRGB =
96-bit unsigned RGB-triplet
RGB INT
- UINTRGB =
96-bit signed RGB-triplet
RGB UINT
- LONGRGB =
192-bit unsigned RGB-triplet
RGB LONG
- ULONGRGB =
192-bit signed RGB-triplet
RGB ULONG
- SFLOATRGB =
single precision RGB-triplet
RGB SFLOAT
- DFLOATRGB =
double precision RGB-triplet
RGB DFLOAT
- UNSIGNED =
Boolean constant to use as a parameter for creating integer classes
The value is
false
. false
- SIGNED =
Boolean constant to use as a parameter for creating integer classes
The value is
true
. 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
- .argmax(&action) ⇒ Object
- .argmin(&action) ⇒ Object
- .argument(block, options = {}, &action) ⇒ Object
-
.BOOL(value) ⇒ BOOL
Shortcut for constructor.
-
.BYTE(value) ⇒ BYTE
Shortcut for constructor.
-
.BYTERGB(value) ⇒ BYTERGB
Shortcut for constructor.
-
.COMPLEX(element_type) ⇒ Class
Create a class deriving from
COMPLEX_
. -
.DCOMPLEX(value) ⇒ DCOMPLEX
Shortcut for constructor.
-
.DFLOAT(value) ⇒ DFLOAT
Shortcut for constructor.
-
.DFLOATRGB(value) ⇒ DFLOATRGB
Shortcut for constructor.
-
.ElementWise(operation, key, conversion = proc { |t| t.send :identity }) ⇒ Class
Create a class deriving from
ElementWise_
. -
.finalise(*shape) { ... } ⇒ Object, Node
Method for performing a lazy computation and then forcing the result.
-
.FLOAT(double) ⇒ Class
Create a class deriving from
FLOAT_
. -
.INDEX(size) ⇒ Class
Instantiate the type of an array index.
-
.inject(*shape, op) { ... } ⇒ Object, Node
Method for specifying injections in a different way.
-
.INT(arg, signed = nil) ⇒ Class, INT
Create a class deriving from
INT_
or instantiate anINT
object. -
.INTRGB(value) ⇒ INTRGB
Shortcut for constructor.
-
.lazy(*shape) { ... } ⇒ Object, Node
Method for performing computations in lazy mode resulting in a lazy expression.
-
.LONG(value) ⇒ LONG
Shortcut for constructor.
-
.LONGRGB(value) ⇒ LONGRGB
Shortcut for constructor.
-
.max(*shape) { ... } ⇒ Object, Node
Method for computing maximum of values.
-
.min(*shape) { ... } ⇒ Object, Node
Method for computing minimum of values.
- .MultiArray(typecode, dimension) ⇒ Object
-
.OBJECT(value) ⇒ OBJECT
Shortcut for constructor.
-
.Pointer(target) ⇒ Class
Create a class deriving from
Pointer_
. -
.prod(*shape) { ... } ⇒ Object, Node
Method for computing product of values.
-
.RGB(arg, g = nil, b = nil) ⇒ Class, RGB
Create a class deriving from
RGB_
or instantiate anRGB
object. -
.SCOMPLEX(value) ⇒ SCOMPLEX
Shortcut for constructor.
-
.Sequence(element_type) ⇒ Class
Create a class to represent one-dimensional uniform arrays.
-
.SFLOAT(value) ⇒ SFLOAT
Shortcut for constructor.
-
.SFLOATRGB(value) ⇒ SFLOATRGB
Shortcut for constructor.
-
.SINT(value) ⇒ SINT
Shortcut for constructor.
-
.SINTRGB(value) ⇒ SINTRGB
Shortcut for constructor.
-
.sum(*shape) { ... } ⇒ Object, Node
Method for summing values.
-
.UBYTE(value) ⇒ UBYTE
Shortcut for constructor.
-
.UBYTERGB(value) ⇒ UBYTERGB
Shortcut for constructor.
-
.UINT(value) ⇒ UINT
Shortcut for constructor.
-
.UINTRGB(value) ⇒ UINTRGB
Shortcut for constructor.
-
.ULONG(value) ⇒ ULONG
Shortcut for constructor.
-
.ULONGRGB(value) ⇒ ULONGRGB
Shortcut for constructor.
-
.USINT(value) ⇒ USINT
Shortcut for constructor.
-
.USINTRGB(value) ⇒ USINTRGB
Shortcut for constructor.
Class Method Details
.argmax(&action) ⇒ Object
926 927 928 |
# File 'lib/multiarray.rb', line 926 def argmax(&action) argument proc { |a,b| a > b }, &action end |
.argmin(&action) ⇒ Object
932 933 934 |
# File 'lib/multiarray.rb', line 932 def argmin(&action) argument proc { |a,b| a < b }, &action end |
.argument(block, options = {}, &action) ⇒ Object
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 |
# File 'lib/multiarray.rb', line 890 def argument(block, = {}, &action) arity = [:arity] || action.arity if arity > 0 indices = [:indices] || (0 ... arity).collect { Variable.new Hornetseye::INDEX(nil) } term = [:term] || action.call(*indices) slices = indices[0 ... -1].inject(term) { |t,index| Lambda.new index, t } var1 = [:var1] || Variable.new(term.typecode) var2 = [:var2] || Variable.new(term.typecode) block = [:block] || block.call( var1, var2 ) lut = Argument.new(slices, indices.last, block, var1, var2, INT.new(0)).force arr = [:arr] || Lambda.new(indices.last, slices) id = (0 ... arr.dimension - 1).collect { |j| lazy(*arr.shape[0 ... -1]) { |*i| i[j] } } lut = INT.new(lut) unless lut.matched? sub_arr = Lut.new(*(id + [lut] + [arr])).force indices = (0 ... arity - 1).collect { Variable.new Hornetseye::INDEX(nil) } term = indices.reverse.inject(sub_arr) { |t,index| t.element index } sub_arg = argument nil, :arity => arity - 1, :indices => indices, :term => term, :arr => sub_arr, :block => block, :var1 => var1, :var2 => var2 if sub_arg.empty? [lut[]] elsif sub_arg.first.is_a? Integer sub_arg + [lut[*sub_arg]] else id = (0 ... sub_arg.first.dimension).collect do |i| lazy(*sub_arg.first.shape) { |*j| j[i] } end sub_arg + [lut.warp(*(id + sub_arg))] end else [] end end |
.BOOL(value) ⇒ BOOL
Shortcut for constructor
The method calls BOOL.new
.
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
.
350 351 352 |
# File 'lib/multiarray/int.rb', line 350 def BYTE( value ) BYTE.new value end |
.BYTERGB(value) ⇒ BYTERGB
Shortcut for constructor
The method calls BYTERGB.new
.
746 747 748 |
# File 'lib/multiarray/rgb.rb', line 746 def BYTERGB(value) BYTERGB.new value end |
.COMPLEX(element_type) ⇒ Class
Create a class deriving from COMPLEX_
Create a class deriving from COMPLEX_
. The parameter element_type
is assigned to the corresponding attribute of the resulting class.
1064 1065 1066 |
# File 'lib/multiarray/complex.rb', line 1064 def COMPLEX( element_type ) COMPLEX_.inherit element_type end |
.DCOMPLEX(value) ⇒ DCOMPLEX
Shortcut for constructor
The method calls DCOMPLEX.new
.
1098 1099 1100 |
# File 'lib/multiarray/complex.rb', line 1098 def DCOMPLEX(value) DCOMPLEX.new value end |
.DFLOAT(value) ⇒ DFLOAT
Shortcut for constructor
The method calls DFLOAT.new
.
278 279 280 |
# File 'lib/multiarray/float.rb', line 278 def DFLOAT( value ) DFLOAT.new value end |
.DFLOATRGB(value) ⇒ DFLOATRGB
Shortcut for constructor
The method calls DFLOATRGB.new
.
863 864 865 |
# File 'lib/multiarray/rgb.rb', line 863 def DFLOATRGB(value) DFLOATRGB.new value end |
.ElementWise(operation, key, conversion = proc { |t| t.send :identity }) ⇒ Class
Create a class deriving from ElementWise_
226 227 228 229 230 231 232 |
# File 'lib/multiarray/elementwise.rb', line 226 def ElementWise( operation, key, conversion = proc { |t| t.send :identity } ) retval = Class.new ElementWise_ retval.operation = operation retval.key = key retval.conversion = conversion retval end |
.finalise(*shape) { ... } ⇒ Object, Node
Method for performing a lazy computation and then forcing the result
attempts to infer the shape if not specified.
798 799 800 801 802 803 804 805 806 807 |
# File 'lib/multiarray.rb', line 798 def finalise( *shape, &action ) previous = Thread.current[ :lazy ] Thread.current[ :lazy ] = false begin retval = lazy *shape, &action retval.matched? ? retval.force : retval ensure Thread.current[ :lazy ] = previous end end |
.FLOAT(double) ⇒ Class
Create a class deriving from FLOAT_
Create a class deriving from FLOAT_
. The parameters double
is assigned to the corresponding attributes of the resulting class.
242 243 244 |
# File 'lib/multiarray/float.rb', line 242 def FLOAT(double) FLOAT_.inherit double end |
.INDEX(size) ⇒ Class
Instantiate the type of an array index
115 116 117 118 119 120 |
# File 'lib/multiarray/index.rb', line 115 def INDEX( size ) retval = Class.new INDEX_ size = INT.new(size) unless size.matched? retval.size = size retval end |
.inject(*shape, op) { ... } ⇒ Object, Node
Method for specifying injections in a different way
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
# File 'lib/multiarray.rb', line 821 def inject(*shape, &action) op = shape.pop = shape.last.is_a?(Hash) ? shape.pop : {} arity = [:arity] || [action.arity, shape.size].max if arity <= 0 term = action.call term.matched? ? term.to_type(term.typecode.maxint) : term else index = Variable.new shape.empty? ? Hornetseye::INDEX(nil) : Hornetseye::INDEX(shape.pop) term = inject *(shape + [:arity => arity - 1] + [op]) do |*args| action.call *(args + [index]) end var1 = Variable.new term.typecode var2 = Variable.new term.typecode Inject.new(term, index, nil, op.call(var1, var2), var1, var2).force end end |
.INT(bits, signed) ⇒ Class .INT(value) ⇒ INT
Create a class deriving from INT_
or instantiate an INT
object
307 308 309 310 311 312 313 |
# File 'lib/multiarray/int.rb', line 307 def INT( arg, signed = nil ) if signed.nil? INT.new arg else INT_.inherit arg, signed end end |
.INTRGB(value) ⇒ INTRGB
Shortcut for constructor
The method calls INTRGB.new
.
798 799 800 |
# File 'lib/multiarray/rgb.rb', line 798 def INTRGB(value) INTRGB.new value end |
.lazy(*shape) { ... } ⇒ Object, Node
Method for performing computations in lazy mode resulting in a lazy expression
attempts to infer the shape if not specified.
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 |
# File 'lib/multiarray.rb', line 767 def lazy( *shape, &action ) previous = Thread.current[ :lazy ] Thread.current[ :lazy ] = true begin = shape.last.is_a?( Hash ) ? shape.pop : {} arity = [ :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.matched? Lambda.new index, term end ensure Thread.current[ :lazy ] = previous end end |
.LONG(value) ⇒ LONG
Shortcut for constructor
The method calls LONG.new
.
415 416 417 |
# File 'lib/multiarray/int.rb', line 415 def LONG( value ) LONG.new value end |
.LONGRGB(value) ⇒ LONGRGB
Shortcut for constructor
The method calls LONGRGB.new
.
824 825 826 |
# File 'lib/multiarray/rgb.rb', line 824 def LONGRGB(value) LONGRGB.new value end |
.max(*shape) { ... } ⇒ Object, Node
Method for computing maximum of values
884 885 886 |
# File 'lib/multiarray.rb', line 884 def max(*shape, &action) inject *(shape + [proc { |a,b| a.major b }]), &action end |
.min(*shape) { ... } ⇒ Object, Node
Method for computing minimum of values
872 873 874 |
# File 'lib/multiarray.rb', line 872 def min(*shape, &action) inject *(shape + [proc { |a,b| a.minor b }]), &action end |
.MultiArray(typecode, dimension) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/multiarray/multiarray.rb', line 99 def MultiArray(typecode, dimension) if dimension > 0 Field_.inherit typecode.typecode, typecode.dimension + dimension else Hornetseye::Pointer typecode end end |
.OBJECT(value) ⇒ OBJECT
Shortcut for constructor
The method calls OBJECT.new
.
165 166 167 |
# File 'lib/multiarray/object.rb', line 165 def OBJECT( value ) OBJECT.new value end |
.Pointer(target) ⇒ Class
Create a class deriving from Pointer_
Create a class deriving from Pointer_
. The parameter target
is assigned to the corresponding attribute of the resulting class.
274 275 276 277 278 |
# File 'lib/multiarray/pointer.rb', line 274 def Pointer( target ) p = Class.new Pointer_ p.target = target p end |
.prod(*shape) { ... } ⇒ Object, Node
Method for computing product of values
860 861 862 |
# File 'lib/multiarray.rb', line 860 def prod(*shape, &action) inject *(shape + [proc { |a,b| a * b }]), &action end |
.RGB(element_type) ⇒ Class .RGB(r, g, b) ⇒ RGB
Create a class deriving from RGB_
or instantiate an RGB
object
697 698 699 700 701 702 703 |
# File 'lib/multiarray/rgb.rb', line 697 def RGB( arg, g = nil, b = nil ) if g.nil? and b.nil? RGB_.inherit arg else RGB.new arg, g, b end end |
.SCOMPLEX(value) ⇒ SCOMPLEX
Shortcut for constructor
The method calls SCOMPLEX.new
.
1085 1086 1087 |
# File 'lib/multiarray/complex.rb', line 1085 def SCOMPLEX(value) SCOMPLEX.new value end |
.Sequence(element_type) ⇒ Class
Create a class to represent one-dimensional uniform arrays
82 83 84 |
# File 'lib/multiarray/sequence.rb', line 82 def Sequence(element_type) Hornetseye::MultiArray element_type, 1 end |
.SFLOAT(value) ⇒ SFLOAT
Shortcut for constructor
The method calls SFLOAT.new
.
263 264 265 |
# File 'lib/multiarray/float.rb', line 263 def SFLOAT( value ) SFLOAT.new value end |
.SFLOATRGB(value) ⇒ SFLOATRGB
Shortcut for constructor
The method calls SFLOATRGB.new
.
850 851 852 |
# File 'lib/multiarray/rgb.rb', line 850 def SFLOATRGB(value) SFLOATRGB.new value end |
.SINT(value) ⇒ SINT
Shortcut for constructor
The method calls SINT.new
.
376 377 378 |
# File 'lib/multiarray/int.rb', line 376 def SINT( value ) SINT.new value end |
.SINTRGB(value) ⇒ SINTRGB
Shortcut for constructor
The method calls SINTRGB.new
.
772 773 774 |
# File 'lib/multiarray/rgb.rb', line 772 def SINTRGB(value) SINTRGB.new value end |
.sum(*shape) { ... } ⇒ Object, Node
Method for summing values
848 849 850 |
# File 'lib/multiarray.rb', line 848 def sum(*shape, &action) inject *(shape + [proc { |a,b| a + b }]), &action end |
.UBYTE(value) ⇒ UBYTE
Shortcut for constructor
The method calls UBYTE.new
.
363 364 365 |
# File 'lib/multiarray/int.rb', line 363 def UBYTE( value ) UBYTE.new value end |
.UBYTERGB(value) ⇒ UBYTERGB
Shortcut for constructor
The method calls UBYTERGB.new
.
759 760 761 |
# File 'lib/multiarray/rgb.rb', line 759 def UBYTERGB(value) UBYTERGB.new value end |
.UINT(value) ⇒ UINT
Shortcut for constructor
The method calls UINT.new
.
402 403 404 |
# File 'lib/multiarray/int.rb', line 402 def UINT( value ) UINT.new value end |
.UINTRGB(value) ⇒ UINTRGB
Shortcut for constructor
The method calls UINTRGB.new
.
811 812 813 |
# File 'lib/multiarray/rgb.rb', line 811 def UINTRGB(value) UINTRGB.new value end |
.ULONG(value) ⇒ ULONG
Shortcut for constructor
The method calls ULONG.new
.
428 429 430 |
# File 'lib/multiarray/int.rb', line 428 def ULONG( value ) ULONG.new value end |
.ULONGRGB(value) ⇒ ULONGRGB
Shortcut for constructor
The method calls ULONGRGB.new
.
837 838 839 |
# File 'lib/multiarray/rgb.rb', line 837 def ULONGRGB(value) ULONGRGB.new value end |