Class: Hornetseye::Node
- Extended by:
- BOOL::Match, COMPLEX_::Match, FLOAT_::Match, INT_::Match, OBJECT::Match, RGB_::Match, Sequence_::Match
- Includes:
- Operations
- Defined in:
- lib/multiarray/node.rb,
lib/multiarray/operations.rb
Overview
Base class for representing native datatypes and operations (terms)
Direct Known Subclasses
Diagonal, Element, ElementWise_, Histogram, Inject, Integral, Lambda, Lookup, Lut, Pointer_, Store, Variable
Class Method Summary collapse
-
.===(other) ⇒ Boolean
Category operator.
-
.array_type ⇒ Class
Get type of result of delayed operation.
-
.basetype ⇒ Class
Base type of this data type.
-
.bool ⇒ Class
Get corresponding boolean-based datatype.
-
.byte ⇒ Class
Convert to type based on bytes.
-
.coercion_bool(other) ⇒ Class
Get boolean-based datatype for binary operation.
-
.coercion_byte(other) ⇒ Class
Get byte-based datatype for binary operation.
-
.coercion_maxint(other) ⇒ Class
Get maximum integer based datatype for binary operation.
-
.compilable? ⇒ Boolean
Check whether this term is compilable.
- .cond(a, b) ⇒ Object
-
.contiguous ⇒ Class
Get corresponding contiguous datatype.
-
.descriptor(hash) ⇒ String
Get unique descriptor of this class.
-
.dimension ⇒ Array<Integer>
Get dimension of this term.
-
.empty? ⇒ Boolean
Check whether the type is an empty array.
-
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations.
-
.float ⇒ Class
Convert to type based on floating point numbers.
-
.float_scalar ⇒ Class
Get corresponding type based on floating-point scalars.
-
.floating(other) ⇒ Class
Get floating point based datatype for binary operation.
- .height ⇒ Object
-
.indgen(offset = 0, increment = 1) ⇒ Object
Generate index array of this type.
-
.match(value, context = nil) ⇒ Class
Find matching native datatype to a Ruby value.
-
.maxint ⇒ Class
Get corresponding maximal integer type.
-
.pointer_type ⇒ Class
Convert to pointer type.
- .rgb? ⇒ Boolean
-
.scalar ⇒ Class
Get corresponding scalar type.
-
.shape ⇒ Array<Integer>
Get shape of this term.
-
.size ⇒ Integer
Get size (number of elements) of this value.
-
.strip ⇒ Array<Array,Node>
Strip of all values.
-
.subst(hash) ⇒ Node
Substitute variables.
-
.to_s ⇒ String
Get unique descriptor of this class.
-
.to_type(dest) ⇒ Class
Convert to different element type.
-
.typecode ⇒ Class
Element-type of this term.
-
.typecodes ⇒ Array<Class>
Get list of types of composite type.
-
.variables ⇒ Set
Get variables contained in this datatype.
- .width ⇒ Object
Instance Method Summary collapse
-
#[](*indices) ⇒ Object, Node
Retrieve value of array element(s).
-
#[]=(*indices, value) ⇒ Object, Node
Assign value to array element(s).
-
#array_type ⇒ Class
Get type of result of delayed operation.
- #basetype ⇒ Object
- #check_shape(*args) ⇒ Object
-
#coerce(other) ⇒ Array<Node>
Coerce with other object.
-
#compilable? ⇒ Boolean
Check whether this term is compilable.
-
#decompose(i) ⇒ Node
Decompose composite elements.
-
#demand ⇒ Node, Object
Reevaluate computation.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#dimension ⇒ Array<Integer>
Get dimension of this term.
-
#dup ⇒ Node
Duplicate object.
-
#empty? ⇒ Boolean
Check whether this object is an empty array.
-
#finalised? ⇒ Boolean
Check whether this object is a finalised computation.
-
#force ⇒ Node, Object
Force delayed computation unless in lazy mode.
-
#get ⇒ Node, Object
Extract native value if this is an element.
- #height ⇒ Object
-
#inspect(indent = nil, lines = nil) ⇒ String
Display information about this object.
- #memory ⇒ Object
-
#pointer_type ⇒ Class
Convert to pointer type.
- #rgb? ⇒ Boolean
-
#shape ⇒ Array<Integer>
Get shape of this term.
-
#simplify ⇒ Node, Object
Reevaluate term.
-
#size ⇒ Integer
Get size (number of elements) of this value.
- #storage_size ⇒ Object
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
-
#to_a ⇒ Array<Object>
Convert to Ruby array of objects.
-
#to_s ⇒ String
Get unique descriptor of this object.
-
#typecode ⇒ Class
Element-type of this term.
-
#variables ⇒ Set
Get variables contained in this object.
- #width ⇒ Object
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from Sequence_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
Methods included from Operations
#+@, #<=>, #b=, #b_with_decompose, #collect, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #eq_with_multiarray, #fill!, #g=, #g_with_decompose, #histogram, #imag=, #imag_with_decompose, #inject, #integral, #lut, #max, #min, #normalise, #product, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #roll, #sum, #to_type, #to_type_with_rgb, #transpose, #unroll
Class Method Details
.===(other) ⇒ Boolean
Category operator
266 267 268 |
# File 'lib/multiarray/node.rb', line 266 def ===( other ) ( other == self ) or ( other.is_a? self ) or ( other.class == self ) end |
.array_type ⇒ Class
Get type of result of delayed operation
92 93 94 |
# File 'lib/multiarray/node.rb', line 92 def array_type self end |
.basetype ⇒ Class
Base type of this data type
74 75 76 |
# File 'lib/multiarray/node.rb', line 74 def basetype self end |
.bool ⇒ Class
Get corresponding boolean-based datatype
165 166 167 |
# File 'lib/multiarray/node.rb', line 165 def bool BOOL end |
.byte ⇒ Class
Convert to type based on bytes
227 228 229 |
# File 'lib/multiarray/node.rb', line 227 def byte BYTE end |
.coercion_bool(other) ⇒ Class
Get boolean-based datatype for binary operation
186 187 188 |
# File 'lib/multiarray/node.rb', line 186 def coercion_bool( other ) other.coercion( self ).bool end |
.coercion_byte(other) ⇒ Class
Get byte-based datatype for binary operation
236 237 238 |
# File 'lib/multiarray/node.rb', line 236 def coercion_byte( other ) coercion( other ).byte end |
.coercion_maxint(other) ⇒ Class
Get maximum integer based datatype for binary operation
202 203 204 |
# File 'lib/multiarray/node.rb', line 202 def coercion_maxint( other ) coercion( other ).maxint end |
.compilable? ⇒ Boolean
Check whether this term is compilable
301 302 303 |
# File 'lib/multiarray/node.rb', line 301 def compilable? true end |
.cond(a, b) ⇒ Object
240 241 242 243 |
# File 'lib/multiarray/node.rb', line 240 def cond( a, b ) t = a.coercion b Hornetseye::MultiArray( t.typecode, *shape ).coercion t end |
.contiguous ⇒ Class
Get corresponding contiguous datatype
154 155 156 |
# File 'lib/multiarray/node.rb', line 154 def contiguous self end |
.descriptor(hash) ⇒ String
Get unique descriptor of this class
45 46 47 |
# File 'lib/multiarray/node.rb', line 45 def descriptor( hash ) 'Node' end |
.dimension ⇒ Array<Integer>
Get dimension of this term
145 146 147 |
# File 'lib/multiarray/node.rb', line 145 def dimension 0 end |
.empty? ⇒ Boolean
Check whether the type is an empty array
138 139 140 |
# File 'lib/multiarray/node.rb', line 138 def empty? size == 0 end |
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations
310 311 312 |
# File 'lib/multiarray/node.rb', line 310 def finalised? true end |
.float ⇒ Class
Convert to type based on floating point numbers
211 212 213 |
# File 'lib/multiarray/node.rb', line 211 def float DFLOAT end |
.float_scalar ⇒ Class
Get corresponding type based on floating-point scalars
179 180 181 |
# File 'lib/multiarray/node.rb', line 179 def float_scalar float.scalar end |
.floating(other) ⇒ Class
Get floating point based datatype for binary operation
218 219 220 |
# File 'lib/multiarray/node.rb', line 218 def floating( other ) other.coercion( self ).float end |
.height ⇒ Object
124 125 126 |
# File 'lib/multiarray/node.rb', line 124 def height shape[1] end |
.indgen(offset = 0, increment = 1) ⇒ Object
Generate index array of this type
109 110 111 |
# File 'lib/multiarray/node.rb', line 109 def indgen( offset = 0, increment = 1 ) offset end |
.match(value, context = nil) ⇒ Class
Find matching native datatype to a Ruby value
56 57 58 59 60 |
# File 'lib/multiarray/node.rb', line 56 def match( value, context = nil ) retval = fit value retval = retval.align context.basetype if context retval end |
.maxint ⇒ Class
Get corresponding maximal integer type
195 196 197 |
# File 'lib/multiarray/node.rb', line 195 def maxint self end |
.pointer_type ⇒ Class
Convert to pointer type
99 100 101 |
# File 'lib/multiarray/node.rb', line 99 def pointer_type Hornetseye::Pointer( self ) end |
.rgb? ⇒ Boolean
158 159 160 |
# File 'lib/multiarray/node.rb', line 158 def rgb? false end |
.scalar ⇒ Class
Get corresponding scalar type
172 173 174 |
# File 'lib/multiarray/node.rb', line 172 def scalar self end |
.shape ⇒ Array<Integer>
Get shape of this term
116 117 118 |
# File 'lib/multiarray/node.rb', line 116 def shape [] end |
.size ⇒ Integer
Get size (number of elements) of this value
131 132 133 |
# File 'lib/multiarray/node.rb', line 131 def size 1 end |
.strip ⇒ Array<Array,Node>
Strip of all values
Split up into variables, values, and a term where all values have been replaced with variables.
values, and the term based on variables.
279 280 281 |
# File 'lib/multiarray/node.rb', line 279 def strip return [], [], self end |
.subst(hash) ⇒ Node
Substitute variables
Substitute the variables with the values given in the hash.
292 293 294 |
# File 'lib/multiarray/node.rb', line 292 def subst( hash ) hash[ self ] || self end |
.to_s ⇒ String
Get unique descriptor of this class
The method calls descriptor( {} ).
34 35 36 |
# File 'lib/multiarray/node.rb', line 34 def to_s descriptor( {} ) end |
.to_type(dest) ⇒ Class
Convert to different element type
250 251 252 |
# File 'lib/multiarray/node.rb', line 250 def to_type( dest ) dest end |
.typecode ⇒ Class
Element-type of this term
65 66 67 |
# File 'lib/multiarray/node.rb', line 65 def typecode self end |
.typecodes ⇒ Array<Class>
Get list of types of composite type
83 84 85 |
# File 'lib/multiarray/node.rb', line 83 def typecodes [ self ] end |
.variables ⇒ Set
Get variables contained in this datatype
259 260 261 |
# File 'lib/multiarray/node.rb', line 259 def variables Set[] end |
.width ⇒ Object
120 121 122 |
# File 'lib/multiarray/node.rb', line 120 def width shape[0] end |
Instance Method Details
#[](*indices) ⇒ Object, Node
Retrieve value of array element(s)
543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/multiarray/node.rb', line 543 def []( *indices ) if indices.empty? force else if indices.last.is_a? Range view = slice indices.last.min, indices.last.size else view = element indices.last end view[ *indices[ 0 ... -1 ] ] end end |
#[]=(*indices, value) ⇒ Object, Node
Assign value to array element(s)
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/multiarray/node.rb', line 579 def []=( *indices ) value = indices.pop value = Node.match( value ).new value unless value.is_a? Node if indices.empty? check_shape value unless compilable? and value.compilable? and dimension > 0 Store.new( self, value ).demand else GCCFunction.run Store.new( self, value ) end value else if indices.last.is_a? Range view = slice indices.last.min, indices.last.size else view = element indices.last end view[ *indices[ 0 ... -1 ] ] = value end end |
#array_type ⇒ Class
Get type of result of delayed operation
321 322 323 |
# File 'lib/multiarray/node.rb', line 321 def array_type self.class.array_type end |
#basetype ⇒ Object
339 340 341 |
# File 'lib/multiarray/node.rb', line 339 def basetype array_type.basetype end |
#check_shape(*args) ⇒ Object
556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/multiarray/node.rb', line 556 def check_shape( *args ) args.each do |arg| if dimension < arg.dimension raise "#{arg.array_type.inspect} has #{arg.dimension} dimension(s) " + "but should not have more than #{dimension}" end if ( shape + arg.shape ).all? { |s| s.is_a? Integer } if shape.last( arg.dimension ) != arg.shape raise "#{arg.array_type.inspect} has shape #{arg.shape.inspect} " + "(does not match last value(s) of #{shape.inspect})" end end end end |
#coerce(other) ⇒ Array<Node>
Coerce with other object
672 673 674 675 676 677 678 |
# File 'lib/multiarray/node.rb', line 672 def coerce( other ) if other.is_a? Node return other, self else return Node.match( other, self ).new( other ), self end end |
#compilable? ⇒ Boolean
Check whether this term is compilable
525 526 527 |
# File 'lib/multiarray/node.rb', line 525 def compilable? typecode.compilable? end |
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
685 686 687 |
# File 'lib/multiarray/node.rb', line 685 def decompose( i ) self end |
#demand ⇒ Node, Object
Reevaluate computation
629 630 631 |
# File 'lib/multiarray/node.rb', line 629 def demand self end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
494 495 496 |
# File 'lib/multiarray/node.rb', line 494 def descriptor( hash ) 'Node()' end |
#dimension ⇒ Array<Integer>
Get dimension of this term
383 384 385 |
# File 'lib/multiarray/node.rb', line 383 def dimension array_type.dimension end |
#dup ⇒ Node
Duplicate object
501 502 503 504 505 |
# File 'lib/multiarray/node.rb', line 501 def dup retval = array_type.new retval[] = self retval end |
#empty? ⇒ Boolean
Check whether this object is an empty array.
376 377 378 |
# File 'lib/multiarray/node.rb', line 376 def empty? array_type.empty? end |
#finalised? ⇒ Boolean
Check whether this object is a finalised computation
534 535 536 |
# File 'lib/multiarray/node.rb', line 534 def finalised? self.class.finalised? end |
#force ⇒ Node, Object
Force delayed computation unless in lazy mode
640 641 642 643 644 645 646 647 648 649 650 651 652 |
# File 'lib/multiarray/node.rb', line 640 def force if ( dimension > 0 and Thread.current[ :lazy ] ) or not variables.empty? self elsif finalised? get elsif compilable? retval = pointer_type.new GCCFunction.run Store.new( retval, self ) retval.demand.get else Store.new( array_type.new, self ).demand.get end end |
#get ⇒ Node, Object
Extract native value if this is an element
396 397 398 |
# File 'lib/multiarray/node.rb', line 396 def get self end |
#height ⇒ Object
354 355 356 |
# File 'lib/multiarray/node.rb', line 354 def height array_type.height end |
#inspect(indent = nil, lines = nil) ⇒ String
Display information about this object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/multiarray/node.rb', line 418 def inspect( indent = nil, lines = nil ) if variables.empty? if dimension == 0 and not indent "#{array_type.inspect}(#{force.inspect})" # !!! else if indent prepend = '' else prepend = "#{array_type.inspect}:\n" indent = 0 lines = 0 end if empty? retval = '[]' else retval = '[ ' for i in 0 ... array_type.num_elements x = element i if x.dimension > 0 if i > 0 retval += ",\n " lines += 1 if lines >= 10 retval += '...' if indent == 0 break end retval += ' ' * indent end str = x.inspect indent + 1, lines lines += str.count "\n" retval += str if lines >= 10 retval += '...' if indent == 0 break end else retval += ', ' if i > 0 str = x.force.inspect # !!! if retval.size + str.size >= 74 - '...'.size - '[ ]'.size * indent.succ retval += '...' break else retval += str end end end retval += ' ]' unless lines >= 10 end prepend + retval end else to_s end end |
#memory ⇒ Object
369 370 371 |
# File 'lib/multiarray/node.rb', line 369 def memory nil end |
#pointer_type ⇒ Class
Convert to pointer type
328 329 330 |
# File 'lib/multiarray/node.rb', line 328 def pointer_type array_type.pointer_type end |
#rgb? ⇒ Boolean
387 388 389 |
# File 'lib/multiarray/node.rb', line 387 def rgb? array_type.rgb? end |
#shape ⇒ Array<Integer>
Get shape of this term
346 347 348 |
# File 'lib/multiarray/node.rb', line 346 def shape array_type.shape end |
#simplify ⇒ Node, Object
Reevaluate term
661 662 663 |
# File 'lib/multiarray/node.rb', line 661 def simplify dimension == 0 ? demand.dup : demand end |
#size ⇒ Integer
Get size (number of elements) of this value
361 362 363 |
# File 'lib/multiarray/node.rb', line 361 def size array_type.size end |
#storage_size ⇒ Object
365 366 367 |
# File 'lib/multiarray/node.rb', line 365 def storage_size array_type.storage_size end |
#strip ⇒ Array<Array,Node>
Strip of all values
Split up into variables, values, and a term where all values have been replaced with variables.
values, and the term based on variables.
618 619 620 |
# File 'lib/multiarray/node.rb', line 618 def strip return [], [], self end |
#subst(hash) ⇒ Node
Substitute variables
Substitute the variables with the values given in the hash.
516 517 518 |
# File 'lib/multiarray/node.rb', line 516 def subst( hash ) hash[ self ] || self end |
#to_a ⇒ Array<Object>
Convert to Ruby array of objects
Perform pending computations and convert native array to Ruby array of objects.
406 407 408 409 410 411 412 413 |
# File 'lib/multiarray/node.rb', line 406 def to_a if dimension == 0 force else n = shape.last ( 0 ... n ).collect { |i| element( i ).to_a } end end |
#to_s ⇒ String
Get unique descriptor of this object
The method calls descriptor( {} ).
483 484 485 |
# File 'lib/multiarray/node.rb', line 483 def to_s descriptor( {} ) end |
#typecode ⇒ Class
Element-type of this term
335 336 337 |
# File 'lib/multiarray/node.rb', line 335 def typecode array_type.typecode end |
#variables ⇒ Set
Get variables contained in this object
605 606 607 |
# File 'lib/multiarray/node.rb', line 605 def variables Set[] end |
#width ⇒ Object
350 351 352 |
# File 'lib/multiarray/node.rb', line 350 def width array_type.width end |