Skip to content

Commit 5ff5be3

Browse files
committed
Moved feature name caching to separate method [skip ci]
1 parent 8aadbaf commit 5ff5be3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/lightgbm/booster.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def feature_name
9999
def model_from_string(model_str)
100100
out_num_iterations = ::FFI::MemoryPointer.new(:int)
101101
check_result FFI.LGBM_BoosterLoadModelFromString(model_str, out_num_iterations, @handle)
102-
@cached_feature_names = nil
102+
@cached_feature_name = nil
103103
self
104104
end
105105

@@ -148,7 +148,7 @@ def predict(input, start_iteration: nil, num_iteration: nil, **params)
148148
input.map(&method(:sorted_feature_values))
149149
elsif rover?(input)
150150
# TODO improve performance
151-
input[feature_name()].to_numo.to_a
151+
input[cached_feature_name].to_numo.to_a
152152
else
153153
input.to_a
154154
end
@@ -250,8 +250,11 @@ def read_int64(ptr)
250250
end
251251

252252
def sorted_feature_values(input_hash)
253-
@cached_feature_names ||= feature_name
254-
input_hash.transform_keys(&:to_s).fetch_values(*@cached_feature_names)
253+
input_hash.transform_keys(&:to_s).fetch_values(*cached_feature_name)
254+
end
255+
256+
def cached_feature_name
257+
@cached_feature_name ||= feature_name
255258
end
256259

257260
include Utils

0 commit comments

Comments
 (0)