Skip to content

Commit 3b0b08b

Browse files
authored
Merge pull request #80 from julioasotodv/master
Added Python package
2 parents f0a72a3 + cc049ad commit 3b0b08b

File tree

5 files changed

+85
-14
lines changed

5 files changed

+85
-14
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ html
1212
latex
1313
logs
1414
*.pyc
15-
15+
*.dylib
16+
*.egg-info*
17+
python/dist/*
18+
python/build/**

python/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ We provide both simple Python interface and scikit-learn wrapper interface. Befo
33
## Instructions for building ThunderSVM
44
* Please refer to [Installation](http://thundersvm.readthedocs.io/en/latest/how-to.html) for building ThunderSVM.
55

6-
* Then, under ```./build/lib/``` of the ThunderSVM root directory, you should be able to see a library of ThunderSVM (e.g., ```libthundersvm.so``` on Linux machines).
6+
* Then, if you want to install the Python package, go to the project root directory and run:
7+
```
8+
cd python && python setup.py install
9+
```
10+
11+
* However, you don't need to install the Python package in order to use it from Python. Thus, under ```./build/lib/``` of the ThunderSVM root directory, you should be able to see a library of ThunderSVM (e.g., ```libthundersvm.so``` on Linux machines).
712

813
* After you have successfully done the above two steps, it is ready to start using Python interfaces.
914

python/setup.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from os import path
2+
import setuptools
3+
from shutil import copyfile
4+
from sys import platform
5+
6+
7+
dirname = path.dirname(path.abspath(__file__))
8+
9+
if platform == "linux" or platform == "linux2":
10+
lib_path = path.abspath(path.join(dirname, '../build/lib/libthundersvm.so'))
11+
elif platform == "win32":
12+
lib_path = path.abspath(path.join(dirname, '../build/bin/Debug/thundersvm.dll'))
13+
elif platform == "darwin":
14+
lib_path = path.abspath(path.join(dirname, '../build/lib/libthundersvm.dylib'))
15+
else :
16+
print ("OS not supported!")
17+
exit()
18+
19+
copyfile(lib_path, path.join(dirname, path.basename(lib_path)))
20+
21+
setuptools.setup(name="thundersvm",
22+
version="github-master",
23+
description="A Fast SVM Library on GPUs and CPUs",
24+
long_description="""The mission of ThunderSVM is to help users easily and efficiently
25+
apply SVMs to solve problems. ThunderSVM exploits GPUs and multi-core CPUs to achieve
26+
high efficiency""",
27+
long_description_content_type="text/plain",
28+
url="https://github.com/zeyiwen/thundersvm",
29+
py_modules=["svm", "thundersvmScikit"],
30+
data_files = [('', [path.basename(lib_path)])],
31+
install_requires=['numpy','scipy','scikit-learn'],
32+
classifiers=(
33+
"Programming Language :: Python :: 3",
34+
"License :: OSI Approved :: Apache Software License",
35+
"Operating System :: OS Independent",
36+
),
37+
)

python/svm.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,33 @@
77
from sys import platform
88

99
dirname = path.dirname(path.abspath(__file__))
10+
1011
if platform == "linux" or platform == "linux2":
11-
lib_path = path.join(dirname, '../build/lib/libthundersvm.so')
12+
shared_library_name = "libthundersvm.so"
1213
elif platform == "win32":
13-
lib_path = path.join(dirname, '../build/bin/Debug/thundersvm.dll')
14+
shared_library_name = "thundersvm.dll"
1415
elif platform == "darwin":
15-
lib_path = path.join(dirname, '../build/lib/libthundersvm.dylib')
16+
shared_library_name = "libthundersvm.dylib"
1617
else :
17-
print ("OS not supported!")
18-
exit()
18+
print ("OS not supported!")
19+
exit()
20+
21+
if path.exists(path.abspath(path.join(dirname, shared_library_name))):
22+
lib_path = path.abspath(path.join(dirname, shared_library_name))
23+
else:
24+
if platform == "linux" or platform == "linux2":
25+
lib_path = path.join(dirname, '../build/lib/', shared_library_name)
26+
elif platform == "win32":
27+
lib_path = path.join(dirname, '../build/bin/Debug/', shared_library_name)
28+
elif platform == "darwin":
29+
lib_path = path.join(dirname, '../build/lib/', shared_library_name)
30+
1931
if path.exists(lib_path):
20-
thundersvm = CDLL(lib_path)
32+
thundersvm = CDLL(lib_path)
2133
else :
22-
print ("Please build the library first!")
23-
exit()
34+
print ("Please build the library first!")
35+
exit()
36+
2437
dataset_path = dirname
2538
'''
2639
class dataset(object):

python/thundersvmScikit.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,32 @@
1212
from sklearn.utils.validation import _num_samples
1313

1414
from ctypes import *
15-
from os import path
15+
from os import path, curdir
1616
from sys import platform
1717

18+
1819
dirname = path.dirname(path.abspath(__file__))
20+
1921
if platform == "linux" or platform == "linux2":
20-
lib_path = path.join(dirname, '../build/lib/libthundersvm.so')
22+
shared_library_name = "libthundersvm.so"
2123
elif platform == "win32":
22-
lib_path = path.join(dirname, '../build/bin/Debug/thundersvm.dll')
24+
shared_library_name = "thundersvm.dll"
2325
elif platform == "darwin":
24-
lib_path = path.join(dirname, '../build/lib/libthundersvm.dylib')
26+
shared_library_name = "libthundersvm.dylib"
2527
else :
2628
print ("OS not supported!")
2729
exit()
30+
31+
if path.exists(path.abspath(path.join(dirname, shared_library_name))):
32+
lib_path = path.abspath(path.join(dirname, shared_library_name))
33+
else:
34+
if platform == "linux" or platform == "linux2":
35+
lib_path = path.join(dirname, '../build/lib/', shared_library_name)
36+
elif platform == "win32":
37+
lib_path = path.join(dirname, '../build/bin/Debug/', shared_library_name)
38+
elif platform == "darwin":
39+
lib_path = path.join(dirname, '../build/lib/', shared_library_name)
40+
2841
if path.exists(lib_path):
2942
thundersvm = CDLL(lib_path)
3043
else :

0 commit comments

Comments
 (0)