Class: Hornetseye::Pointer_

Inherits:
Node show all
Defined in:
lib/multiarray/pointer.rb

Overview

Class for representing native pointer types

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#+@, #<=>, ===, #[], #[]=, #allocate, #b=, #b_with_decompose, #basetype, #between?, bool, byte, #check_shape, #clip, #coerce, coercion_bool, coercion_byte, coercion_maxint, #collect, #compilable?, compilable?, #components, cond, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #dilate, #dimension, dimension, #downsample, #dup, #each, #empty?, #eq_with_multiarray, #erode, #fill!, #finalised?, #flip, float, float_scalar, floating, #fmod_with_float, #force, #g=, #g_with_decompose, #gauss_blur, #gauss_gradient, #get, #height, #histogram, #histogram_with_rgb, identity, #if, #if_else, #imag=, #imag_with_decompose, indgen, #inject, #inspect, #integral, #lut, #lut_with_rgb, #malloc, #mask, match, #matched?, #max, maxint, #mean, #memorise, #min, #normalise, #prod, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, #shape, shape, #shift, #simplify, #size, #sobel, #stretch, #stride, strip, #subst, subst, #sum, #swap_rgb_with_scalar, #table, #to_a, #to_s, to_s, #to_type, to_type, #to_type_with_identity, #to_type_with_rgb, #transpose, #typecode, typecodes, #unmask, #unroll, #variables, variables, #warp, #width

Methods included from Field_::Match

#align, #fit

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

Constructor Details

#initialize(value = self.class.default) ⇒ Pointer_

Constructor for pointer object

Parameters:

  • value (Malloc, List) (defaults to: self.class.default)

    Initial value for pointer object.



126
127
128
# File 'lib/multiarray/pointer.rb', line 126

def initialize( value = self.class.default )
  @value = value
end

Class Attribute Details

.targetNode

Target type of pointer

Returns:

  • (Node)

    Type of object the pointer is pointing at.



28
29
30
# File 'lib/multiarray/pointer.rb', line 28

def target
  @target
end

Class Method Details

.==(other) ⇒ Boolean

Test equality of classes

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Boolean indicating whether classes are equal.



71
72
73
74
# File 'lib/multiarray/pointer.rb', line 71

def ==( other )
  other.is_a? Class and other < Pointer_ and
    target == other.target
end

.basetypeClass

Base type of this data type

Returns:

  • (Class)

    Returns element_type.



108
109
110
# File 'lib/multiarray/pointer.rb', line 108

def basetype
  target.basetype
end

.construct(*args) ⇒ Element

Construct new object from arguments

Parameters:

Returns:

  • (Element)

    New object of this type.



37
38
39
# File 'lib/multiarray/pointer.rb', line 37

def construct( *args )
  new *args
end

.defaultMemory, List

Get default value for elements of this type

Returns:

  • (Memory, List)

    Memory for storing one object of type target.



62
63
64
# File 'lib/multiarray/pointer.rb', line 62

def default
  target.memory_type.new target.storage_size
end

.descriptor(hash) ⇒ String

Get unique descriptor of this class

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this class.



55
56
57
# File 'lib/multiarray/pointer.rb', line 55

def descriptor( hash )
  inspect
end

.eql?Boolean

Equality for hash operations

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Returns true if objects are equal.



92
93
94
# File 'lib/multiarray/pointer.rb', line 92

def eql?
  self == other
end

.finalised?Boolean

Check whether objects of this class are finalised computations

Returns:

  • (Boolean)

    Returns false.



117
118
119
# File 'lib/multiarray/pointer.rb', line 117

def finalised?
  false
end

.hashFixnum

Compute hash value for this class

Returns:



81
82
83
# File 'lib/multiarray/pointer.rb', line 81

def hash
  [ :Pointer_, target ].hash
end

.inspectString

Display string with information about this class

Returns:

  • (String)

    String with information about this class (e.g. ‘*(UBYTE)’).



44
45
46
# File 'lib/multiarray/pointer.rb', line 44

def inspect
  "*(#{target.inspect})"
end

.typecodeClass

Get element type

Returns:

  • (Class)

    Returns the corresponding element type.



99
100
101
# File 'lib/multiarray/pointer.rb', line 99

def typecode
  target
end

Instance Method Details

#assign(value) ⇒ Object

Store a value in this native element

Parameters:

  • value (Object)

    New value for native element.

Returns:



178
179
180
181
182
183
184
185
# File 'lib/multiarray/pointer.rb', line 178

def assign( value )
  if @value.respond_to? :assign
    @value.assign value.simplify.get
  else
    @value = value.simplify.get
  end
  value
end

#decompose(i) ⇒ Node

Decompose composite elements

This method decomposes composite elements into array.

Returns:

  • (Node)

    Result of decomposition.



243
244
245
246
247
248
249
250
# File 'lib/multiarray/pointer.rb', line 243

def decompose( i )
  if self.class.target < Composite
    pointer = Hornetseye::Pointer( self.class.target.element_type ).new @value
    pointer.lookup INT.new( i ), INT.new( 1 )
  else
    super
  end
end

#demandNode, Object

Reevaluate computation

Returns:

See Also:



207
208
209
# File 'lib/multiarray/pointer.rb', line 207

def demand
  self.class.target.fetch(@value).simplify
end

#descriptor(hash) ⇒ String

Get unique descriptor of this object

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this object,



167
168
169
# File 'lib/multiarray/pointer.rb', line 167

def descriptor( hash )
  "#{self.class.to_s}(#{@value.to_s})"
end

#lookup(value, stride) ⇒ Object

Lookup element of an array

Parameters:

  • value (Node)

    Index of element.

  • stride (Node)

    Stride for iterating over elements.



217
218
219
220
221
222
223
224
# File 'lib/multiarray/pointer.rb', line 217

def lookup( value, stride )
  if value.is_a? Variable
    Lookup.new self, value, stride
  else
    self.class.new @value + ( stride.get *
                              self.class.target.storage_size ) * value.get
  end
end

#memoryMalloc, List

Get access to storage object

Returns:

  • (Malloc, List)

    The object used to store the data.



133
134
135
# File 'lib/multiarray/pointer.rb', line 133

def memory
  @value
end

#skip(index, start) ⇒ Node

Skip elements of an array

Parameters:

  • index (Variable)

    Variable identifying index of array.

  • start (Node)

    Wrapped integer with number of elements to skip.

Returns:

  • (Node)

    Lookup object with elements skipped.



234
235
236
# File 'lib/multiarray/pointer.rb', line 234

def skip( index, start )
  self
end

#store(value) ⇒ Object

Store new value in this pointer

Parameters:

  • value (Object)

    New value for this pointer object.

Returns:



194
195
196
197
198
# File 'lib/multiarray/pointer.rb', line 194

def store( value )
  result = value.simplify
  self.class.target.new(result.get).write @value
  result
end

#stridesArray<Integer>, NilClass

Get strides of array

Returns:



142
143
144
# File 'lib/multiarray/pointer.rb', line 142

def strides
  []
end

#stripArray<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.

Returns:



155
156
157
158
# File 'lib/multiarray/pointer.rb', line 155

def strip
  variable = Variable.new self.class
  return [ variable ], [ self ], variable
end

#valuesArray<Object>

Get array with components of this value

Returns:

  • (Array<Object>)

    Get array with value of this object as single element.



257
258
259
# File 'lib/multiarray/pointer.rb', line 257

def values
  [ @value ]
end