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
03469ae5
Unverified
Commit
03469ae5
authored
Jul 05, 2021
by
Nikita Titov
Committed by
GitHub
Jul 04, 2021
Browse files
[tests][python] refactor file loading routine in C API test (#4437)
* refactor file loading in C API test * continue
parent
29052c5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
34 deletions
+11
-34
tests/c_api_test/test_.py
tests/c_api_test/test_.py
+11
-34
No files found.
tests/c_api_test/test_.py
View file @
03469ae5
...
@@ -80,16 +80,9 @@ def save_to_binary(handle, filename):
...
@@ -80,16 +80,9 @@ def save_to_binary(handle, filename):
def
load_from_csr
(
filename
,
reference
):
def
load_from_csr
(
filename
,
reference
):
data
=
[]
data
=
np
.
loadtxt
(
str
(
filename
),
dtype
=
np
.
float64
)
label
=
[]
csr
=
sparse
.
csr_matrix
(
data
[:,
1
:])
with
open
(
filename
,
'r'
)
as
inp
:
label
=
data
[:,
0
].
astype
(
np
.
float32
)
for
line
in
inp
.
readlines
():
values
=
line
.
split
(
'
\t
'
)
data
.
append
([
float
(
x
)
for
x
in
values
[
1
:]])
label
.
append
(
float
(
values
[
0
]))
mat
=
np
.
array
(
data
,
dtype
=
np
.
float64
)
label
=
np
.
array
(
label
,
dtype
=
np
.
float32
)
csr
=
sparse
.
csr_matrix
(
mat
)
handle
=
ctypes
.
c_void_p
()
handle
=
ctypes
.
c_void_p
()
ref
=
None
ref
=
None
if
reference
is
not
None
:
if
reference
is
not
None
:
...
@@ -122,16 +115,9 @@ def load_from_csr(filename, reference):
...
@@ -122,16 +115,9 @@ def load_from_csr(filename, reference):
def
load_from_csc
(
filename
,
reference
):
def
load_from_csc
(
filename
,
reference
):
data
=
[]
data
=
np
.
loadtxt
(
str
(
filename
),
dtype
=
np
.
float64
)
label
=
[]
csc
=
sparse
.
csc_matrix
(
data
[:,
1
:])
with
open
(
filename
,
'r'
)
as
inp
:
label
=
data
[:,
0
].
astype
(
np
.
float32
)
for
line
in
inp
.
readlines
():
values
=
line
.
split
(
'
\t
'
)
data
.
append
([
float
(
x
)
for
x
in
values
[
1
:]])
label
.
append
(
float
(
values
[
0
]))
mat
=
np
.
array
(
data
,
dtype
=
np
.
float64
)
label
=
np
.
array
(
label
,
dtype
=
np
.
float32
)
csc
=
sparse
.
csc_matrix
(
mat
)
handle
=
ctypes
.
c_void_p
()
handle
=
ctypes
.
c_void_p
()
ref
=
None
ref
=
None
if
reference
is
not
None
:
if
reference
is
not
None
:
...
@@ -164,16 +150,10 @@ def load_from_csc(filename, reference):
...
@@ -164,16 +150,10 @@ def load_from_csc(filename, reference):
def
load_from_mat
(
filename
,
reference
):
def
load_from_mat
(
filename
,
reference
):
data
=
[]
mat
=
np
.
loadtxt
(
str
(
filename
),
dtype
=
np
.
float64
)
label
=
[]
label
=
mat
[:,
0
].
astype
(
np
.
float32
)
with
open
(
filename
,
'r'
)
as
inp
:
mat
=
mat
[:,
1
:]
for
line
in
inp
.
readlines
():
values
=
line
.
split
(
'
\t
'
)
data
.
append
([
float
(
x
)
for
x
in
values
[
1
:]])
label
.
append
(
float
(
values
[
0
]))
mat
=
np
.
array
(
data
,
dtype
=
np
.
float64
)
data
=
np
.
array
(
mat
.
reshape
(
mat
.
size
),
dtype
=
np
.
float64
,
copy
=
False
)
data
=
np
.
array
(
mat
.
reshape
(
mat
.
size
),
dtype
=
np
.
float64
,
copy
=
False
)
label
=
np
.
array
(
label
,
dtype
=
np
.
float32
)
handle
=
ctypes
.
c_void_p
()
handle
=
ctypes
.
c_void_p
()
ref
=
None
ref
=
None
if
reference
is
not
None
:
if
reference
is
not
None
:
...
@@ -258,11 +238,8 @@ def test_booster():
...
@@ -258,11 +238,8 @@ def test_booster():
c_str
(
'model.txt'
),
c_str
(
'model.txt'
),
ctypes
.
byref
(
num_total_model
),
ctypes
.
byref
(
num_total_model
),
ctypes
.
byref
(
booster2
))
ctypes
.
byref
(
booster2
))
data
=
[]
data
=
np
.
loadtxt
(
str
(
binary_example_dir
/
'binary.test'
),
dtype
=
np
.
float64
)
with
open
(
binary_example_dir
/
'binary.test'
,
'r'
)
as
inp
:
mat
=
data
[:,
1
:]
for
line
in
inp
.
readlines
():
data
.
append
([
float
(
x
)
for
x
in
line
.
split
(
'
\t
'
)[
1
:]])
mat
=
np
.
array
(
data
,
dtype
=
np
.
float64
)
preb
=
np
.
empty
(
mat
.
shape
[
0
],
dtype
=
np
.
float64
)
preb
=
np
.
empty
(
mat
.
shape
[
0
],
dtype
=
np
.
float64
)
num_preb
=
ctypes
.
c_int64
(
0
)
num_preb
=
ctypes
.
c_int64
(
0
)
data
=
np
.
array
(
mat
.
reshape
(
mat
.
size
),
dtype
=
np
.
float64
,
copy
=
False
)
data
=
np
.
array
(
mat
.
reshape
(
mat
.
size
),
dtype
=
np
.
float64
,
copy
=
False
)
...
...
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