Class: CAClassIterator
- Inherits:
-
CAIterator
- Object
- CAIterator
- CAClassIterator
- Defined in:
- lib/carray/base/iterator.rb
Overview
:nodoc:
Constant Summary collapse
- UNIFORM_KERNEL =
false
Instance Attribute Summary collapse
-
#classifier ⇒ Object
readonly
Returns the value of attribute classifier.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #__build__(&block) ⇒ Object
-
#initialize(reference, classifier = nil) ⇒ CAClassIterator
constructor
A new instance of CAClassIterator.
- #kernel_at_addr(addr, ref = nil) ⇒ Object
- #kernel_at_index(idx, ref = nil) ⇒ Object
- #ranking(&block) ⇒ Object
Methods inherited from CAIterator
#[], #[]=, #asign!, #ca, #convert, define_calculate_method, define_evaluate_method, define_filter_method, #each, #each_with_addr, #each_with_index, #inject, #pick, #put, #sort_by, #sort_by!, #sort_with, #to_a
Constructor Details
#initialize(reference, classifier = nil) ⇒ CAClassIterator
316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/carray/base/iterator.rb', line 316 def initialize (reference, classifier = nil) @reference = reference @classifier = classifier || @reference.uniq.sort @null = CArray.new(@reference.data_type,[0]) @table = {} @rank = 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
#classifier ⇒ Object (readonly)
Returns the value of attribute classifier.
331 332 333 |
# File 'lib/carray/base/iterator.rb', line 331 def classifier @classifier end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
331 332 333 |
# File 'lib/carray/base/iterator.rb', line 331 def table @table end |
Instance Method Details
#__build__(&block) ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/carray/base/iterator.rb', line 333 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
353 354 355 356 357 358 359 360 |
# File 'lib/carray/base/iterator.rb', line 353 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
362 363 364 |
# File 'lib/carray/base/iterator.rb', line 362 def kernel_at_index (idx, ref = nil) kernel_at_addr(idx[0], ref) end |