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
08c38efc
Unverified
Commit
08c38efc
authored
May 17, 2021
by
Nikita Titov
Committed by
GitHub
May 17, 2021
Browse files
[python] Handle integer types more accurate in Python-to-C interface (#4292)
parent
b423cb47
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+17
-17
No files found.
python-package/lightgbm/basic.py
View file @
08c38efc
...
@@ -786,8 +786,8 @@ class _InnerPredictor:
...
@@ -786,8 +786,8 @@ class _InnerPredictor:
self
.
handle
,
self
.
handle
,
ptr_data
,
ptr_data
,
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
mat
.
shape
[
0
]),
ctypes
.
c_int
32
(
mat
.
shape
[
0
]),
ctypes
.
c_int
(
mat
.
shape
[
1
]),
ctypes
.
c_int
32
(
mat
.
shape
[
1
]),
ctypes
.
c_int
(
C_API_IS_ROW_MAJOR
),
ctypes
.
c_int
(
C_API_IS_ROW_MAJOR
),
ctypes
.
c_int
(
predict_type
),
ctypes
.
c_int
(
predict_type
),
ctypes
.
c_int
(
start_iteration
),
ctypes
.
c_int
(
start_iteration
),
...
@@ -880,7 +880,7 @@ class _InnerPredictor:
...
@@ -880,7 +880,7 @@ class _InnerPredictor:
_safe_call
(
_LIB
.
LGBM_BoosterPredictForCSR
(
_safe_call
(
_LIB
.
LGBM_BoosterPredictForCSR
(
self
.
handle
,
self
.
handle
,
ptr_indptr
,
ptr_indptr
,
ctypes
.
c_int
32
(
type_ptr_indptr
),
ctypes
.
c_int
(
type_ptr_indptr
),
csr_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
csr_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
ptr_data
,
ptr_data
,
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
type_ptr_data
),
...
@@ -915,7 +915,7 @@ class _InnerPredictor:
...
@@ -915,7 +915,7 @@ class _InnerPredictor:
_safe_call
(
_LIB
.
LGBM_BoosterPredictSparseOutput
(
_safe_call
(
_LIB
.
LGBM_BoosterPredictSparseOutput
(
self
.
handle
,
self
.
handle
,
ptr_indptr
,
ptr_indptr
,
ctypes
.
c_int
32
(
type_ptr_indptr
),
ctypes
.
c_int
(
type_ptr_indptr
),
csr_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
csr_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
ptr_data
,
ptr_data
,
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
type_ptr_data
),
...
@@ -973,7 +973,7 @@ class _InnerPredictor:
...
@@ -973,7 +973,7 @@ class _InnerPredictor:
_safe_call
(
_LIB
.
LGBM_BoosterPredictSparseOutput
(
_safe_call
(
_LIB
.
LGBM_BoosterPredictSparseOutput
(
self
.
handle
,
self
.
handle
,
ptr_indptr
,
ptr_indptr
,
ctypes
.
c_int
32
(
type_ptr_indptr
),
ctypes
.
c_int
(
type_ptr_indptr
),
csc_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
csc_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
ptr_data
,
ptr_data
,
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
type_ptr_data
),
...
@@ -1012,7 +1012,7 @@ class _InnerPredictor:
...
@@ -1012,7 +1012,7 @@ class _InnerPredictor:
_safe_call
(
_LIB
.
LGBM_BoosterPredictForCSC
(
_safe_call
(
_LIB
.
LGBM_BoosterPredictForCSC
(
self
.
handle
,
self
.
handle
,
ptr_indptr
,
ptr_indptr
,
ctypes
.
c_int
32
(
type_ptr_indptr
),
ctypes
.
c_int
(
type_ptr_indptr
),
csc_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
csc_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
ptr_data
,
ptr_data
,
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
type_ptr_data
),
...
@@ -1306,8 +1306,8 @@ class Dataset:
...
@@ -1306,8 +1306,8 @@ class Dataset:
_safe_call
(
_LIB
.
LGBM_DatasetCreateFromMat
(
_safe_call
(
_LIB
.
LGBM_DatasetCreateFromMat
(
ptr_data
,
ptr_data
,
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
mat
.
shape
[
0
]),
ctypes
.
c_int
32
(
mat
.
shape
[
0
]),
ctypes
.
c_int
(
mat
.
shape
[
1
]),
ctypes
.
c_int
32
(
mat
.
shape
[
1
]),
ctypes
.
c_int
(
C_API_IS_ROW_MAJOR
),
ctypes
.
c_int
(
C_API_IS_ROW_MAJOR
),
c_str
(
params_str
),
c_str
(
params_str
),
ref_dataset
,
ref_dataset
,
...
@@ -1349,11 +1349,11 @@ class Dataset:
...
@@ -1349,11 +1349,11 @@ class Dataset:
self
.
handle
=
ctypes
.
c_void_p
()
self
.
handle
=
ctypes
.
c_void_p
()
_safe_call
(
_LIB
.
LGBM_DatasetCreateFromMats
(
_safe_call
(
_LIB
.
LGBM_DatasetCreateFromMats
(
ctypes
.
c_int
(
len
(
mats
)),
ctypes
.
c_int
32
(
len
(
mats
)),
ctypes
.
cast
(
ptr_data
,
ctypes
.
POINTER
(
ctypes
.
POINTER
(
ctypes
.
c_double
))),
ctypes
.
cast
(
ptr_data
,
ctypes
.
POINTER
(
ctypes
.
POINTER
(
ctypes
.
c_double
))),
ctypes
.
c_int
(
type_ptr_data
),
ctypes
.
c_int
(
type_ptr_data
),
nrow
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
nrow
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
ctypes
.
c_int
(
ncol
),
ctypes
.
c_int
32
(
ncol
),
ctypes
.
c_int
(
C_API_IS_ROW_MAJOR
),
ctypes
.
c_int
(
C_API_IS_ROW_MAJOR
),
c_str
(
params_str
),
c_str
(
params_str
),
ref_dataset
,
ref_dataset
,
...
@@ -1445,7 +1445,7 @@ class Dataset:
...
@@ -1445,7 +1445,7 @@ class Dataset:
_safe_call
(
_LIB
.
LGBM_DatasetGetSubset
(
_safe_call
(
_LIB
.
LGBM_DatasetGetSubset
(
self
.
reference
.
construct
().
handle
,
self
.
reference
.
construct
().
handle
,
used_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
used_indices
.
ctypes
.
data_as
(
ctypes
.
POINTER
(
ctypes
.
c_int32
)),
ctypes
.
c_int
(
used_indices
.
shape
[
0
]),
ctypes
.
c_int
32
(
used_indices
.
shape
[
0
]),
c_str
(
params_str
),
c_str
(
params_str
),
ctypes
.
byref
(
self
.
handle
)))
ctypes
.
byref
(
self
.
handle
)))
if
not
self
.
free_raw_data
:
if
not
self
.
free_raw_data
:
...
@@ -1651,8 +1651,8 @@ class Dataset:
...
@@ -1651,8 +1651,8 @@ class Dataset:
"""
"""
if
self
.
handle
is
None
:
if
self
.
handle
is
None
:
raise
Exception
(
f
"Cannot get
{
field_name
}
before construct Dataset"
)
raise
Exception
(
f
"Cannot get
{
field_name
}
before construct Dataset"
)
tmp_out_len
=
ctypes
.
c_int
()
tmp_out_len
=
ctypes
.
c_int
(
0
)
out_type
=
ctypes
.
c_int
()
out_type
=
ctypes
.
c_int
(
0
)
ret
=
ctypes
.
POINTER
(
ctypes
.
c_void_p
)()
ret
=
ctypes
.
POINTER
(
ctypes
.
c_void_p
)()
_safe_call
(
_LIB
.
LGBM_DatasetGetField
(
_safe_call
(
_LIB
.
LGBM_DatasetGetField
(
self
.
handle
,
self
.
handle
,
...
@@ -1985,7 +1985,7 @@ class Dataset:
...
@@ -1985,7 +1985,7 @@ class Dataset:
The number of rows in the Dataset.
The number of rows in the Dataset.
"""
"""
if
self
.
handle
is
not
None
:
if
self
.
handle
is
not
None
:
ret
=
ctypes
.
c_int
()
ret
=
ctypes
.
c_int
(
0
)
_safe_call
(
_LIB
.
LGBM_DatasetGetNumData
(
self
.
handle
,
_safe_call
(
_LIB
.
LGBM_DatasetGetNumData
(
self
.
handle
,
ctypes
.
byref
(
ret
)))
ctypes
.
byref
(
ret
)))
return
ret
.
value
return
ret
.
value
...
@@ -2001,7 +2001,7 @@ class Dataset:
...
@@ -2001,7 +2001,7 @@ class Dataset:
The number of columns (features) in the Dataset.
The number of columns (features) in the Dataset.
"""
"""
if
self
.
handle
is
not
None
:
if
self
.
handle
is
not
None
:
ret
=
ctypes
.
c_int
()
ret
=
ctypes
.
c_int
(
0
)
_safe_call
(
_LIB
.
LGBM_DatasetGetNumFeature
(
self
.
handle
,
_safe_call
(
_LIB
.
LGBM_DatasetGetNumFeature
(
self
.
handle
,
ctypes
.
byref
(
ret
)))
ctypes
.
byref
(
ret
)))
return
ret
.
value
return
ret
.
value
...
@@ -3185,8 +3185,8 @@ class Booster:
...
@@ -3185,8 +3185,8 @@ class Booster:
_safe_call
(
_LIB
.
LGBM_BoosterRefit
(
_safe_call
(
_LIB
.
LGBM_BoosterRefit
(
new_booster
.
handle
,
new_booster
.
handle
,
ptr_data
,
ptr_data
,
ctypes
.
c_int
(
nrow
),
ctypes
.
c_int
32
(
nrow
),
ctypes
.
c_int
(
ncol
)))
ctypes
.
c_int
32
(
ncol
)))
new_booster
.
network
=
self
.
network
new_booster
.
network
=
self
.
network
new_booster
.
__attr
=
self
.
__attr
.
copy
()
new_booster
.
__attr
=
self
.
__attr
.
copy
()
return
new_booster
return
new_booster
...
...
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