Module: Hornetseye
- Extended by:
- MultiArrayConstructor
- Defined in:
- lib/multiarray.rb,
lib/multiarray/rgb.rb,
lib/multiarray/rgb.rb,
lib/multiarray/lut.rb,
lib/multiarray/int.rb,
lib/multiarray/node.rb,
lib/multiarray/bool.rb,
lib/multiarray/mask.rb,
lib/multiarray/list.rb,
lib/multiarray/store.rb,
lib/multiarray/index.rb,
lib/multiarray/float.rb,
lib/multiarray/field.rb,
lib/multiarray/lookup.rb,
lib/multiarray/random.rb,
lib/multiarray/malloc.rb,
lib/multiarray/object.rb,
lib/multiarray/lambda.rb,
lib/multiarray/unmask.rb,
lib/multiarray/inject.rb,
lib/multiarray/pointer.rb,
lib/multiarray/element.rb,
lib/multiarray/methods.rb,
lib/multiarray/gcctype.rb,
lib/multiarray/complex.rb,
lib/multiarray/complex.rb,
lib/multiarray/variable.rb,
lib/multiarray/gccvalue.rb,
lib/multiarray/argument.rb,
lib/multiarray/sequence.rb,
lib/multiarray/integral.rb,
lib/multiarray/diagonal.rb,
lib/multiarray/gcccache.rb,
lib/multiarray/composite.rb,
lib/multiarray/histogram.rb,
lib/multiarray/shortcuts.rb,
lib/multiarray/operations.rb,
lib/multiarray/multiarray.rb,
lib/multiarray/components.rb,
lib/multiarray/gcccontext.rb,
lib/multiarray/gccfunction.rb,
lib/multiarray/elementwise.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_, GCCFunction, Histogram, INDEX_, INT_, Inject, Integral, Lambda, List, Lookup, Lut, Malloc, Mask, MultiArray, Node, OBJECT, Pointer_, RGB, RGB_, Random, Sequence, Store, Unmask
Constant Summary
- 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
- 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
Class Method Summary (collapse)
- + (Object) argmax(&action)
- + (Object) argmin(&action)
- + (Object) argument(block, options = {}, &action)
-
+ (Class) COMPLEX(element_type)
Create a class deriving from COMPLEX_.
-
+ (Object, Node) finalise(*shape) { ... }
Method for performing a lazy computation and then forcing the result.
-
+ (Class) FLOAT(double)
Create a class deriving from FLOAT_.
-
+ (Class) INDEX(size)
Instantiate the type of an array index.
-
+ (Class, INT) INT(arg, signed = nil)
Create a class deriving from INT_ or instantiate an INT object Create a class deriving from INT_.
-
+ (Object, Node) lazy(*shape) { ... }
Method for performing computations in lazy mode resulting in a lazy expression.
-
+ (Object, Node) max(*shape) { ... }
Method for computing maximum of values.
-
+ (Object, Node) min(*shape) { ... }
Method for computing minimum of values.
- + (Object) MultiArray(typecode, dimension)
-
+ (OBJECT) OBJECT(value)
Shortcut for constructor.
-
+ (Class) Pointer(target)
Create a class deriving from Pointer_.
-
+ (Object, Node) prod(*shape) { ... }
Method for computing product of values.
-
+ (Class, RGB) RGB(arg, g = nil, b = nil)
Create a class deriving from RGB_ or instantiate an RGB object Create a class deriving from RGB_.
-
+ (Class) Sequence(element_type)
Create a class to represent one-dimensional uniform arrays.
-
+ (Object, Node) sum(*shape) { ... }
Method for summing values.
Class Method Details
+ (Object) argmax(&action)
926 927 928 |
# File 'lib/multiarray.rb', line 926 def argmax(&action) argument proc { |a,b| a > b }, &action end |
+ (Object) argmin(&action)
932 933 934 |
# File 'lib/multiarray.rb', line 932 def argmin(&action) argument proc { |a,b| a < b }, &action end |
+ (Object) argument(block, options = {}, &action)
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 |
+ (Class) COMPLEX(element_type)
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 |
+ (Object, Node) finalise(*shape) { ... }
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 |
+ (Class) FLOAT(double)
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 |
+ (Class) INDEX(size)
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 |
+ (Class, INT) INT(bits, signed) + (Class, INT) INT(value)
Create a class deriving from INT_ or instantiate an INT object Create a class deriving from INT_. The parameters bits and signed
are assigned to the corresponding attributes of the resulting class.
@param [Integer] bits Number of bits of native integer.
@param [Boolean] signed Specify +UNSIGNED+ or +SIGNED+ here.
@return [Class] A class deriving from +INT_+.
This is a shortcut for INT.new( value ).
@param [Integer] value Initial value for integer object.
@return [INT] Wrapped integer value.
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 |
+ (Object, Node) lazy(*shape) { ... }
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 |
+ (Object, Node) max(*shape) { ... }
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 |
+ (Object, Node) min(*shape) { ... }
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 |
+ (Object) MultiArray(typecode, dimension)
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) OBJECT(value)
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 |
+ (Class) Pointer(target)
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 |
+ (Object, Node) prod(*shape) { ... }
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 |
+ (Class, RGB) RGB(element_type) + (Class, RGB) RGB(r, g, b)
Create a class deriving from RGB_ or instantiate an RGB object Create a class deriving from RGB_. The parameters element_type is
assigned to the corresponding attribute of the resulting class.
@param [Class] element_type Element type of native RGB value.
@return [Class] A class deriving from +RGB_+.
This is a shortcut for RGB.new( r, g, b ).
@param [Object] r Initial value for red channel.
@param [Object] g Initial value for green channel.
@param [Object] b Initial value for blue channel.
@return [RGB] The RGB value.
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 |
+ (Class) Sequence(element_type)
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 |