Class: Hornetseye::Sequence_

Inherits:
Object
  • Object
show all
Defined in:
lib/multiarray/sequence.rb

Overview

Class for representing n-dimensional native arrays

Defined Under Namespace

Modules: Match

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.element_typeClass

Type of array elements

Returns:

  • (Class)

    element_type Type of array elements.



76
77
78
# File 'lib/multiarray/sequence.rb', line 76

def element_type
  @element_type
end

.num_elementsInteger

Number of array elements

Returns:

  • (Integer)

    num_elements Number of elements.



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

def num_elements
  @num_elements
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.



282
283
284
285
286
# File 'lib/multiarray/sequence.rb', line 282

def ==( other )
  other.is_a? Class and other < Sequence_ and
    other.element_type == element_type and
    other.num_elements == num_elements
end

.[](*args) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/multiarray/sequence.rb', line 105

def []( *args )
  retval = new
  recursion = lambda do |element,args|
    if element.dimension > 0
      args.each_with_index do |arg,i|
        recursion.call element.element( i ), arg
      end
    else
      element[] = args
    end
  end
  recursion.call retval, args
  retval
end

.array_typeClass

Get type of result of delayed operation

Returns:

  • (Class)

    Type of result.



162
163
164
# File 'lib/multiarray/sequence.rb', line 162

def array_type
  self
end

.basetypeClass

Base type of this data type

Returns:

  • (Class)

    Returns element_type.



153
154
155
# File 'lib/multiarray/sequence.rb', line 153

def basetype
  element_type.basetype
end

.boolObject



182
183
184
# File 'lib/multiarray/sequence.rb', line 182

def bool
  Hornetseye::Sequence element_type.bool, num_elements
end

.byteObject



212
213
214
# File 'lib/multiarray/sequence.rb', line 212

def byte
  Hornetseye::Sequence element_type.byte, num_elements
end

.coerce(other) ⇒ Array<Class>

Compute balanced type for binary operation

Parameters:

  • other (Class)

    Other type to coerce with.

Returns:

  • (Array<Class>)

    Result of coercion.



312
313
314
315
316
317
318
# File 'lib/multiarray/sequence.rb', line 312

def coerce( other )
  if other < Sequence_
    return other, self
  else
    return Hornetseye::Sequence( other, num_elements ), self
  end
end

.coercion(other) ⇒ Class

Type coercion for native elements

Parameters:

  • other (Class)

    Other native datatype to coerce with.

Returns:

  • (Class)

    Result of coercion.



295
296
297
298
299
300
301
302
303
# File 'lib/multiarray/sequence.rb', line 295

def coercion( other )
  if other < Sequence_
    Hornetseye::Sequence element_type.coercion( other.element_type ),
                         num_elements
  else
    Hornetseye::Sequence element_type.coercion( other ),
                         num_elements
  end
end

.coercion_bool(other) ⇒ Object



186
187
188
# File 'lib/multiarray/sequence.rb', line 186

def coercion_bool( other )
  coercion( other ).bool
end

.coercion_byte(other) ⇒ Object



216
217
218
# File 'lib/multiarray/sequence.rb', line 216

def coercion_byte( other )
  coercion( other ).byte
end

.coercion_maxint(other) ⇒ Object



208
209
210
# File 'lib/multiarray/sequence.rb', line 208

def coercion_maxint( other )
  coercion( other ).maxint
end

.compilable?Boolean

Returns:

  • (Boolean)


324
325
326
# File 'lib/multiarray/sequence.rb', line 324

def compilable?
  element_type.compilable?
end

.cond(a, b) ⇒ Object



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

def cond( a, b )
  t = a.coercion b
  Hornetseye::MultiArray( t.typecode, *shape ).coercion t
end

.contiguousObject



178
179
180
# File 'lib/multiarray/sequence.rb', line 178

def contiguous
  self
end

.defaultObject

Get default value for elements of this type

Returns:

  • (Object)

    Returns an array of default values.



88
89
90
91
92
93
94
95
96
# File 'lib/multiarray/sequence.rb', line 88

def default
  Hornetseye::lazy( num_elements ) do |i|
    if element_type.dimension > 0
      element = element_type.default
    else
      element = element_type.new
    end
  end
