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
5fd47b36
Commit
5fd47b36
authored
Sep 10, 2018
by
Nikita Titov
Committed by
Guolin Ke
Sep 10, 2018
Browse files
[test] slight C_API test refactoring (#1655)
* renamed functions * updated find_lib function
parent
f83e4aa4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
29 deletions
+27
-29
tests/c_api_test/test_.py
tests/c_api_test/test_.py
+27
-29
No files found.
tests/c_api_test/test_.py
View file @
5fd47b36
...
@@ -7,7 +7,6 @@ import sys
...
@@ -7,7 +7,6 @@ import sys
from
platform
import
system
from
platform
import
system
import
numpy
as
np
import
numpy
as
np
import
pytest
from
scipy
import
sparse
from
scipy
import
sparse
...
@@ -17,8 +16,13 @@ def find_lib_path():
...
@@ -17,8 +16,13 @@ def find_lib_path():
return
[]
return
[]
curr_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
__file__
)))
curr_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
__file__
)))
dll_path
=
[
curr_path
,
os
.
path
.
join
(
curr_path
,
'../../'
),
os
.
path
.
join
(
curr_path
,
'../../lib/'
)]
dll_path
=
[
curr_path
,
os
.
path
.
join
(
curr_path
,
'../../'
),
os
.
path
.
join
(
curr_path
,
'../../python-package/lightgbm/compile'
),
os
.
path
.
join
(
curr_path
,
'../../python-package/compile'
),
os
.
path
.
join
(
curr_path
,
'../../lib/'
)]
if
system
()
in
(
'Windows'
,
'Microsoft'
):
if
system
()
in
(
'Windows'
,
'Microsoft'
):
dll_path
.
append
(
os
.
path
.
join
(
curr_path
,
'../../python-package/compile/Release/'
))
dll_path
.
append
(
os
.
path
.
join
(
curr_path
,
'../../python-package/compile/windows/x64/DLL/'
))
dll_path
.
append
(
os
.
path
.
join
(
curr_path
,
'../../Release/'
))
dll_path
.
append
(
os
.
path
.
join
(
curr_path
,
'../../Release/'
))
dll_path
.
append
(
os
.
path
.
join
(
curr_path
,
'../../windows/x64/DLL/'
))
dll_path
.
append
(
os
.
path
.
join
(
curr_path
,
'../../windows/x64/DLL/'
))
dll_path
=
[
os
.
path
.
join
(
p
,
'lib_lightgbm.dll'
)
for
p
in
dll_path
]
dll_path
=
[
os
.
path
.
join
(
p
,
'lib_lightgbm.dll'
)
for
p
in
dll_path
]
...
@@ -57,8 +61,7 @@ def c_str(string):
...
@@ -57,8 +61,7 @@ def c_str(string):
return
ctypes
.
c_char_p
(
string
.
encode
(
'ascii'
))
return
ctypes
.
c_char_p
(
string
.
encode
(
'ascii'
))
@
pytest
.
mark
.
skip
def
load_from_file
(
filename
,
reference
):
def
test_load_from_file
(
filename
,
reference
):
ref
=
None
ref
=
None
if
reference
is
not
None
:
if
reference
is
not
None
:
ref
=
reference
ref
=
reference
...
@@ -76,13 +79,11 @@ def test_load_from_file(filename, reference):
...
@@ -76,13 +79,11 @@ def test_load_from_file(filename, reference):
return
handle
return
handle
@
pytest
.
mark
.
skip
def
save_to_binary
(
handle
,
filename
):
def
test_save_to_binary
(
handle
,
filename
):
LIB
.
LGBM_DatasetSaveBinary
(
handle
,
c_str
(
filename
))
LIB
.
LGBM_DatasetSaveBinary
(
handle
,
c_str
(
filename
))
@
pytest
.
mark
.
skip
def
load_from_csr
(
filename
,
reference
):
def
test_load_from_csr
(
filename
,
reference
):
data
=
[]
data
=
[]
label
=
[]
label
=
[]
inp
=
open
(
filename
,
'r'
)
inp
=
open
(
filename
,
'r'
)
...
@@ -119,8 +120,7 @@ def test_load_from_csr(filename, reference):
...
@@ -119,8 +120,7 @@ def test_load_from_csr(filename, reference):
return
handle
return
handle
@
pytest
.
mark
.
skip
def
load_from_csc
(
filename
,
reference
):
def
test_load_from_csc
(
filename
,
reference
):
data
=
[]
data
=
[]
label
=
[]
label
=
[]
inp
=
open
(
filename
,
'r'
)
inp
=
open
(
filename
,
'r'
)
...
@@ -157,8 +157,7 @@ def test_load_from_csc(filename, reference):
...
@@ -157,8 +157,7 @@ def test_load_from_csc(filename, reference):
return
handle
return
handle
@
pytest
.
mark
.
skip
def
load_from_mat
(
filename
,
reference
):
def
test_load_from_mat
(
filename
,
reference
):
data
=
[]
data
=
[]
label
=
[]
label
=
[]
inp
=
open
(
filename
,
'r'
)
inp
=
open
(
filename
,
'r'
)
...
@@ -192,28 +191,27 @@ def test_load_from_mat(filename, reference):
...
@@ -192,28 +191,27 @@ def test_load_from_mat(filename, reference):
return
handle
return
handle
@
pytest
.
mark
.
skip
def
free_dataset
(
handle
):
def
test_free_dataset
(
handle
):
LIB
.
LGBM_DatasetFree
(
handle
)
LIB
.
LGBM_DatasetFree
(
handle
)
def
test_dataset
():
def
test_dataset
():
train
=
test_
load_from_file
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.train'
),
None
)
train
=
load_from_file
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.train'
),
None
)
test
=
test_
load_from_mat
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
test
=
load_from_mat
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
test_
free_dataset
(
test
)
free_dataset
(
test
)
test
=
test_
load_from_csr
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
test
=
load_from_csr
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
test_
free_dataset
(
test
)
free_dataset
(
test
)
test
=
test_
load_from_csc
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
test
=
load_from_csc
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
test_
free_dataset
(
test
)
free_dataset
(
test
)
test_
save_to_binary
(
train
,
'train.binary.bin'
)
save_to_binary
(
train
,
'train.binary.bin'
)
test_
free_dataset
(
train
)
free_dataset
(
train
)
train
=
test_
load_from_file
(
'train.binary.bin'
,
None
)
train
=
load_from_file
(
'train.binary.bin'
,
None
)
test_
free_dataset
(
train
)
free_dataset
(
train
)
def
test_booster
():
def
test_booster
():
train
=
test_
load_from_mat
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.train'
),
None
)
train
=
load_from_mat
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.train'
),
None
)
test
=
test_
load_from_mat
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
test
=
load_from_mat
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'../../examples/binary_classification/binary.test'
),
train
)
booster
=
ctypes
.
c_void_p
()
booster
=
ctypes
.
c_void_p
()
LIB
.
LGBM_BoosterCreate
(
train
,
c_str
(
"app=binary metric=auc num_leaves=31 verbose=0"
),
ctypes
.
byref
(
booster
))
LIB
.
LGBM_BoosterCreate
(
train
,
c_str
(
"app=binary metric=auc num_leaves=31 verbose=0"
),
ctypes
.
byref
(
booster
))
LIB
.
LGBM_BoosterAddValidData
(
booster
,
test
)
LIB
.
LGBM_BoosterAddValidData
(
booster
,
test
)
...
@@ -227,8 +225,8 @@ def test_booster():
...
@@ -227,8 +225,8 @@ def test_booster():
print
(
'%d Iteration test AUC %f'
%
(
i
,
result
[
0
]))
print
(
'%d Iteration test AUC %f'
%
(
i
,
result
[
0
]))
LIB
.
LGBM_BoosterSaveModel
(
booster
,
0
,
-
1
,
c_str
(
'model.txt'
))
LIB
.
LGBM_BoosterSaveModel
(
booster
,
0
,
-
1
,
c_str
(
'model.txt'
))
LIB
.
LGBM_BoosterFree
(
booster
)
LIB
.
LGBM_BoosterFree
(
booster
)
test_
free_dataset
(
train
)
free_dataset
(
train
)
test_
free_dataset
(
test
)
free_dataset
(
test
)
booster2
=
ctypes
.
c_void_p
()
booster2
=
ctypes
.
c_void_p
()
num_total_model
=
ctypes
.
c_long
()
num_total_model
=
ctypes
.
c_long
()
LIB
.
LGBM_BoosterCreateFromModelfile
(
c_str
(
'model.txt'
),
ctypes
.
byref
(
num_total_model
),
ctypes
.
byref
(
booster2
))
LIB
.
LGBM_BoosterCreateFromModelfile
(
c_str
(
'model.txt'
),
ctypes
.
byref
(
num_total_model
),
ctypes
.
byref
(
booster2
))
...
...
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