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
81d4d4d1
Unverified
Commit
81d4d4d1
authored
Aug 30, 2022
by
James Lamb
Committed by
GitHub
Aug 30, 2022
Browse files
[python-package] fix type hints on ctypes array converters (#5446)
[python-package] fix type hints on cptr converters
parent
4162485d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+4
-4
No files found.
python-package/lightgbm/basic.py
View file @
81d4d4d1
...
@@ -255,7 +255,7 @@ def _data_to_2d_numpy(data: Any, dtype: type = np.float32, name: str = 'list') -
...
@@ -255,7 +255,7 @@ def _data_to_2d_numpy(data: Any, dtype: type = np.float32, name: str = 'list') -
"It should be list of lists, numpy 2-D array or pandas DataFrame"
)
"It should be list of lists, numpy 2-D array or pandas DataFrame"
)
def
cfloat32_array_to_numpy
(
cptr
:
ctypes
.
POINTER
,
length
:
int
)
->
np
.
ndarray
:
def
cfloat32_array_to_numpy
(
cptr
:
Any
,
length
:
int
)
->
np
.
ndarray
:
"""Convert a ctypes float pointer array to a numpy array."""
"""Convert a ctypes float pointer array to a numpy array."""
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_float
)):
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_float
)):
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
...
@@ -263,7 +263,7 @@ def cfloat32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
...
@@ -263,7 +263,7 @@ def cfloat32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
raise
RuntimeError
(
'Expected float pointer'
)
raise
RuntimeError
(
'Expected float pointer'
)
def
cfloat64_array_to_numpy
(
cptr
:
ctypes
.
POINTER
,
length
:
int
)
->
np
.
ndarray
:
def
cfloat64_array_to_numpy
(
cptr
:
Any
,
length
:
int
)
->
np
.
ndarray
:
"""Convert a ctypes double pointer array to a numpy array."""
"""Convert a ctypes double pointer array to a numpy array."""
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_double
)):
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_double
)):
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
...
@@ -271,7 +271,7 @@ def cfloat64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
...
@@ -271,7 +271,7 @@ def cfloat64_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
raise
RuntimeError
(
'Expected double pointer'
)
raise
RuntimeError
(
'Expected double pointer'
)
def
cint32_array_to_numpy
(
cptr
:
ctypes
.
POINTER
,
length
:
int
)
->
np
.
ndarray
:
def
cint32_array_to_numpy
(
cptr
:
Any
,
length
:
int
)
->
np
.
ndarray
:
"""Convert a ctypes int pointer array to a numpy array."""
"""Convert a ctypes int pointer array to a numpy array."""
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_int32
)):
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_int32
)):
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
...
@@ -279,7 +279,7 @@ def cint32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
...
@@ -279,7 +279,7 @@ def cint32_array_to_numpy(cptr: ctypes.POINTER, length: int) -> np.ndarray:
raise
RuntimeError
(
'Expected int32 pointer'
)
raise
RuntimeError
(
'Expected int32 pointer'
)
def
cint64_array_to_numpy
(
cptr
:
ctypes
.
POINTER
,
length
:
int
)
->
np
.
ndarray
:
def
cint64_array_to_numpy
(
cptr
:
Any
,
length
:
int
)
->
np
.
ndarray
:
"""Convert a ctypes int pointer array to a numpy array."""
"""Convert a ctypes int pointer array to a numpy array."""
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_int64
)):
if
isinstance
(
cptr
,
ctypes
.
POINTER
(
ctypes
.
c_int64
)):
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
return
np
.
ctypeslib
.
as_array
(
cptr
,
shape
=
(
length
,)).
copy
()
...
...
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