Class: CAClassIterator

Inherits:
CAIterator show all
Defined in:
lib/carray/iterator.rb

Overview

:nodoc:

Constant Summary collapse

UNIFORM_KERNEL =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CAIterator

#[], #[]=, #asign!, #ca, #calculate, #convert, define_calculate_method, define_evaluate_method, define_filter_method, #dim, #each, #each_with_addr, #each_with_index, #elements, #evaluate, #filter, #inject, #kernel_move_to_addr, #kernel_move_to_index, #ndim, #pick, #prepare_output, #put, #rank, #reference, #shape, #sort_by, #sort_by!, #sort_with, #to_a

Constructor Details

#initialize(reference, classifier = nil) ⇒ CAClassIterator

Returns a new instance of CAClassIterator.



317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/carray/iterator.rb', line 317

def initialize (reference, classifier = nil)
  @reference = reference
  @classifier = classifier || @reference.uniq.sort
  @null = CArray.new(@reference.data_type,[0])
  @table = {}
  @ndim = 1
  @dim  = [0]
  if @classifier.all_masked? or @classifier.size == 0
    @dim  = [0]
  else
#      @dim  = [@classifier.max+1]
    @dim  = [@classifier.size]
  end
end

Instance Attribute Details

#classifierObject (readonly)

Returns the value of attribute classifier.



332
333
334
# File 'lib/carray/iterator.rb', line 332

def classifier
  @classifier
end

#tableObject (readonly)

Returns the value of attribute table.



332
333
334
# File 'lib/carray/iterator.rb', line 332

def table
  @table
end

Instance Method Details

#__build__(&block) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/carray/iterator.rb', line 334

def __build__ (&block)
  if @block
    @classifier.each_with_addr do |v, i|
      @table[v] = block[v].where
    end
  else
    @classifier.each_with_addr do |v, i|
      @table[v] = @reference.eq(v).where
    end
  end
  return self
end

#kernel_at_addr(addr, ref = nil) ⇒ Object



354
355
356
357
358
359
360
361
# File 'lib/carray/iterator.rb', line 354

def kernel_at_addr (addr, ref = nil)
  ref ||= @reference
  if @table[addr]
    return ref[@table[addr]]
  else
    return @null
  end
end

#kernel_at_index(idx, ref = nil) ⇒ Object



363
364
365
# File 'lib/carray/iterator.rb', line 363

def kernel_at_index (idx, ref = nil)
  kernel_at_addr(idx[0], ref)
end

#ndiming(&block) ⇒ Object



347
348
349
350
351
352
# File 'lib/carray/iterator.rb', line 347

def ndiming (&block)
  block ||= lambda {|a| a.size }
  values = self.to_a.map{|v| block[v] }.to_ca
  addrs  = values.sort_addr.reverse
  return CArray.join([@classifier[addrs], values[addrs]])
end