Class: EnumerableOperator::Diagonal
- Includes:
- Enumerable
- Defined in:
- lib/agents/sets/enum/op.rb
Instance Attribute Summary collapse
-
#dim ⇒ Object
readonly
Returns the value of attribute dim.
-
#factors ⇒ Object
readonly
Returns the value of attribute factors.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(*factors) ⇒ Diagonal
constructor
A new instance of Diagonal.
Methods included from Enumerable
#each_cluster, #each_with_neighbors, #group, nest, #nest, #pipe
Constructor Details
#initialize(*factors) ⇒ Diagonal
Returns a new instance of Diagonal.
59 60 61 62 |
# File 'lib/agents/sets/enum/op.rb', line 59 def initialize(*factors) @factors = factors @dim = @factors.length end |
Instance Attribute Details
#dim ⇒ Object (readonly)
Returns the value of attribute dim.
57 58 59 |
# File 'lib/agents/sets/enum/op.rb', line 57 def dim @dim end |
#factors ⇒ Object (readonly)
Returns the value of attribute factors.
57 58 59 |
# File 'lib/agents/sets/enum/op.rb', line 57 def factors @factors end |
Instance Method Details
#each ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/agents/sets/enum/op.rb', line 64 def each factors = @factors.map { |factor| if factor.kind_of? Array then factor else factor.entries end } minlength = factors.min { |f, g| f.length <=> g.length }.length for i in 0..(minlength-1) yield factors.map { |factor| factor[i] } end self end |