Class: Hornetseye::Pointer_

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

===, #[], #[]=, #array_type, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, #compilable?, compilable?, cond, contiguous, dimension, #dimension, #dup, empty?, #empty?, #finalised?, float, float_scalar, floating, #force, #get, #height, height, indgen, #inspect, match, maxint, #pointer_type, rgb?, #rgb?, scalar, shape, #shape, #simplify, #size, size, #storage_size, strip, subst, #subst, #to_a, to_s, #to_s, to_type, #typecode, typecodes, variables, #variables, #width, width

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from Sequence_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

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

Constructor Details

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

Returns a new instance of Pointer_.



137
138
139
# File 'lib/multiarray/pointer.rb', line 137

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.



26
27
28
# File 'lib/multiarray/pointer.rb', line 26

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.



69
70
71
72
# File 'lib/multiarray/pointer.rb', line 69

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

.array_typeClass

Get type of result of delayed operation

Returns:

  • (Class)

    Type of result.



115
116
117
# File 'lib/multiarray/pointer.rb', line 115

def array_type
  target
end

.basetypeClass

Base type of this data type

Returns:

  • (Class)

    Returns element_type.



106
107
108
# File 'lib/multiarray/pointer.rb', line 106

def basetype
  target.basetype
end

.construct(*args) ⇒ Element

Construct new object from arguments

Parameters:

Returns:

  • (Element)

    New object of this type.



35
36
37
# File 'lib/multiarray/pointer.rb', line 35

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.



60
61
62
# File 'lib/multiarray/pointer.rb', line 60

def default
  target.memory.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.



53
54
55
# File 'lib/multiarray/pointer.rb', line 53

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.



90
91
92
# File 'lib/multiarray/pointer.rb', line 90

def eql?
  self == other
end

.finalised?Boolean

Check whether objects of this class are finalised computations

Returns:

  • (Boolean)

    Returns false.



131
132
133
# File 'lib/multiarray/pointer.rb', line 131

def finalised?
  false
end

.hashFixnum

Compute hash value for this class.

Returns:



79
80
81
# File 'lib/multiarray/pointer.rb', line 79

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)’).



42
43
44
# File 'lib/multiarray/pointer.rb', line 42

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

.pointer_typeClass

Get corresponding pointer type

Returns:

  • (Class)

    Returns self.



122
123
124
# File 'lib/multiarray/pointer.rb', line 122

def pointer_type
  self
end

.typecodeClass

Get element type

Returns:

  • (Class)

    Returns the corresponding element type.



97
98
99
# File 'lib/multiarray/pointer.rb', line 97

def typecode
  target
end

Instance Method Details

#decompose(i) ⇒ Node

Decompose composite elements

This method decomposes composite elements into array.

Returns:

  • (Node)

    Result of decomposition.



211
212
213
214
215
216
217
218
# File 'lib/multiarray/pointer.rb', line 211

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:



183
184
185
# File 'lib/multiarray/pointer.rb', line 183

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

#descriptor(hash) ⇒ Object



159
160
161
# File 'lib/multiarray/pointer.rb', line 159

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.



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

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

#memoryObject



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

def memory
  @value
end

#skip(index, start) ⇒ Object



202
203
204
# File 'lib/multiarray/pointer.rb', line 202

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:



170
171
172
173
174
# File 'lib/multiarray/pointer.rb', line 170

def store( value )
  result = value.simplify
  self.class.target.new( result.get ).write @value
  result
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:



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

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.



225
226
227
# File 'lib/multiarray/pointer.rb', line 225

def values
  [ @value ]
end