Module: Kumi::Core::IR::ExecutionEngine::Values
- Defined in:
- lib/kumi/core/ir/execution_engine/values.rb
Overview
Value constructors and helpers for VM data representation
Class Method Summary collapse
-
.row(v, idx = nil) ⇒ Object
Create a row with optional index.
-
.scalar(v) ⇒ Object
Create a scalar value.
-
.scalar?(val) ⇒ Boolean
Check if value is scalar.
-
.vec(scope, rows, has_idx) ⇒ Object
Create a vector with scope and rows.
-
.vec?(val) ⇒ Boolean
Check if value is vector.
Class Method Details
.row(v, idx = nil) ⇒ Object
Create a row with optional index
29 30 31 |
# File 'lib/kumi/core/ir/execution_engine/values.rb', line 29 def self.row(v, idx = nil) idx ? { v: v, idx: Array(idx) } : { v: v } end |
.scalar(v) ⇒ Object
Create a scalar value
10 11 12 |
# File 'lib/kumi/core/ir/execution_engine/values.rb', line 10 def self.scalar(v) { k: :scalar, v: v } end |
.scalar?(val) ⇒ Boolean
Check if value is scalar
34 35 36 |
# File 'lib/kumi/core/ir/execution_engine/values.rb', line 34 def self.scalar?(val) val[:k] == :scalar end |
.vec(scope, rows, has_idx) ⇒ Object
Create a vector with scope and rows
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kumi/core/ir/execution_engine/values.rb', line 15 def self.vec(scope, rows, has_idx) rank = if has_idx rows.empty? ? 0 : rows.first[:idx].length # TODO: > Make sure this is not costly # raise if rows.any? { |r| r[:idx].length != rank } # rows = rows.sort_by { |r| r[:idx] } # one-time sort else 0 end { k: :vec, scope: scope, rows: rows, has_idx: has_idx, rank: rank } end |
.vec?(val) ⇒ Boolean
Check if value is vector
39 40 41 |
# File 'lib/kumi/core/ir/execution_engine/values.rb', line 39 def self.vec?(val) val[:k] == :vec end |