end

.descriptor(hash) ⇒ String

Get unique descriptor of this class

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this class.



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/multiarray/sequence.rb', line 265

def descriptor( hash )
  if element_type and num_elements
    if dimension == 1
      "Sequence(#{typecode.descriptor( hash )},#{num_elements.to_s})"
    else
      "MultiArray(#{typecode.descriptor( hash )},#{shape.join ','})"
    end
  else
    'MultiArray(?,?)'
  end
end

.dimensionObject



170
171
172
# File 'lib/multiarray/sequence.rb', line 170

def dimension
  element_type.dimension + 1
end

.empty?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/multiarray/sequence.rb', line 140

def empty?
  size == 0
end

.floatClass

Convert to type based on floating point numbers

Returns:

  • (Class)

    Corresponding type based on floating point numbers.



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

def float
  Hornetseye::Sequence element_type.float, num_elements
end

.float_scalarObject



197
198
199
# File 'lib/multiarray/sequence.rb', line 197

def float_scalar
  Hornetseye::Sequence element_type.float_scalar, num_elements
end

.floating(other) ⇒ Object



229
230
231
# File 'lib/multiarray/sequence.rb', line 229

def floating( other )
  coercion( other ).float
end

.heightObject



128
129
130
# File 'lib/multiarray/sequence.rb', line 128

def height
  shape[1]
end

.indgen(offset = 0, increment = 1) ⇒ Object



98
99
100
101
102
103
# File 'lib/multiarray/sequence.rb', line 98

def indgen( offset = 0, increment = 1 )
  Hornetseye::lazy( num_elements ) do |i|
    ( element_type.size * increment * i +
      element_type.indgen( offset, increment ) ).to_type typecode
  end
end

.inspectObject



242
243
244
245
246
247
248
249
250
251
252
# File 'lib/multiarray/sequence.rb', line 242

def inspect
  if element_type and num_elements
    if dimension == 1
      "Sequence(#{typecode.inspect},#{num_elements.inspect})"
    else
      "MultiArray(#{typecode.inspect},#{shape.join ','})"
    end
  else
    'MultiArray(?,?)'
  end
end

.maxintClass

Get corresponding maximum integer type

Returns:

  • (Class)

    Returns type based on maximum integers.



204
205
206
# File 'lib/multiarray/sequence.rb', line 204

def maxint
  Hornetseye::Sequence element_type.maxint, num_elements
end

.new(memory = nil) ⇒ Object



320
321
322
# File 'lib/multiarray/sequence.rb', line 320

def new( memory = nil )
  MultiArray.new typecode, *( shape + [ :memory => memory ] )
end

.pointer_typeObject



166
167
168
# File 'lib/multiarray/sequence.rb', line 166

def pointer_type
  self
end

.rgb?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/multiarray/sequence.rb', line 174

def rgb?
  element_type.rgb?
end

.scalarClass

Get corresponding scalar type

Returns:

  • (Class)

    Returns type for array of scalars.



193
194
195
# File 'lib/multiarray/sequence.rb', line 193

def scalar
  Hornetseye::Sequence element_type.scalar, num_elements
end

.shapeObject



120
121
122
# File 'lib/multiarray/sequence.rb', line 120

def shape
  element_type.shape + [ num_elements ]
end

.sizeObject



132
133
134
# File 'lib/multiarray/sequence.rb', line 132

def size
  num_elements * element_type.size
end

.storage_sizeObject



136
137
138
# File 'lib/multiarray/sequence.rb', line 136

def storage_size
  num_elements * element_type.storage_size
end

.to_sObject



254
255
256
# File 'lib/multiarray/sequence.rb', line 254

def to_s
  descriptor( {} )
end

.to_type(dest) ⇒ Object



238
239
240
# File 'lib/multiarray/sequence.rb', line 238

def to_type( dest )
  Hornetseye::Sequence element_type.to_type( dest ), num_elements
end

.typecodeObject



144
145
146
# File 'lib/multiarray/sequence.rb', line 144

def typecode
  element_type.typecode
end

.widthObject



124
125
126
# File 'lib/multiarray/sequence.rb', line 124

def width
  shape[0]
end