Skip to content

Commit

Permalink
Merge pull request #80 from julioasotodv/master
Browse files Browse the repository at this point in the history
Added Python package
  • Loading branch information
QinbinLi committed Jun 29, 2018
2 parents f0a72a3 + cc049ad commit 3b0b08b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ html
latex
logs
*.pyc

*.dylib
*.egg-info*
python/dist/*
python/build/**
7 changes: 6 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ We provide both simple Python interface and scikit-learn wrapper interface. Befo
## Instructions for building ThunderSVM
* Please refer to [Installation](http://thundersvm.readthedocs.io/en/latest/how-to.html) for building ThunderSVM.

* 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).
* Then, if you want to install the Python package, go to the project root directory and run:
```
cd python && python setup.py install
```

* 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).

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

Expand Down
37 changes: 37 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from os import path
import setuptools
from shutil import copyfile
from sys import platform


dirname = path.dirname(path.abspath(__file__))

if platform == "linux" or platform == "linux2":
lib_path = path.abspath(path.join(dirname, '../build/lib/libthundersvm.so'))
elif platform == "win32":
lib_path = path.abspath(path.join(dirname, '../build/bin/Debug/thundersvm.dll'))
elif platform == "darwin":
lib_path = path.abspath(path.join(dirname, '../build/lib/libthundersvm.dylib'))
else :
print ("OS not supported!")
exit()

copyfile(lib_path, path.join(dirname, path.basename(lib_path)))

setuptools.setup(name="thundersvm",
version="github-master",
description="A Fast SVM Library on GPUs and CPUs",
long_description="""The mission of ThunderSVM is to help users easily and efficiently
apply SVMs to solve problems. ThunderSVM exploits GPUs and multi-core CPUs to achieve
high efficiency""",
long_description_content_type="text/plain",
url="https://github.com/zeyiwen/thundersvm",
py_modules=["svm", "thundersvmScikit"],
data_files = [('', [path.basename(lib_path)])],
install_requires=['numpy','scipy','scikit-learn'],
classifiers=(
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
),
)
29 changes: 21 additions & 8 deletions python/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,33 @@
from sys import platform

dirname = path.dirname(path.abspath(__file__))

if platform == "linux" or platform == "linux2":
lib_path = path.join(dirname, '../build/lib/libthundersvm.so')
shared_library_name = "libthundersvm.so"
elif platform == "win32":
lib_path = path.join(dirname, '../build/bin/Debug/thundersvm.dll')
shared_library_name = "thundersvm.dll"
elif platform == "darwin":
lib_path = path.join(dirname, '../build/lib/libthundersvm.dylib')
shared_library_name = "libthundersvm.dylib"
else :
print ("OS not supported!")
exit()
print ("OS not supported!")
exit()

if path.exists(path.abspath(path.join(dirname, shared_library_name))):
lib_path = path.abspath(path.join(dirname, shared_library_name))
else:
if platform == "linux" or platform == "linux2":
lib_path = path.join(dirname, '../build/lib/', shared_library_name)
elif platform == "win32":
lib_path = path.join(dirname, '../build/bin/Debug/', shared_library_name)
elif platform == "darwin":
lib_path = path.join(dirname, '../build/lib/', shared_library_name)

if path.exists(lib_path):
thundersvm = CDLL(lib_path)
thundersvm = CDLL(lib_path)
else :
print ("Please build the library first!")
exit()
print ("Please build the library first!")
exit()

dataset_path = dirname
'''
class dataset(object):
Expand Down
21 changes: 17 additions & 4 deletions python/thundersvmScikit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@
from sklearn.utils.validation import _num_samples

from ctypes import *
from os import path
from os import path, curdir
from sys import platform


dirname = path.dirname(path.abspath(__file__))

if platform == "linux" or platform == "linux2":
lib_path = path.join(dirname, '../build/lib/libthundersvm.so')
shared_library_name = "libthundersvm.so"
elif platform == "win32":
lib_path = path.join(dirname, '../build/bin/Debug/thundersvm.dll')
shared_library_name = "thundersvm.dll"
elif platform == "darwin":
lib_path = path.join(dirname, '../build/lib/libthundersvm.dylib')
shared_library_name = "libthundersvm.dylib"
else :
print ("OS not supported!")
exit()

if path.exists(path.abspath(path.join(dirname, shared_library_name))):
lib_path = path.abspath(path.join(dirname, shared_library_name))
else:
if platform == "linux" or platform == "linux2":
lib_path = path.join(dirname, '../build/lib/', shared_library_name)
elif platform == "win32":
lib_path = path.join(dirname, '../build/bin/Debug/', shared_library_name)
elif platform == "darwin":
lib_path = path.join(dirname, '../build/lib/', shared_library_name)

if path.exists(lib_path):
thundersvm = CDLL(lib_path)
else :
Expand Down

0 comments on commit 3b0b08b

Please sign in to comment.