Class: Enumerator::ArithmeticSequence
- Inherits:
-
Object
- Object
- Enumerator::ArithmeticSequence
- Defined in:
- lib/carray/basics.rb
Overview
Reopened to add #to_ca, so a stepped sequence can be handed to any CArray entry point that coerces its operand.
Instance Method Summary collapse
-
#to_ca(writable: false) ⇒ CArray
Returns the members of
selfas a 1-DCA_OBJECTCArray, so that a strided axis can be written(0..10).step(2)or(0.0..1.0).step(0.25).
Instance Method Details
#to_ca(writable: false) ⇒ CArray
467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/carray/basics.rb', line 467 def to_ca(writable: false) if writable raise "#{self.class}#to_ca builds a new array; " \ "it can't satisfy `writable: true'" end first, last, by = self.begin, self.end, self.step if last.nil? raise RangeError, "cannot convert endless arithmetic sequence to an array" end if first.is_a?(Integer) and last.is_a?(Integer) and by > 0 and first > last return CA_OBJECT(Range.new(first, last, exclude_end?), by) end return CA_OBJECT(to_a) end |