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
9bf2de1e
Commit
9bf2de1e
authored
Aug 25, 2018
by
dmitryikh
Committed by
Guolin Ke
Aug 25, 2018
Browse files
Small optimizations and fixes (#1607)
* fix optimization rule * preallocate vector in RowFunctionFromCSR
parent
244db078
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
src/application/predictor.hpp
src/application/predictor.hpp
+1
-1
src/c_api.cpp
src/c_api.cpp
+12
-0
No files found.
src/application/predictor.hpp
View file @
9bf2de1e
...
...
@@ -220,7 +220,7 @@ private:
}
void
ClearPredictBuffer
(
double
*
pred_buf
,
size_t
buf_size
,
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
)
{
if
(
features
.
size
()
<
static_cast
<
size_t
>
(
buf_size
/
2
))
{
if
(
features
.
size
()
>
static_cast
<
size_t
>
(
buf_size
/
2
))
{
std
::
memset
(
pred_buf
,
0
,
sizeof
(
double
)
*
(
buf_size
));
}
else
{
int
loop_size
=
static_cast
<
int
>
(
features
.
size
());
...
...
src/c_api.cpp
View file @
9bf2de1e
...
...
@@ -1382,6 +1382,9 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
std
::
vector
<
std
::
pair
<
int
,
double
>>
ret
;
int64_t
start
=
ptr_indptr
[
idx
];
int64_t
end
=
ptr_indptr
[
idx
+
1
];
if
(
end
-
start
>
0
)
{
ret
.
reserve
(
end
-
start
);
}
for
(
int64_t
i
=
start
;
i
<
end
;
++
i
)
{
ret
.
emplace_back
(
indices
[
i
],
data_ptr
[
i
]);
}
...
...
@@ -1393,6 +1396,9 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
std
::
vector
<
std
::
pair
<
int
,
double
>>
ret
;
int64_t
start
=
ptr_indptr
[
idx
];
int64_t
end
=
ptr_indptr
[
idx
+
1
];
if
(
end
-
start
>
0
)
{
ret
.
reserve
(
end
-
start
);
}
for
(
int64_t
i
=
start
;
i
<
end
;
++
i
)
{
ret
.
emplace_back
(
indices
[
i
],
data_ptr
[
i
]);
}
...
...
@@ -1407,6 +1413,9 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
std
::
vector
<
std
::
pair
<
int
,
double
>>
ret
;
int64_t
start
=
ptr_indptr
[
idx
];
int64_t
end
=
ptr_indptr
[
idx
+
1
];
if
(
end
-
start
>
0
)
{
ret
.
reserve
(
end
-
start
);
}
for
(
int64_t
i
=
start
;
i
<
end
;
++
i
)
{
ret
.
emplace_back
(
indices
[
i
],
data_ptr
[
i
]);
}
...
...
@@ -1418,6 +1427,9 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
std
::
vector
<
std
::
pair
<
int
,
double
>>
ret
;
int64_t
start
=
ptr_indptr
[
idx
];
int64_t
end
=
ptr_indptr
[
idx
+
1
];
if
(
end
-
start
>
0
)
{
ret
.
reserve
(
end
-
start
);
}
for
(
int64_t
i
=
start
;
i
<
end
;
++
i
)
{
ret
.
emplace_back
(
indices
[
i
],
data_ptr
[
i
]);
}
...
...
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