Skip to content

Commit

Permalink
Add global-config method
Browse files Browse the repository at this point in the history
  • Loading branch information
titsuki committed Aug 8, 2021
1 parent 8bd38ff commit 87ceca2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"build-depends": [
"Algorithm::XGBoost::CustomBuilder",
"LibraryMake",
"Distribution::Builder::MakeFromJSON"
"Distribution::Builder::MakeFromJSON",
"Json::Tiny"
],
"builder": "Algorithm::XGBoost::CustomBuilder",
"depends": [
Expand Down
12 changes: 11 additions & 1 deletion lib/Algorithm/XGBoost.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ my sub XGBoostVersion(int32 is rw, int32 is rw, int32 is rw) is native($library)
my sub XGBLastError is native($library) { * }
my sub XGBRegisterLogCallBack(&callback (Str --> void)) is native($library) { * }
my sub XGBSetGlobalConfig(Str --> int32) is native($library) { * }
my sub XGBGetGlobalConfig(Str is rw --> int32) is native($library) { * }
my sub XGBGetGlobalConfig(Pointer[Str] is rw --> int32) is native($library) { * }

method new {!!!}

Expand All @@ -36,6 +36,16 @@ method train(Algorithm::XGBoost::DMatrix $dmat, Int $num-iteration --> Algorithm
Algorithm::XGBoost::Model.create($booster);
}

multi method global-config(Str $json-str) {
XGBSetGlobalConfig($json-str);
}

multi method global-config(--> Str) {
my $json-str = Pointer.new;
XGBGetGlobalConfig($json-str);
nativecast(Str, $json-str);
}

=begin pod
=head1 NAME
Expand Down
7 changes: 7 additions & 0 deletions t/01-basic.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ subtest {
is $model.predict($test), (0.9463129639625549, 0.09843720495700836)
}, "Given a label list @y, Then DMatrix.from-matrix should set the labels";

subtest {
use JSON::Tiny;
Algorithm::XGBoost.global-config(q[{"verbosity": 2}]);
my $json = Algorithm::XGBoost.global-config;
is from-json($json)<verbosity>, 2;
}, ".global-config should set/get verbosity=2"

done-testing;

0 comments on commit 87ceca2

Please sign in to comment.