Class: Kumi::RegistryV2::Instance
- Inherits:
-
Object
- Object
- Kumi::RegistryV2::Instance
- Defined in:
- lib/kumi/registry_v2.rb
Instance Method Summary collapse
-
#function(id) ⇒ Object
——– functions ——–.
- #function_elementwise?(id) ⇒ Boolean
- #function_kind(id) ⇒ Object
- #function_reduce?(id) ⇒ Boolean
- #function_select?(id) ⇒ Boolean
- #impl_for(kernel_id) ⇒ Object
-
#initialize(functions_by_id, kernels_by_key) ⇒ Instance
constructor
A new instance of Instance.
-
#kernel_for(id, target:) ⇒ Object
——– kernels (no changes here) ——–.
- #kernel_id_for(id, target:) ⇒ Object
- #kernel_identity_for(id, dtype:, target:) ⇒ Object
- #registry_ref ⇒ Object
- #resolve_function(id) ⇒ Object
-
#resolve_function_with_types(alias_or_id, arg_types) ⇒ Object
Type-aware function resolution for overloads Returns the function_id that best matches the given argument types.
Constructor Details
#initialize(functions_by_id, kernels_by_key) ⇒ Instance
Returns a new instance of Instance.
32 33 34 35 36 37 38 |
# File 'lib/kumi/registry_v2.rb', line 32 def initialize(functions_by_id, kernels_by_key) @functions = functions_by_id # "core.mul" => Function<...> @alias = build_alias(@functions) # "count" => "agg.count" @overload_resolver = Core::Functions::OverloadResolver.new(@functions) @kernels = kernels_by_key # [fn_id, target_sym] => Kernel @by_id = @kernels.values.to_h { |k| [k.id, k] } end |
Instance Method Details
#function(id) ⇒ Object
——– functions ——–
41 42 43 |
# File 'lib/kumi/registry_v2.rb', line 41 def function(id) @functions.fetch(resolve_function(id)) end |
#function_elementwise?(id) ⇒ Boolean
62 |
# File 'lib/kumi/registry_v2.rb', line 62 def function_elementwise?(id) = function(id).elementwise? |
#function_kind(id) ⇒ Object
60 |
# File 'lib/kumi/registry_v2.rb', line 60 def function_kind(id) = function(id).kind |
#function_reduce?(id) ⇒ Boolean
61 |
# File 'lib/kumi/registry_v2.rb', line 61 def function_reduce?(id) = function(id).reduce? |
#function_select?(id) ⇒ Boolean
63 |
# File 'lib/kumi/registry_v2.rb', line 63 def function_select?(id) = resolve_function(id) == SELECT_ID |
#impl_for(kernel_id) ⇒ Object
90 91 92 |
# File 'lib/kumi/registry_v2.rb', line 90 def impl_for(kernel_id) (@by_id[kernel_id] or raise "unknown kernel #{kernel_id}").impl end |
#kernel_for(id, target:) ⇒ Object
——– kernels (no changes here) ——–
66 67 68 69 |
# File 'lib/kumi/registry_v2.rb', line 66 def kernel_for(id, target:) fid = resolve_function(id) @kernels[[fid, target.to_sym]] or raise "no kernel for #{fid} on #{target}" end |
#kernel_id_for(id, target:) ⇒ Object
71 72 73 74 75 |
# File 'lib/kumi/registry_v2.rb', line 71 def kernel_id_for(id, target:) fid = resolve_function(id) k = @kernels[[fid, target.to_sym]] or raise "no kernel for #{fid} on #{target}" k.id end |
#kernel_identity_for(id, dtype:, target:) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kumi/registry_v2.rb', line 77 def kernel_identity_for(id, dtype:, target:) fid = resolve_function(id) k = @kernels[[fid, target.to_sym]] or raise "no kernel for #{fid} on #{target}" map = k.identity or raise "no identity for #{fid} on #{target}" identity = map[dtype.to_s] || map["any"] return identity if identity raise "no identity for dtype #{dtype} on #{fid}" end |
#registry_ref ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/kumi/registry_v2.rb', line 94 def registry_ref # ... (implementation is fine, but needs to access struct attributes) ... stable = { kernels: @by_id.values.map do |k| { "id" => k.id, "fn" => k.fn_id, "target" => k.target.to_s, "impl" => k.impl } end.sort_by { _1["id"] }, functions: @functions.transform_values do |f| { "kind" => f.kind.to_s, "aliases" => f.aliases, "params" => f.params } end } "sha256:#{Digest::SHA256.hexdigest(JSON.generate(stable))}" end |
#resolve_function(id) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/kumi/registry_v2.rb', line 45 def resolve_function(id) s = id.to_s return s if @functions.key?(s) @alias.fetch(s) do raise "unknown function #{id}" end end |
#resolve_function_with_types(alias_or_id, arg_types) ⇒ Object
Type-aware function resolution for overloads Returns the function_id that best matches the given argument types
56 57 58 |
# File 'lib/kumi/registry_v2.rb', line 56 def resolve_function_with_types(alias_or_id, arg_types) @overload_resolver.resolve(alias_or_id, arg_types) end |