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
60a4a13e
Unverified
Commit
60a4a13e
authored
Sep 25, 2023
by
James Lamb
Committed by
GitHub
Sep 25, 2023
Browse files
[python-package] remove unnecessary allocations in ctypes code (#6111)
parent
7c9a985a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+8
-8
No files found.
python-package/lightgbm/basic.py
View file @
60a4a13e
...
...
@@ -479,7 +479,7 @@ class _ConfigAliases:
buffer_len
=
1
<<
20
tmp_out_len
=
ctypes
.
c_int64
(
0
)
string_buffer
=
ctypes
.
create_string_buffer
(
buffer_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_DumpParamAliases
(
ctypes
.
c_int64
(
buffer_len
),
ctypes
.
byref
(
tmp_out_len
),
...
...
@@ -488,7 +488,7 @@ class _ConfigAliases:
# if buffer length is not long enough, re-allocate a buffer
if
actual_len
>
buffer_len
:
string_buffer
=
ctypes
.
create_string_buffer
(
actual_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_DumpParamAliases
(
ctypes
.
c_int64
(
actual_len
),
ctypes
.
byref
(
tmp_out_len
),
...
...
@@ -3315,7 +3315,7 @@ class Booster:
buffer_len
=
1
<<
20
tmp_out_len
=
ctypes
.
c_int64
(
0
)
string_buffer
=
ctypes
.
create_string_buffer
(
buffer_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_BoosterGetLoadedParam
(
self
.
_handle
,
ctypes
.
c_int64
(
buffer_len
),
...
...
@@ -3325,7 +3325,7 @@ class Booster:
# if buffer length is not long enough, re-allocate a buffer
if
actual_len
>
buffer_len
:
string_buffer
=
ctypes
.
create_string_buffer
(
actual_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_BoosterGetLoadedParam
(
self
.
_handle
,
ctypes
.
c_int64
(
actual_len
),
...
...
@@ -4078,7 +4078,7 @@ class Booster:
buffer_len
=
1
<<
20
tmp_out_len
=
ctypes
.
c_int64
(
0
)
string_buffer
=
ctypes
.
create_string_buffer
(
buffer_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_BoosterSaveModelToString
(
self
.
_handle
,
ctypes
.
c_int
(
start_iteration
),
...
...
@@ -4091,7 +4091,7 @@ class Booster:
# if buffer length is not long enough, re-allocate a buffer
if
actual_len
>
buffer_len
:
string_buffer
=
ctypes
.
create_string_buffer
(
actual_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_BoosterSaveModelToString
(
self
.
_handle
,
ctypes
.
c_int
(
start_iteration
),
...
...
@@ -4146,7 +4146,7 @@ class Booster:
buffer_len
=
1
<<
20
tmp_out_len
=
ctypes
.
c_int64
(
0
)
string_buffer
=
ctypes
.
create_string_buffer
(
buffer_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_BoosterDumpModel
(
self
.
_handle
,
ctypes
.
c_int
(
start_iteration
),
...
...
@@ -4159,7 +4159,7 @@ class Booster:
# if buffer length is not long enough, reallocate a buffer
if
actual_len
>
buffer_len
:
string_buffer
=
ctypes
.
create_string_buffer
(
actual_len
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
*
[
ctypes
.
addressof
(
string_buffer
)
]
)
ptr_string_buffer
=
ctypes
.
c_char_p
(
ctypes
.
addressof
(
string_buffer
))
_safe_call
(
_LIB
.
LGBM_BoosterDumpModel
(
self
.
_handle
,
ctypes
.
c_int
(
start_iteration
),
...
...
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