Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
90127b52
"git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "4ca85fbce7db160414141db76b60691b65eaa229"
Commit
90127b52
authored
Feb 02, 2019
by
Nikita Titov
Committed by
Guolin Ke
Feb 02, 2019
Browse files
cpplint whitespaces and new lines (#1986)
parent
6f548ada
Changes
79
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
53 additions
and
95 deletions
+53
-95
src/io/config_auto.cpp
src/io/config_auto.cpp
+6
-6
src/io/dataset.cpp
src/io/dataset.cpp
+2
-4
src/io/dataset_loader.cpp
src/io/dataset_loader.cpp
+10
-14
src/io/dense_nbits_bin.hpp
src/io/dense_nbits_bin.hpp
+0
-5
src/io/file_io.cpp
src/io/file_io.cpp
+2
-2
src/io/json11.cpp
src/io/json11.cpp
+5
-7
src/io/metadata.cpp
src/io/metadata.cpp
+0
-2
src/io/ordered_sparse_bin.hpp
src/io/ordered_sparse_bin.hpp
+0
-4
src/io/parser.hpp
src/io/parser.hpp
+3
-0
src/io/sparse_bin.hpp
src/io/sparse_bin.hpp
+4
-4
src/io/tree.cpp
src/io/tree.cpp
+2
-5
src/lightgbm_R.cpp
src/lightgbm_R.cpp
+1
-14
src/metric/binary_metric.hpp
src/metric/binary_metric.hpp
+0
-3
src/metric/multiclass_metric.hpp
src/metric/multiclass_metric.hpp
+0
-2
src/metric/regression_metric.hpp
src/metric/regression_metric.hpp
+1
-3
src/metric/xentropy_metric.hpp
src/metric/xentropy_metric.hpp
+12
-13
src/network/linkers.h
src/network/linkers.h
+2
-3
src/network/linkers_mpi.cpp
src/network/linkers_mpi.cpp
+1
-1
src/network/linkers_socket.cpp
src/network/linkers_socket.cpp
+0
-1
src/network/network.cpp
src/network/network.cpp
+2
-2
No files found.
src/io/config_auto.cpp
View file @
90127b52
...
@@ -524,7 +524,7 @@ void Config::GetMembersFromString(const std::unordered_map<std::string, std::str
...
@@ -524,7 +524,7 @@ void Config::GetMembersFromString(const std::unordered_map<std::string, std::str
std
::
string
Config
::
SaveMembersToString
()
const
{
std
::
string
Config
::
SaveMembersToString
()
const
{
std
::
stringstream
str_buf
;
std
::
stringstream
str_buf
;
str_buf
<<
"[data: "
<<
data
<<
"]
\n
"
;
str_buf
<<
"[data: "
<<
data
<<
"]
\n
"
;
str_buf
<<
"[valid: "
<<
Common
::
Join
(
valid
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[valid: "
<<
Common
::
Join
(
valid
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[num_iterations: "
<<
num_iterations
<<
"]
\n
"
;
str_buf
<<
"[num_iterations: "
<<
num_iterations
<<
"]
\n
"
;
str_buf
<<
"[learning_rate: "
<<
learning_rate
<<
"]
\n
"
;
str_buf
<<
"[learning_rate: "
<<
learning_rate
<<
"]
\n
"
;
str_buf
<<
"[num_leaves: "
<<
num_leaves
<<
"]
\n
"
;
str_buf
<<
"[num_leaves: "
<<
num_leaves
<<
"]
\n
"
;
...
@@ -556,8 +556,8 @@ std::string Config::SaveMembersToString() const {
...
@@ -556,8 +556,8 @@ std::string Config::SaveMembersToString() const {
str_buf
<<
"[cat_smooth: "
<<
cat_smooth
<<
"]
\n
"
;
str_buf
<<
"[cat_smooth: "
<<
cat_smooth
<<
"]
\n
"
;
str_buf
<<
"[max_cat_to_onehot: "
<<
max_cat_to_onehot
<<
"]
\n
"
;
str_buf
<<
"[max_cat_to_onehot: "
<<
max_cat_to_onehot
<<
"]
\n
"
;
str_buf
<<
"[top_k: "
<<
top_k
<<
"]
\n
"
;
str_buf
<<
"[top_k: "
<<
top_k
<<
"]
\n
"
;
str_buf
<<
"[monotone_constraints: "
<<
Common
::
Join
(
Common
::
ArrayCast
<
int8_t
,
int
>
(
monotone_constraints
),
","
)
<<
"]
\n
"
;
str_buf
<<
"[monotone_constraints: "
<<
Common
::
Join
(
Common
::
ArrayCast
<
int8_t
,
int
>
(
monotone_constraints
),
","
)
<<
"]
\n
"
;
str_buf
<<
"[feature_contri: "
<<
Common
::
Join
(
feature_contri
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[feature_contri: "
<<
Common
::
Join
(
feature_contri
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[forcedsplits_filename: "
<<
forcedsplits_filename
<<
"]
\n
"
;
str_buf
<<
"[forcedsplits_filename: "
<<
forcedsplits_filename
<<
"]
\n
"
;
str_buf
<<
"[refit_decay_rate: "
<<
refit_decay_rate
<<
"]
\n
"
;
str_buf
<<
"[refit_decay_rate: "
<<
refit_decay_rate
<<
"]
\n
"
;
str_buf
<<
"[verbosity: "
<<
verbosity
<<
"]
\n
"
;
str_buf
<<
"[verbosity: "
<<
verbosity
<<
"]
\n
"
;
...
@@ -571,7 +571,7 @@ std::string Config::SaveMembersToString() const {
...
@@ -571,7 +571,7 @@ std::string Config::SaveMembersToString() const {
str_buf
<<
"[input_model: "
<<
input_model
<<
"]
\n
"
;
str_buf
<<
"[input_model: "
<<
input_model
<<
"]
\n
"
;
str_buf
<<
"[output_result: "
<<
output_result
<<
"]
\n
"
;
str_buf
<<
"[output_result: "
<<
output_result
<<
"]
\n
"
;
str_buf
<<
"[initscore_filename: "
<<
initscore_filename
<<
"]
\n
"
;
str_buf
<<
"[initscore_filename: "
<<
initscore_filename
<<
"]
\n
"
;
str_buf
<<
"[valid_data_initscores: "
<<
Common
::
Join
(
valid_data_initscores
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[valid_data_initscores: "
<<
Common
::
Join
(
valid_data_initscores
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[pre_partition: "
<<
pre_partition
<<
"]
\n
"
;
str_buf
<<
"[pre_partition: "
<<
pre_partition
<<
"]
\n
"
;
str_buf
<<
"[enable_bundle: "
<<
enable_bundle
<<
"]
\n
"
;
str_buf
<<
"[enable_bundle: "
<<
enable_bundle
<<
"]
\n
"
;
str_buf
<<
"[max_conflict_rate: "
<<
max_conflict_rate
<<
"]
\n
"
;
str_buf
<<
"[max_conflict_rate: "
<<
max_conflict_rate
<<
"]
\n
"
;
...
@@ -608,10 +608,10 @@ std::string Config::SaveMembersToString() const {
...
@@ -608,10 +608,10 @@ std::string Config::SaveMembersToString() const {
str_buf
<<
"[poisson_max_delta_step: "
<<
poisson_max_delta_step
<<
"]
\n
"
;
str_buf
<<
"[poisson_max_delta_step: "
<<
poisson_max_delta_step
<<
"]
\n
"
;
str_buf
<<
"[tweedie_variance_power: "
<<
tweedie_variance_power
<<
"]
\n
"
;
str_buf
<<
"[tweedie_variance_power: "
<<
tweedie_variance_power
<<
"]
\n
"
;
str_buf
<<
"[max_position: "
<<
max_position
<<
"]
\n
"
;
str_buf
<<
"[max_position: "
<<
max_position
<<
"]
\n
"
;
str_buf
<<
"[label_gain: "
<<
Common
::
Join
(
label_gain
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[label_gain: "
<<
Common
::
Join
(
label_gain
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[metric_freq: "
<<
metric_freq
<<
"]
\n
"
;
str_buf
<<
"[metric_freq: "
<<
metric_freq
<<
"]
\n
"
;
str_buf
<<
"[is_provide_training_metric: "
<<
is_provide_training_metric
<<
"]
\n
"
;
str_buf
<<
"[is_provide_training_metric: "
<<
is_provide_training_metric
<<
"]
\n
"
;
str_buf
<<
"[eval_at: "
<<
Common
::
Join
(
eval_at
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[eval_at: "
<<
Common
::
Join
(
eval_at
,
","
)
<<
"]
\n
"
;
str_buf
<<
"[num_machines: "
<<
num_machines
<<
"]
\n
"
;
str_buf
<<
"[num_machines: "
<<
num_machines
<<
"]
\n
"
;
str_buf
<<
"[local_listen_port: "
<<
local_listen_port
<<
"]
\n
"
;
str_buf
<<
"[local_listen_port: "
<<
local_listen_port
<<
"]
\n
"
;
str_buf
<<
"[time_out: "
<<
time_out
<<
"]
\n
"
;
str_buf
<<
"[time_out: "
<<
time_out
<<
"]
\n
"
;
...
...
src/io/dataset.cpp
View file @
90127b52
...
@@ -86,7 +86,7 @@ std::vector<std::vector<int>> FindGroups(const std::vector<std::unique_ptr<BinMa
...
@@ -86,7 +86,7 @@ std::vector<std::vector<int>> FindGroups(const std::vector<std::unique_ptr<BinMa
bool
need_new_group
=
true
;
bool
need_new_group
=
true
;
std
::
vector
<
int
>
available_groups
;
std
::
vector
<
int
>
available_groups
;
for
(
int
gid
=
0
;
gid
<
static_cast
<
int
>
(
features_in_group
.
size
());
++
gid
)
{
for
(
int
gid
=
0
;
gid
<
static_cast
<
int
>
(
features_in_group
.
size
());
++
gid
)
{
if
(
group_non_zero_cnt
[
gid
]
+
cur_non_zero_cnt
<=
total_sample_cnt
+
max_error_cnt
){
if
(
group_non_zero_cnt
[
gid
]
+
cur_non_zero_cnt
<=
total_sample_cnt
+
max_error_cnt
)
{
if
(
!
is_use_gpu
||
group_num_bin
[
gid
]
+
bin_mappers
[
fidx
]
->
num_bin
()
+
(
bin_mappers
[
fidx
]
->
GetDefaultBin
()
==
0
?
-
1
:
0
)
if
(
!
is_use_gpu
||
group_num_bin
[
gid
]
+
bin_mappers
[
fidx
]
->
num_bin
()
+
(
bin_mappers
[
fidx
]
->
GetDefaultBin
()
==
0
?
-
1
:
0
)
<=
gpu_max_bin_per_group
)
{
<=
gpu_max_bin_per_group
)
{
available_groups
.
push_back
(
gid
);
available_groups
.
push_back
(
gid
);
...
@@ -188,7 +188,7 @@ std::vector<std::vector<int>> FastFeatureBundling(std::vector<std::unique_ptr<Bi
...
@@ -188,7 +188,7 @@ std::vector<std::vector<int>> FastFeatureBundling(std::vector<std::unique_ptr<Bi
cnt_non_zero
+=
static_cast
<
int
>
(
num_data
*
(
1.0
f
-
bin_mappers
[
fidx
]
->
sparse_rate
()));
cnt_non_zero
+=
static_cast
<
int
>
(
num_data
*
(
1.0
f
-
bin_mappers
[
fidx
]
->
sparse_rate
()));
}
}
double
sparse_rate
=
1.0
f
-
static_cast
<
double
>
(
cnt_non_zero
)
/
(
num_data
);
double
sparse_rate
=
1.0
f
-
static_cast
<
double
>
(
cnt_non_zero
)
/
(
num_data
);
// take apart small sparse group, due it will not gain on speed
// take apart small sparse group, due it will not gain on speed
if
(
sparse_rate
>=
sparse_threshold
&&
is_enable_sparse
)
{
if
(
sparse_rate
>=
sparse_threshold
&&
is_enable_sparse
)
{
for
(
size_t
j
=
0
;
j
<
features_in_group
[
i
].
size
();
++
j
)
{
for
(
size_t
j
=
0
;
j
<
features_in_group
[
i
].
size
();
++
j
)
{
const
int
fidx
=
features_in_group
[
i
][
j
];
const
int
fidx
=
features_in_group
[
i
][
j
];
...
@@ -216,7 +216,6 @@ void Dataset::Construct(
...
@@ -216,7 +216,6 @@ void Dataset::Construct(
const
int
*
num_per_col
,
const
int
*
num_per_col
,
size_t
total_sample_cnt
,
size_t
total_sample_cnt
,
const
Config
&
io_config
)
{
const
Config
&
io_config
)
{
num_total_features_
=
static_cast
<
int
>
(
bin_mappers
.
size
());
num_total_features_
=
static_cast
<
int
>
(
bin_mappers
.
size
());
sparse_threshold_
=
io_config
.
sparse_threshold
;
sparse_threshold_
=
io_config
.
sparse_threshold
;
// get num_features
// get num_features
...
@@ -699,7 +698,6 @@ void Dataset::ConstructHistograms(const std::vector<int8_t>& is_feature_used,
...
@@ -699,7 +698,6 @@ void Dataset::ConstructHistograms(const std::vector<int8_t>& is_feature_used,
score_t
*
ordered_gradients
,
score_t
*
ordered_hessians
,
score_t
*
ordered_gradients
,
score_t
*
ordered_hessians
,
bool
is_constant_hessian
,
bool
is_constant_hessian
,
HistogramBinEntry
*
hist_data
)
const
{
HistogramBinEntry
*
hist_data
)
const
{
if
(
leaf_idx
<
0
||
num_data
<
0
||
hist_data
==
nullptr
)
{
if
(
leaf_idx
<
0
||
num_data
<
0
||
hist_data
==
nullptr
)
{
return
;
return
;
}
}
...
...
src/io/dataset_loader.cpp
View file @
90127b52
...
@@ -18,7 +18,6 @@ DatasetLoader::DatasetLoader(const Config& io_config, const PredictFunction& pre
...
@@ -18,7 +18,6 @@ DatasetLoader::DatasetLoader(const Config& io_config, const PredictFunction& pre
}
}
DatasetLoader
::~
DatasetLoader
()
{
DatasetLoader
::~
DatasetLoader
()
{
}
}
void
DatasetLoader
::
SetHeader
(
const
char
*
filename
)
{
void
DatasetLoader
::
SetHeader
(
const
char
*
filename
)
{
...
@@ -382,12 +381,12 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
...
@@ -382,12 +381,12 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
}
}
mem_ptr
+=
sizeof
(
int
)
*
(
dataset
->
num_groups_
);
mem_ptr
+=
sizeof
(
int
)
*
(
dataset
->
num_groups_
);
if
(
!
config_
.
monotone_constraints
.
empty
())
{
if
(
!
config_
.
monotone_constraints
.
empty
())
{
CHECK
(
static_cast
<
size_t
>
(
dataset
->
num_total_features_
)
==
config_
.
monotone_constraints
.
size
());
CHECK
(
static_cast
<
size_t
>
(
dataset
->
num_total_features_
)
==
config_
.
monotone_constraints
.
size
());
dataset
->
monotone_types_
.
resize
(
dataset
->
num_features_
);
dataset
->
monotone_types_
.
resize
(
dataset
->
num_features_
);
for
(
int
i
=
0
;
i
<
dataset
->
num_total_features_
;
++
i
){
for
(
int
i
=
0
;
i
<
dataset
->
num_total_features_
;
++
i
)
{
int
inner_fidx
=
dataset
->
InnerFeatureIndex
(
i
);
int
inner_fidx
=
dataset
->
InnerFeatureIndex
(
i
);
if
(
inner_fidx
>=
0
)
{
if
(
inner_fidx
>=
0
)
{
dataset
->
monotone_types_
[
inner_fidx
]
=
config_
.
monotone_constraints
[
i
];
dataset
->
monotone_types_
[
inner_fidx
]
=
config_
.
monotone_constraints
[
i
];
}
}
}
}
...
@@ -405,12 +404,12 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
...
@@ -405,12 +404,12 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
dataset
->
monotone_types_
.
clear
();
dataset
->
monotone_types_
.
clear
();
}
}
if
(
!
config_
.
feature_contri
.
empty
())
{
if
(
!
config_
.
feature_contri
.
empty
())
{
CHECK
(
static_cast
<
size_t
>
(
dataset
->
num_total_features_
)
==
config_
.
feature_contri
.
size
());
CHECK
(
static_cast
<
size_t
>
(
dataset
->
num_total_features_
)
==
config_
.
feature_contri
.
size
());
dataset
->
feature_penalty_
.
resize
(
dataset
->
num_features_
);
dataset
->
feature_penalty_
.
resize
(
dataset
->
num_features_
);
for
(
int
i
=
0
;
i
<
dataset
->
num_total_features_
;
++
i
){
for
(
int
i
=
0
;
i
<
dataset
->
num_total_features_
;
++
i
)
{
int
inner_fidx
=
dataset
->
InnerFeatureIndex
(
i
);
int
inner_fidx
=
dataset
->
InnerFeatureIndex
(
i
);
if
(
inner_fidx
>=
0
)
{
if
(
inner_fidx
>=
0
)
{
dataset
->
feature_penalty_
[
inner_fidx
]
=
config_
.
feature_contri
[
i
];
dataset
->
feature_penalty_
[
inner_fidx
]
=
config_
.
feature_contri
[
i
];
}
}
}
}
...
@@ -526,8 +525,7 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
...
@@ -526,8 +525,7 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
dataset
->
feature_groups_
.
emplace_back
(
std
::
unique_ptr
<
FeatureGroup
>
(
dataset
->
feature_groups_
.
emplace_back
(
std
::
unique_ptr
<
FeatureGroup
>
(
new
FeatureGroup
(
buffer
.
data
(),
new
FeatureGroup
(
buffer
.
data
(),
*
num_global_data
,
*
num_global_data
,
*
used_data_indices
)
*
used_data_indices
)));
));
}
}
dataset
->
feature_groups_
.
shrink_to_fit
();
dataset
->
feature_groups_
.
shrink_to_fit
();
dataset
->
is_finish_load_
=
true
;
dataset
->
is_finish_load_
=
true
;
...
@@ -782,8 +780,8 @@ std::vector<std::string> DatasetLoader::SampleTextDataFromFile(const char* filen
...
@@ -782,8 +780,8 @@ std::vector<std::string> DatasetLoader::SampleTextDataFromFile(const char* filen
[
this
,
rank
,
num_machines
,
&
qid
,
&
query_boundaries
,
&
is_query_used
,
num_queries
]
[
this
,
rank
,
num_machines
,
&
qid
,
&
query_boundaries
,
&
is_query_used
,
num_queries
]
(
data_size_t
line_idx
)
{
(
data_size_t
line_idx
)
{
if
(
qid
>=
num_queries
)
{
if
(
qid
>=
num_queries
)
{
Log
::
Fatal
(
"Query id exceeds the range of the query file,
\
Log
::
Fatal
(
"Query id exceeds the range of the query file,
"
please ensure the query file is correct"
);
"
please ensure the query file is correct"
);
}
}
if
(
line_idx
>=
query_boundaries
[
qid
+
1
])
{
if
(
line_idx
>=
query_boundaries
[
qid
+
1
])
{
// if is new query
// if is new query
...
@@ -801,7 +799,6 @@ std::vector<std::string> DatasetLoader::SampleTextDataFromFile(const char* filen
...
@@ -801,7 +799,6 @@ std::vector<std::string> DatasetLoader::SampleTextDataFromFile(const char* filen
}
}
void
DatasetLoader
::
ConstructBinMappersFromTextData
(
int
rank
,
int
num_machines
,
const
std
::
vector
<
std
::
string
>&
sample_data
,
const
Parser
*
parser
,
Dataset
*
dataset
)
{
void
DatasetLoader
::
ConstructBinMappersFromTextData
(
int
rank
,
int
num_machines
,
const
std
::
vector
<
std
::
string
>&
sample_data
,
const
Parser
*
parser
,
Dataset
*
dataset
)
{
std
::
vector
<
std
::
vector
<
double
>>
sample_values
;
std
::
vector
<
std
::
vector
<
double
>>
sample_values
;
std
::
vector
<
std
::
vector
<
int
>>
sample_indices
;
std
::
vector
<
std
::
vector
<
int
>>
sample_indices
;
std
::
vector
<
std
::
pair
<
int
,
double
>>
oneline_features
;
std
::
vector
<
std
::
pair
<
int
,
double
>>
oneline_features
;
...
@@ -1143,7 +1140,6 @@ std::string DatasetLoader::CheckCanLoadFromBin(const char* filename) {
...
@@ -1143,7 +1140,6 @@ std::string DatasetLoader::CheckCanLoadFromBin(const char* filename) {
}
else
{
}
else
{
return
std
::
string
();
return
std
::
string
();
}
}
}
}
}
}
// namespace LightGBM
src/io/dense_nbits_bin.hpp
View file @
90127b52
...
@@ -45,7 +45,6 @@ public:
...
@@ -45,7 +45,6 @@ public:
}
}
~
Dense4bitsBin
()
{
~
Dense4bitsBin
()
{
}
}
void
Push
(
int
,
data_size_t
idx
,
uint32_t
value
)
override
{
void
Push
(
int
,
data_size_t
idx
,
uint32_t
value
)
override
{
...
@@ -72,11 +71,9 @@ public:
...
@@ -72,11 +71,9 @@ public:
void
ConstructHistogram
(
const
data_size_t
*
data_indices
,
data_size_t
num_data
,
void
ConstructHistogram
(
const
data_size_t
*
data_indices
,
data_size_t
num_data
,
const
score_t
*
ordered_gradients
,
const
score_t
*
ordered_hessians
,
const
score_t
*
ordered_gradients
,
const
score_t
*
ordered_hessians
,
HistogramBinEntry
*
out
)
const
override
{
HistogramBinEntry
*
out
)
const
override
{
const
data_size_t
rest
=
num_data
&
0x3
;
const
data_size_t
rest
=
num_data
&
0x3
;
data_size_t
i
=
0
;
data_size_t
i
=
0
;
for
(;
i
<
num_data
-
rest
;
i
+=
4
)
{
for
(;
i
<
num_data
-
rest
;
i
+=
4
)
{
const
data_size_t
idx0
=
data_indices
[
i
];
const
data_size_t
idx0
=
data_indices
[
i
];
const
auto
bin0
=
(
data_
[
idx0
>>
1
]
>>
((
idx0
&
1
)
<<
2
))
&
0xf
;
const
auto
bin0
=
(
data_
[
idx0
>>
1
]
>>
((
idx0
&
1
)
<<
2
))
&
0xf
;
...
@@ -103,7 +100,6 @@ public:
...
@@ -103,7 +100,6 @@ public:
++
out
[
bin1
].
cnt
;
++
out
[
bin1
].
cnt
;
++
out
[
bin2
].
cnt
;
++
out
[
bin2
].
cnt
;
++
out
[
bin3
].
cnt
;
++
out
[
bin3
].
cnt
;
}
}
for
(;
i
<
num_data
;
++
i
)
{
for
(;
i
<
num_data
;
++
i
)
{
...
@@ -121,7 +117,6 @@ public:
...
@@ -121,7 +117,6 @@ public:
const
data_size_t
rest
=
num_data
&
0x3
;
const
data_size_t
rest
=
num_data
&
0x3
;
data_size_t
i
=
0
;
data_size_t
i
=
0
;
for
(;
i
<
num_data
-
rest
;
i
+=
4
)
{
for
(;
i
<
num_data
-
rest
;
i
+=
4
)
{
const
auto
bin0
=
(
data_
[
i
>>
1
])
&
0xf
;
const
auto
bin0
=
(
data_
[
i
>>
1
])
&
0xf
;
const
auto
bin1
=
(
data_
[
i
>>
1
]
>>
4
)
&
0xf
;
const
auto
bin1
=
(
data_
[
i
>>
1
]
>>
4
)
&
0xf
;
const
auto
bin2
=
(
data_
[(
i
>>
1
)
+
1
])
&
0xf
;
const
auto
bin2
=
(
data_
[(
i
>>
1
)
+
1
])
&
0xf
;
...
...
src/io/file_io.cpp
View file @
90127b52
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include <hdfs.h>
#include <hdfs.h>
#endif
#endif
namespace
LightGBM
{
namespace
LightGBM
{
struct
LocalFile
:
VirtualFileReader
,
VirtualFileWriter
{
struct
LocalFile
:
VirtualFileReader
,
VirtualFileWriter
{
LocalFile
(
const
std
::
string
&
filename
,
const
std
::
string
&
mode
)
:
filename_
(
filename
),
mode_
(
mode
)
{}
LocalFile
(
const
std
::
string
&
filename
,
const
std
::
string
&
mode
)
:
filename_
(
filename
),
mode_
(
mode
)
{}
...
@@ -148,7 +148,7 @@ std::unordered_map<std::string, hdfsFS> HDFSFile::fs_cache_ = std::unordered_map
...
@@ -148,7 +148,7 @@ std::unordered_map<std::string, hdfsFS> HDFSFile::fs_cache_ = std::unordered_map
#define WITH_HDFS(x) x
#define WITH_HDFS(x) x
#else
#else
#define WITH_HDFS(x) Log::Fatal("HDFS support is not enabled")
#define WITH_HDFS(x) Log::Fatal("HDFS support is not enabled")
#endif // USE_HDFS
#endif
// USE_HDFS
std
::
unique_ptr
<
VirtualFileReader
>
VirtualFileReader
::
Make
(
const
std
::
string
&
filename
)
{
std
::
unique_ptr
<
VirtualFileReader
>
VirtualFileReader
::
Make
(
const
std
::
string
&
filename
)
{
if
(
0
==
filename
.
find
(
kHdfsProto
))
{
if
(
0
==
filename
.
find
(
kHdfsProto
))
{
...
...
src/io/json11.cpp
View file @
90127b52
...
@@ -148,7 +148,6 @@ void Json::dump(string &out) const {
...
@@ -148,7 +148,6 @@ void Json::dump(string &out) const {
template
<
Json
::
Type
tag
,
typename
T
>
template
<
Json
::
Type
tag
,
typename
T
>
class
Value
:
public
JsonValue
{
class
Value
:
public
JsonValue
{
protected:
protected:
// Constructors
// Constructors
explicit
Value
(
const
T
&
value
)
:
m_value
(
value
)
{}
explicit
Value
(
const
T
&
value
)
:
m_value
(
value
)
{}
explicit
Value
(
T
&&
value
)
:
m_value
(
move
(
value
))
{}
explicit
Value
(
T
&&
value
)
:
m_value
(
move
(
value
))
{}
...
@@ -345,7 +344,6 @@ namespace {
...
@@ -345,7 +344,6 @@ namespace {
* Object that tracks all state of an in-progress parse.
* Object that tracks all state of an in-progress parse.
*/
*/
struct
JsonParser
final
{
struct
JsonParser
final
{
/* State
/* State
*/
*/
const
string
&
str
;
const
string
&
str
;
...
@@ -397,7 +395,7 @@ struct JsonParser final {
...
@@ -397,7 +395,7 @@ struct JsonParser final {
}
}
comment_found
=
true
;
comment_found
=
true
;
}
}
else
if
(
str
[
i
]
==
'*'
)
{
// multiline comment
else
if
(
str
[
i
]
==
'*'
)
{
// multiline comment
i
++
;
i
++
;
if
(
i
>
str
.
size
()
-
2
)
if
(
i
>
str
.
size
()
-
2
)
return
fail
(
"Unexpected end of input inside multi-line comment"
,
false
);
return
fail
(
"Unexpected end of input inside multi-line comment"
,
false
);
...
@@ -422,14 +420,14 @@ struct JsonParser final {
...
@@ -422,14 +420,14 @@ struct JsonParser final {
*/
*/
void
consume_garbage
()
{
void
consume_garbage
()
{
consume_whitespace
();
consume_whitespace
();
if
(
strategy
==
JsonParse
::
COMMENTS
)
{
if
(
strategy
==
JsonParse
::
COMMENTS
)
{
bool
comment_found
=
false
;
bool
comment_found
=
false
;
do
{
do
{
comment_found
=
consume_comment
();
comment_found
=
consume_comment
();
if
(
failed
)
return
;
if
(
failed
)
return
;
consume_whitespace
();
consume_whitespace
();
}
}
while
(
comment_found
);
while
(
comment_found
);
}
}
}
}
...
@@ -726,7 +724,7 @@ struct JsonParser final {
...
@@ -726,7 +724,7 @@ struct JsonParser final {
return
fail
(
"Expected value, got "
+
esc
(
ch
));
return
fail
(
"Expected value, got "
+
esc
(
ch
));
}
}
};
};
}
//namespace
{
}
//
namespace
Json
Json
::
parse
(
const
string
&
in
,
string
&
err
,
JsonParse
strategy
)
{
Json
Json
::
parse
(
const
string
&
in
,
string
&
err
,
JsonParse
strategy
)
{
JsonParser
parser
{
in
,
0
,
err
,
false
,
strategy
};
JsonParser
parser
{
in
,
0
,
err
,
false
,
strategy
};
...
@@ -784,4 +782,4 @@ bool Json::has_shape(const shape & types, string & err) const {
...
@@ -784,4 +782,4 @@ bool Json::has_shape(const shape & types, string & err) const {
return
true
;
return
true
;
}
}
}
// namespace json11
}
// namespace json11
src/io/metadata.cpp
View file @
90127b52
...
@@ -125,7 +125,6 @@ void Metadata::Init(const Metadata& fullset, const data_size_t* used_indices, da
...
@@ -125,7 +125,6 @@ void Metadata::Init(const Metadata& fullset, const data_size_t* used_indices, da
}
else
{
}
else
{
num_queries_
=
0
;
num_queries_
=
0
;
}
}
}
}
void
Metadata
::
PartitionLabel
(
const
std
::
vector
<
data_size_t
>&
used_indices
)
{
void
Metadata
::
PartitionLabel
(
const
std
::
vector
<
data_size_t
>&
used_indices
)
{
...
@@ -516,7 +515,6 @@ void Metadata::SaveBinaryToFile(const VirtualFileWriter* writer) const {
...
@@ -516,7 +515,6 @@ void Metadata::SaveBinaryToFile(const VirtualFileWriter* writer) const {
if
(
!
query_boundaries_
.
empty
())
{
if
(
!
query_boundaries_
.
empty
())
{
writer
->
Write
(
query_boundaries_
.
data
(),
sizeof
(
data_size_t
)
*
(
num_queries_
+
1
));
writer
->
Write
(
query_boundaries_
.
data
(),
sizeof
(
data_size_t
)
*
(
num_queries_
+
1
));
}
}
}
}
size_t
Metadata
::
SizesInByte
()
const
{
size_t
Metadata
::
SizesInByte
()
const
{
...
...
src/io/ordered_sparse_bin.hpp
View file @
90127b52
...
@@ -87,7 +87,6 @@ public:
...
@@ -87,7 +87,6 @@ public:
data_size_t
i
=
start
;
data_size_t
i
=
start
;
// use data on current leaf to construct histogram
// use data on current leaf to construct histogram
for
(;
i
<
end
-
rest
;
i
+=
4
)
{
for
(;
i
<
end
-
rest
;
i
+=
4
)
{
const
VAL_T
bin0
=
ordered_pair_
[
i
].
bin
;
const
VAL_T
bin0
=
ordered_pair_
[
i
].
bin
;
const
VAL_T
bin1
=
ordered_pair_
[
i
+
1
].
bin
;
const
VAL_T
bin1
=
ordered_pair_
[
i
+
1
].
bin
;
const
VAL_T
bin2
=
ordered_pair_
[
i
+
2
].
bin
;
const
VAL_T
bin2
=
ordered_pair_
[
i
+
2
].
bin
;
...
@@ -119,7 +118,6 @@ public:
...
@@ -119,7 +118,6 @@ public:
}
}
for
(;
i
<
end
;
++
i
)
{
for
(;
i
<
end
;
++
i
)
{
const
VAL_T
bin0
=
ordered_pair_
[
i
].
bin
;
const
VAL_T
bin0
=
ordered_pair_
[
i
].
bin
;
const
auto
g0
=
gradient
[
ordered_pair_
[
i
].
ridx
];
const
auto
g0
=
gradient
[
ordered_pair_
[
i
].
ridx
];
...
@@ -129,7 +127,6 @@ public:
...
@@ -129,7 +127,6 @@ public:
out
[
bin0
].
sum_hessians
+=
h0
;
out
[
bin0
].
sum_hessians
+=
h0
;
++
out
[
bin0
].
cnt
;
++
out
[
bin0
].
cnt
;
}
}
}
}
void
ConstructHistogram
(
int
leaf
,
const
score_t
*
gradient
,
void
ConstructHistogram
(
int
leaf
,
const
score_t
*
gradient
,
...
@@ -141,7 +138,6 @@ public:
...
@@ -141,7 +138,6 @@ public:
data_size_t
i
=
start
;
data_size_t
i
=
start
;
// use data on current leaf to construct histogram
// use data on current leaf to construct histogram
for
(;
i
<
end
-
rest
;
i
+=
4
)
{
for
(;
i
<
end
-
rest
;
i
+=
4
)
{
const
VAL_T
bin0
=
ordered_pair_
[
i
].
bin
;
const
VAL_T
bin0
=
ordered_pair_
[
i
].
bin
;
const
VAL_T
bin1
=
ordered_pair_
[
i
+
1
].
bin
;
const
VAL_T
bin1
=
ordered_pair_
[
i
+
1
].
bin
;
const
VAL_T
bin2
=
ordered_pair_
[
i
+
2
].
bin
;
const
VAL_T
bin2
=
ordered_pair_
[
i
+
2
].
bin
;
...
...
src/io/parser.hpp
View file @
90127b52
...
@@ -44,6 +44,7 @@ public:
...
@@ -44,6 +44,7 @@ public:
inline
int
TotalColumns
()
const
override
{
inline
int
TotalColumns
()
const
override
{
return
total_columns_
;
return
total_columns_
;
}
}
private:
private:
int
label_idx_
=
0
;
int
label_idx_
=
0
;
int
total_columns_
=
-
1
;
int
total_columns_
=
-
1
;
...
@@ -79,6 +80,7 @@ public:
...
@@ -79,6 +80,7 @@ public:
inline
int
TotalColumns
()
const
override
{
inline
int
TotalColumns
()
const
override
{
return
total_columns_
;
return
total_columns_
;
}
}
private:
private:
int
label_idx_
=
0
;
int
label_idx_
=
0
;
int
total_columns_
=
-
1
;
int
total_columns_
=
-
1
;
...
@@ -118,6 +120,7 @@ public:
...
@@ -118,6 +120,7 @@ public:
inline
int
TotalColumns
()
const
override
{
inline
int
TotalColumns
()
const
override
{
return
-
1
;
return
-
1
;
}
}
private:
private:
int
label_idx_
=
0
;
int
label_idx_
=
0
;
};
};
...
...
src/io/sparse_bin.hpp
View file @
90127b52
...
@@ -41,7 +41,7 @@ public:
...
@@ -41,7 +41,7 @@ public:
inline
uint32_t
RawGet
(
data_size_t
idx
)
override
;
inline
uint32_t
RawGet
(
data_size_t
idx
)
override
;
inline
VAL_T
InnerRawGet
(
data_size_t
idx
);
inline
VAL_T
InnerRawGet
(
data_size_t
idx
);
inline
uint32_t
Get
(
data_size_t
idx
)
override
{
inline
uint32_t
Get
(
data_size_t
idx
)
override
{
VAL_T
ret
=
InnerRawGet
(
idx
);
VAL_T
ret
=
InnerRawGet
(
idx
);
if
(
ret
>=
min_bin_
&&
ret
<=
max_bin_
)
{
if
(
ret
>=
min_bin_
&&
ret
<=
max_bin_
)
{
return
ret
-
min_bin_
+
bias_
;
return
ret
-
min_bin_
+
bias_
;
...
@@ -51,6 +51,7 @@ public:
...
@@ -51,6 +51,7 @@ public:
}
}
inline
void
Reset
(
data_size_t
idx
)
override
;
inline
void
Reset
(
data_size_t
idx
)
override
;
private:
private:
const
SparseBin
<
VAL_T
>*
bin_data_
;
const
SparseBin
<
VAL_T
>*
bin_data_
;
data_size_t
cur_pos_
;
data_size_t
cur_pos_
;
...
@@ -82,7 +83,6 @@ public:
...
@@ -82,7 +83,6 @@ public:
}
}
~
SparseBin
()
{
~
SparseBin
()
{
}
}
void
ReSize
(
data_size_t
num_data
)
override
{
void
ReSize
(
data_size_t
num_data
)
override
{
...
@@ -188,7 +188,7 @@ public:
...
@@ -188,7 +188,7 @@ public:
if
((
default_left
&&
missing_type
==
MissingType
::
Zero
)
||
(
default_bin
<=
threshold
&&
missing_type
!=
MissingType
::
Zero
))
{
if
((
default_left
&&
missing_type
==
MissingType
::
Zero
)
||
(
default_bin
<=
threshold
&&
missing_type
!=
MissingType
::
Zero
))
{
default_indices
=
lte_indices
;
default_indices
=
lte_indices
;
default_count
=
&
lte_count
;
default_count
=
&
lte_count
;
}
}
for
(
data_size_t
i
=
0
;
i
<
num_data
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data
;
++
i
)
{
const
data_size_t
idx
=
data_indices
[
i
];
const
data_size_t
idx
=
data_indices
[
i
];
const
VAL_T
bin
=
iterator
.
InnerRawGet
(
idx
);
const
VAL_T
bin
=
iterator
.
InnerRawGet
(
idx
);
...
@@ -200,7 +200,7 @@ public:
...
@@ -200,7 +200,7 @@ public:
lte_indices
[
lte_count
++
]
=
idx
;
lte_indices
[
lte_count
++
]
=
idx
;
}
}
}
}
}
}
return
lte_count
;
return
lte_count
;
}
}
...
...
src/io/tree.cpp
View file @
90127b52
...
@@ -17,7 +17,6 @@ namespace LightGBM {
...
@@ -17,7 +17,6 @@ namespace LightGBM {
Tree
::
Tree
(
int
max_leaves
)
Tree
::
Tree
(
int
max_leaves
)
:
max_leaves_
(
max_leaves
)
{
:
max_leaves_
(
max_leaves
)
{
left_child_
.
resize
(
max_leaves_
-
1
);
left_child_
.
resize
(
max_leaves_
-
1
);
right_child_
.
resize
(
max_leaves_
-
1
);
right_child_
.
resize
(
max_leaves_
-
1
);
split_feature_inner_
.
resize
(
max_leaves_
-
1
);
split_feature_inner_
.
resize
(
max_leaves_
-
1
);
...
@@ -45,7 +44,6 @@ Tree::Tree(int max_leaves)
...
@@ -45,7 +44,6 @@ Tree::Tree(int max_leaves)
}
}
Tree
::~
Tree
()
{
Tree
::~
Tree
()
{
}
}
int
Tree
::
Split
(
int
leaf
,
int
feature
,
int
real_feature
,
uint32_t
threshold_bin
,
int
Tree
::
Split
(
int
leaf
,
int
feature
,
int
real_feature
,
uint32_t
threshold_bin
,
...
@@ -379,7 +377,7 @@ std::string Tree::ToIfElse(int index, bool predict_leaf_index) const {
...
@@ -379,7 +377,7 @@ std::string Tree::ToIfElse(int index, bool predict_leaf_index) const {
}
}
str_buf
<<
" }"
<<
'\n'
;
str_buf
<<
" }"
<<
'\n'
;
//Predict func by Map to ifelse
//
Predict func by Map to ifelse
str_buf
<<
"double PredictTree"
<<
index
;
str_buf
<<
"double PredictTree"
<<
index
;
if
(
predict_leaf_index
)
{
if
(
predict_leaf_index
)
{
str_buf
<<
"LeafByMap"
;
str_buf
<<
"LeafByMap"
;
...
@@ -480,7 +478,7 @@ Tree::Tree(const char* str, size_t* used_len) {
...
@@ -480,7 +478,7 @@ Tree::Tree(const char* str, size_t* used_len) {
while
(
read_line
<
max_num_line
)
{
while
(
read_line
<
max_num_line
)
{
if
(
*
p
==
'\r'
||
*
p
==
'\n'
)
break
;
if
(
*
p
==
'\r'
||
*
p
==
'\n'
)
break
;
auto
start
=
p
;
auto
start
=
p
;
while
(
*
p
!=
'='
)
++
p
;
while
(
*
p
!=
'='
)
++
p
;
std
::
string
key
(
start
,
p
-
start
);
std
::
string
key
(
start
,
p
-
start
);
++
p
;
++
p
;
start
=
p
;
start
=
p
;
...
@@ -652,7 +650,6 @@ void Tree::TreeSHAP(const double *feature_values, double *phi,
...
@@ -652,7 +650,6 @@ void Tree::TreeSHAP(const double *feature_values, double *phi,
int
node
,
int
unique_depth
,
int
node
,
int
unique_depth
,
PathElement
*
parent_unique_path
,
double
parent_zero_fraction
,
PathElement
*
parent_unique_path
,
double
parent_zero_fraction
,
double
parent_one_fraction
,
int
parent_feature_index
)
const
{
double
parent_one_fraction
,
int
parent_feature_index
)
const
{
// extend the unique path
// extend the unique path
PathElement
*
unique_path
=
parent_unique_path
+
unique_depth
;
PathElement
*
unique_path
=
parent_unique_path
+
unique_depth
;
if
(
unique_depth
>
0
)
std
::
copy
(
parent_unique_path
,
parent_unique_path
+
unique_depth
,
unique_path
);
if
(
unique_depth
>
0
)
std
::
copy
(
parent_unique_path
,
parent_unique_path
+
unique_depth
,
unique_path
);
...
...
src/lightgbm_R.cpp
View file @
90127b52
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
#define R_API_BEGIN() \
#define R_API_BEGIN() \
try {
try {
#define R_API_END() } \
#define R_API_END() } \
catch(std::exception& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.what()); return call_state;} \
catch(std::exception& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.what()); return call_state;} \
catch(std::string& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.c_str()); return call_state; } \
catch(std::string& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.c_str()); return call_state; } \
...
@@ -54,7 +53,6 @@ LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename,
...
@@ -54,7 +53,6 @@ LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename,
LGBM_SE
reference
,
LGBM_SE
reference
,
LGBM_SE
out
,
LGBM_SE
out
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
DatasetHandle
handle
=
nullptr
;
DatasetHandle
handle
=
nullptr
;
CHECK_CALL
(
LGBM_DatasetCreateFromFile
(
R_CHAR_PTR
(
filename
),
R_CHAR_PTR
(
parameters
),
CHECK_CALL
(
LGBM_DatasetCreateFromFile
(
R_CHAR_PTR
(
filename
),
R_CHAR_PTR
(
parameters
),
...
@@ -96,7 +94,6 @@ LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data,
...
@@ -96,7 +94,6 @@ LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data,
LGBM_SE
reference
,
LGBM_SE
reference
,
LGBM_SE
out
,
LGBM_SE
out
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int32_t
nrow
=
static_cast
<
int32_t
>
(
R_AS_INT
(
num_row
));
int32_t
nrow
=
static_cast
<
int32_t
>
(
R_AS_INT
(
num_row
));
int32_t
ncol
=
static_cast
<
int32_t
>
(
R_AS_INT
(
num_col
));
int32_t
ncol
=
static_cast
<
int32_t
>
(
R_AS_INT
(
num_col
));
...
@@ -114,7 +111,6 @@ LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle,
...
@@ -114,7 +111,6 @@ LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle,
LGBM_SE
parameters
,
LGBM_SE
parameters
,
LGBM_SE
out
,
LGBM_SE
out
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int
len
=
R_AS_INT
(
len_used_row_indices
);
int
len
=
R_AS_INT
(
len_used_row_indices
);
std
::
vector
<
int
>
idxvec
(
len
);
std
::
vector
<
int
>
idxvec
(
len
);
...
@@ -151,7 +147,6 @@ LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle,
...
@@ -151,7 +147,6 @@ LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle,
LGBM_SE
actual_len
,
LGBM_SE
actual_len
,
LGBM_SE
feature_names
,
LGBM_SE
feature_names
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int
len
=
0
;
int
len
=
0
;
CHECK_CALL
(
LGBM_DatasetGetNumFeature
(
R_GET_PTR
(
handle
),
&
len
));
CHECK_CALL
(
LGBM_DatasetGetNumFeature
(
R_GET_PTR
(
handle
),
&
len
));
...
@@ -204,7 +199,7 @@ LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle,
...
@@ -204,7 +199,7 @@ LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle,
vec
[
i
]
=
static_cast
<
int32_t
>
(
R_INT_PTR
(
field_data
)[
i
]);
vec
[
i
]
=
static_cast
<
int32_t
>
(
R_INT_PTR
(
field_data
)[
i
]);
}
}
CHECK_CALL
(
LGBM_DatasetSetField
(
R_GET_PTR
(
handle
),
name
,
vec
.
data
(),
len
,
C_API_DTYPE_INT32
));
CHECK_CALL
(
LGBM_DatasetSetField
(
R_GET_PTR
(
handle
),
name
,
vec
.
data
(),
len
,
C_API_DTYPE_INT32
));
}
else
if
(
!
strcmp
(
"init_score"
,
name
))
{
}
else
if
(
!
strcmp
(
"init_score"
,
name
))
{
CHECK_CALL
(
LGBM_DatasetSetField
(
R_GET_PTR
(
handle
),
name
,
R_REAL_PTR
(
field_data
),
len
,
C_API_DTYPE_FLOAT64
));
CHECK_CALL
(
LGBM_DatasetSetField
(
R_GET_PTR
(
handle
),
name
,
R_REAL_PTR
(
field_data
),
len
,
C_API_DTYPE_FLOAT64
));
}
else
{
}
else
{
std
::
vector
<
float
>
vec
(
len
);
std
::
vector
<
float
>
vec
(
len
);
...
@@ -221,7 +216,6 @@ LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle,
...
@@ -221,7 +216,6 @@ LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle,
LGBM_SE
field_name
,
LGBM_SE
field_name
,
LGBM_SE
field_data
,
LGBM_SE
field_data
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
const
char
*
name
=
R_CHAR_PTR
(
field_name
);
const
char
*
name
=
R_CHAR_PTR
(
field_name
);
int
out_len
=
0
;
int
out_len
=
0
;
...
@@ -256,7 +250,6 @@ LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle,
...
@@ -256,7 +250,6 @@ LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle,
LGBM_SE
field_name
,
LGBM_SE
field_name
,
LGBM_SE
out
,
LGBM_SE
out
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
const
char
*
name
=
R_CHAR_PTR
(
field_name
);
const
char
*
name
=
R_CHAR_PTR
(
field_name
);
int
out_len
=
0
;
int
out_len
=
0
;
...
@@ -323,7 +316,6 @@ LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data,
...
@@ -323,7 +316,6 @@ LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data,
LGBM_SE
LGBM_BoosterCreateFromModelfile_R
(
LGBM_SE
filename
,
LGBM_SE
LGBM_BoosterCreateFromModelfile_R
(
LGBM_SE
filename
,
LGBM_SE
out
,
LGBM_SE
out
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int
out_num_iterations
=
0
;
int
out_num_iterations
=
0
;
BoosterHandle
handle
=
nullptr
;
BoosterHandle
handle
=
nullptr
;
...
@@ -335,7 +327,6 @@ LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename,
...
@@ -335,7 +327,6 @@ LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename,
LGBM_SE
LGBM_BoosterLoadModelFromString_R
(
LGBM_SE
model_str
,
LGBM_SE
LGBM_BoosterLoadModelFromString_R
(
LGBM_SE
model_str
,
LGBM_SE
out
,
LGBM_SE
out
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int
out_num_iterations
=
0
;
int
out_num_iterations
=
0
;
BoosterHandle
handle
=
nullptr
;
BoosterHandle
handle
=
nullptr
;
...
@@ -422,7 +413,6 @@ LGBM_SE LGBM_BoosterRollbackOneIter_R(LGBM_SE handle,
...
@@ -422,7 +413,6 @@ LGBM_SE LGBM_BoosterRollbackOneIter_R(LGBM_SE handle,
LGBM_SE
LGBM_BoosterGetCurrentIteration_R
(
LGBM_SE
handle
,
LGBM_SE
LGBM_BoosterGetCurrentIteration_R
(
LGBM_SE
handle
,
LGBM_SE
out
,
LGBM_SE
out
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
int
out_iteration
;
int
out_iteration
;
R_API_BEGIN
();
R_API_BEGIN
();
CHECK_CALL
(
LGBM_BoosterGetCurrentIteration
(
R_GET_PTR
(
handle
),
&
out_iteration
));
CHECK_CALL
(
LGBM_BoosterGetCurrentIteration
(
R_GET_PTR
(
handle
),
&
out_iteration
));
...
@@ -435,7 +425,6 @@ LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle,
...
@@ -435,7 +425,6 @@ LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle,
LGBM_SE
actual_len
,
LGBM_SE
actual_len
,
LGBM_SE
eval_names
,
LGBM_SE
eval_names
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int
len
;
int
len
;
CHECK_CALL
(
LGBM_BoosterGetEvalCounts
(
R_GET_PTR
(
handle
),
&
len
));
CHECK_CALL
(
LGBM_BoosterGetEvalCounts
(
R_GET_PTR
(
handle
),
&
len
));
...
@@ -552,7 +541,6 @@ LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle,
...
@@ -552,7 +541,6 @@ LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle,
LGBM_SE
parameter
,
LGBM_SE
parameter
,
LGBM_SE
out_result
,
LGBM_SE
out_result
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int
pred_type
=
GetPredictType
(
is_rawscore
,
is_leafidx
,
is_predcontrib
);
int
pred_type
=
GetPredictType
(
is_rawscore
,
is_leafidx
,
is_predcontrib
);
...
@@ -583,7 +571,6 @@ LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle,
...
@@ -583,7 +571,6 @@ LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle,
LGBM_SE
parameter
,
LGBM_SE
parameter
,
LGBM_SE
out_result
,
LGBM_SE
out_result
,
LGBM_SE
call_state
)
{
LGBM_SE
call_state
)
{
R_API_BEGIN
();
R_API_BEGIN
();
int
pred_type
=
GetPredictType
(
is_rawscore
,
is_leafidx
,
is_predcontrib
);
int
pred_type
=
GetPredictType
(
is_rawscore
,
is_leafidx
,
is_predcontrib
);
...
...
src/metric/binary_metric.hpp
View file @
90127b52
...
@@ -20,11 +20,9 @@ template<typename PointWiseLossCalculator>
...
@@ -20,11 +20,9 @@ template<typename PointWiseLossCalculator>
class
BinaryMetric
:
public
Metric
{
class
BinaryMetric
:
public
Metric
{
public:
public:
explicit
BinaryMetric
(
const
Config
&
)
{
explicit
BinaryMetric
(
const
Config
&
)
{
}
}
virtual
~
BinaryMetric
()
{
virtual
~
BinaryMetric
()
{
}
}
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
...
@@ -157,7 +155,6 @@ public:
...
@@ -157,7 +155,6 @@ public:
class
AUCMetric
:
public
Metric
{
class
AUCMetric
:
public
Metric
{
public:
public:
explicit
AUCMetric
(
const
Config
&
)
{
explicit
AUCMetric
(
const
Config
&
)
{
}
}
virtual
~
AUCMetric
()
{
virtual
~
AUCMetric
()
{
...
...
src/metric/multiclass_metric.hpp
View file @
90127b52
...
@@ -20,11 +20,9 @@ public:
...
@@ -20,11 +20,9 @@ public:
}
}
virtual
~
MulticlassMetric
()
{
virtual
~
MulticlassMetric
()
{
}
}
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
name_
.
emplace_back
(
PointWiseLossCalculator
::
Name
());
name_
.
emplace_back
(
PointWiseLossCalculator
::
Name
());
num_data_
=
num_data
;
num_data_
=
num_data
;
// get label
// get label
...
...
src/metric/regression_metric.hpp
View file @
90127b52
...
@@ -19,7 +19,6 @@ public:
...
@@ -19,7 +19,6 @@ public:
}
}
virtual
~
RegressionMetric
()
{
virtual
~
RegressionMetric
()
{
}
}
const
std
::
vector
<
std
::
string
>&
GetName
()
const
override
{
const
std
::
vector
<
std
::
string
>&
GetName
()
const
override
{
...
@@ -87,7 +86,6 @@ public:
...
@@ -87,7 +86,6 @@ public:
}
}
double
loss
=
PointWiseLossCalculator
::
AverageLoss
(
sum_loss
,
sum_weights_
);
double
loss
=
PointWiseLossCalculator
::
AverageLoss
(
sum_loss
,
sum_weights_
);
return
std
::
vector
<
double
>
(
1
,
loss
);
return
std
::
vector
<
double
>
(
1
,
loss
);
}
}
inline
static
double
AverageLoss
(
double
sum_loss
,
double
sum_weights
)
{
inline
static
double
AverageLoss
(
double
sum_loss
,
double
sum_weights
)
{
...
@@ -259,7 +257,7 @@ public:
...
@@ -259,7 +257,7 @@ public:
const
double
theta
=
-
1.0
/
score
;
const
double
theta
=
-
1.0
/
score
;
const
double
a
=
psi
;
const
double
a
=
psi
;
const
double
b
=
-
Common
::
SafeLog
(
-
theta
);
const
double
b
=
-
Common
::
SafeLog
(
-
theta
);
const
double
c
=
1.
/
psi
*
Common
::
SafeLog
(
label
/
psi
)
-
Common
::
SafeLog
(
label
)
-
0
;
// 0 = std::lgamma(1.0 / psi) = std::lgamma(1.0);
const
double
c
=
1.
/
psi
*
Common
::
SafeLog
(
label
/
psi
)
-
Common
::
SafeLog
(
label
)
-
0
;
// 0 = std::lgamma(1.0 / psi) = std::lgamma(1.0);
return
-
((
label
*
theta
-
b
)
/
a
+
c
);
return
-
((
label
*
theta
-
b
)
/
a
+
c
);
}
}
inline
static
const
char
*
Name
()
{
inline
static
const
char
*
Name
()
{
...
...
src/metric/xentropy_metric.hpp
View file @
90127b52
...
@@ -66,7 +66,7 @@ namespace LightGBM {
...
@@ -66,7 +66,7 @@ namespace LightGBM {
//
//
class
CrossEntropyMetric
:
public
Metric
{
class
CrossEntropyMetric
:
public
Metric
{
public:
public:
explicit
CrossEntropyMetric
(
const
Config
&
)
{}
explicit
CrossEntropyMetric
(
const
Config
&
)
{}
virtual
~
CrossEntropyMetric
()
{}
virtual
~
CrossEntropyMetric
()
{}
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
...
@@ -105,12 +105,12 @@ public:
...
@@ -105,12 +105,12 @@ public:
if
(
weights_
==
nullptr
)
{
if
(
weights_
==
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
]);
// NOTE: does not work unless score is a probability
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
]);
// NOTE: does not work unless score is a probability
}
}
}
else
{
}
else
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
])
*
weights_
[
i
];
// NOTE: does not work unless score is a probability
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
])
*
weights_
[
i
];
// NOTE: does not work unless score is a probability
}
}
}
}
}
else
{
}
else
{
...
@@ -139,7 +139,7 @@ public:
...
@@ -139,7 +139,7 @@ public:
}
}
double
factor_to_bigger_better
()
const
override
{
double
factor_to_bigger_better
()
const
override
{
return
-
1.0
f
;
// negative means smaller loss is better, positive means larger loss is better
return
-
1.0
f
;
// negative means smaller loss is better, positive means larger loss is better
}
}
private:
private:
...
@@ -182,7 +182,6 @@ public:
...
@@ -182,7 +182,6 @@ public:
Log
::
Fatal
(
"[%s:%s]: (metric) all weights must be positive"
,
GetName
()[
0
].
c_str
(),
__func__
);
Log
::
Fatal
(
"[%s:%s]: (metric) all weights must be positive"
,
GetName
()[
0
].
c_str
(),
__func__
);
}
}
}
}
}
}
std
::
vector
<
double
>
Eval
(
const
double
*
score
,
const
ObjectiveFunction
*
objective
)
const
override
{
std
::
vector
<
double
>
Eval
(
const
double
*
score
,
const
ObjectiveFunction
*
objective
)
const
override
{
...
@@ -191,13 +190,13 @@ public:
...
@@ -191,13 +190,13 @@ public:
if
(
weights_
==
nullptr
)
{
if
(
weights_
==
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
double
hhat
=
std
::
log
(
1.0
f
+
std
::
exp
(
score
[
i
]));
// auto-convert
double
hhat
=
std
::
log
(
1.0
f
+
std
::
exp
(
score
[
i
]));
// auto-convert
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
1.0
f
,
hhat
);
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
1.0
f
,
hhat
);
}
}
}
else
{
}
else
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
double
hhat
=
std
::
log
(
1.0
f
+
std
::
exp
(
score
[
i
]));
// auto-convert
double
hhat
=
std
::
log
(
1.0
f
+
std
::
exp
(
score
[
i
]));
// auto-convert
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
weights_
[
i
],
hhat
);
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
weights_
[
i
],
hhat
);
}
}
}
}
...
@@ -206,14 +205,14 @@ public:
...
@@ -206,14 +205,14 @@ public:
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
double
hhat
=
0
;
double
hhat
=
0
;
objective
->
ConvertOutput
(
&
score
[
i
],
&
hhat
);
// NOTE: this only works if objective = "xentlambda"
objective
->
ConvertOutput
(
&
score
[
i
],
&
hhat
);
// NOTE: this only works if objective = "xentlambda"
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
1.0
f
,
hhat
);
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
1.0
f
,
hhat
);
}
}
}
else
{
}
else
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
double
hhat
=
0
;
double
hhat
=
0
;
objective
->
ConvertOutput
(
&
score
[
i
],
&
hhat
);
// NOTE: this only works if objective = "xentlambda"
objective
->
ConvertOutput
(
&
score
[
i
],
&
hhat
);
// NOTE: this only works if objective = "xentlambda"
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
weights_
[
i
],
hhat
);
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
weights_
[
i
],
hhat
);
}
}
}
}
...
@@ -300,12 +299,12 @@ public:
...
@@ -300,12 +299,12 @@ public:
if
(
weights_
==
nullptr
)
{
if
(
weights_
==
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
]);
// NOTE: does not work unless score is a probability
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
]);
// NOTE: does not work unless score is a probability
}
}
}
else
{
}
else
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
])
*
weights_
[
i
];
// NOTE: does not work unless score is a probability
sum_loss
+=
XentLoss
(
label_
[
i
],
score
[
i
])
*
weights_
[
i
];
// NOTE: does not work unless score is a probability
}
}
}
}
}
else
{
}
else
{
...
@@ -352,6 +351,6 @@ private:
...
@@ -352,6 +351,6 @@ private:
std
::
vector
<
std
::
string
>
name_
;
std
::
vector
<
std
::
string
>
name_
;
};
};
}
// end namespace LightGBM
}
// end namespace LightGBM
#endif // end #ifndef LIGHTGBM_METRIC_XENTROPY_METRIC_HPP_
#endif
// end #ifndef LIGHTGBM_METRIC_XENTROPY_METRIC_HPP_
src/network/linkers.h
View file @
90127b52
...
@@ -222,9 +222,8 @@ inline void Linkers::Recv(int rank, char* data, int len) const {
...
@@ -222,9 +222,8 @@ inline void Linkers::Recv(int rank, char* data, int len) const {
int
recv_cnt
=
0
;
int
recv_cnt
=
0
;
while
(
recv_cnt
<
len
)
{
while
(
recv_cnt
<
len
)
{
recv_cnt
+=
linkers_
[
rank
]
->
Recv
(
data
+
recv_cnt
,
recv_cnt
+=
linkers_
[
rank
]
->
Recv
(
data
+
recv_cnt
,
//len - recv_cnt
// len - recv_cnt
std
::
min
(
len
-
recv_cnt
,
SocketConfig
::
kMaxReceiveSize
)
std
::
min
(
len
-
recv_cnt
,
SocketConfig
::
kMaxReceiveSize
));
);
}
}
}
}
...
...
src/network/linkers_mpi.cpp
View file @
90127b52
...
@@ -29,4 +29,4 @@ Linkers::~Linkers() {
...
@@ -29,4 +29,4 @@ Linkers::~Linkers() {
}
// namespace LightGBM
}
// namespace LightGBM
#endif // USE_MPI
#endif
// USE_MPI
src/network/linkers_socket.cpp
View file @
90127b52
...
@@ -117,7 +117,6 @@ void Linkers::ParseMachineList(const std::string& machines, const std::string& f
...
@@ -117,7 +117,6 @@ void Linkers::ParseMachineList(const std::string& machines, const std::string& f
Log
::
Warning
(
"World size is larger than the machine_list size, change world size to %d"
,
client_ips_
.
size
());
Log
::
Warning
(
"World size is larger than the machine_list size, change world size to %d"
,
client_ips_
.
size
());
num_machines_
=
static_cast
<
int
>
(
client_ips_
.
size
());
num_machines_
=
static_cast
<
int
>
(
client_ips_
.
size
());
}
}
}
}
void
Linkers
::
TryBind
(
int
port
)
{
void
Linkers
::
TryBind
(
int
port
)
{
...
...
src/network/network.cpp
View file @
90127b52
...
@@ -137,7 +137,7 @@ void Network::Allgather(char* input, const comm_size_t* block_start, const comm_
...
@@ -137,7 +137,7 @@ void Network::Allgather(char* input, const comm_size_t* block_start, const comm_
if
(
allgather_ext_fun_
!=
nullptr
)
{
if
(
allgather_ext_fun_
!=
nullptr
)
{
return
allgather_ext_fun_
(
input
,
block_len
[
rank_
],
block_start
,
block_len
,
num_machines_
,
output
,
all_size
);
return
allgather_ext_fun_
(
input
,
block_len
[
rank_
],
block_start
,
block_len
,
num_machines_
,
output
,
all_size
);
}
}
const
comm_size_t
kRingThreshold
=
10
*
1024
*
1024
;
// 10MB
const
comm_size_t
kRingThreshold
=
10
*
1024
*
1024
;
// 10MB
const
int
kRingNodeThreshold
=
64
;
const
int
kRingNodeThreshold
=
64
;
if
(
all_size
>
kRingThreshold
&&
num_machines_
<
kRingNodeThreshold
)
{
if
(
all_size
>
kRingThreshold
&&
num_machines_
<
kRingNodeThreshold
)
{
// when num_machines is small and data is large
// when num_machines is small and data is large
...
@@ -234,7 +234,7 @@ void Network::ReduceScatter(char* input, comm_size_t input_size, int type_size,
...
@@ -234,7 +234,7 @@ void Network::ReduceScatter(char* input, comm_size_t input_size, int type_size,
if
(
reduce_scatter_ext_fun_
!=
nullptr
)
{
if
(
reduce_scatter_ext_fun_
!=
nullptr
)
{
return
reduce_scatter_ext_fun_
(
input
,
input_size
,
type_size
,
block_start
,
block_len
,
num_machines_
,
output
,
output_size
,
reducer
);
return
reduce_scatter_ext_fun_
(
input
,
input_size
,
type_size
,
block_start
,
block_len
,
num_machines_
,
output
,
output_size
,
reducer
);
}
}
const
comm_size_t
kRingThreshold
=
10
*
1024
*
1024
;
// 10MB
const
comm_size_t
kRingThreshold
=
10
*
1024
*
1024
;
// 10MB
if
(
recursive_halving_map_
.
is_power_of_2
||
input_size
<
kRingThreshold
)
{
if
(
recursive_halving_map_
.
is_power_of_2
||
input_size
<
kRingThreshold
)
{
ReduceScatterRecursiveHalving
(
input
,
input_size
,
type_size
,
block_start
,
block_len
,
output
,
output_size
,
reducer
);
ReduceScatterRecursiveHalving
(
input
,
input_size
,
type_size
,
block_start
,
block_len
,
output
,
output_size
,
reducer
);
}
else
{
}
else
{
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment