Skip to content

python3 support and auto autodetect so file #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## compile libmf interface object files

You just need a standard c++ compiler
You just need a standard c++ compiler
```
$ g++ --std=c++11 *.cpp -shared -o python-libmf.so
```
Expand All @@ -25,3 +25,8 @@ if these work then you are good to go!
`data.shape => (x, 3)` where x is the number of observations

`ind` is a sparse numpy array of indices specifying where we want to predict unobserved values

## for mac os 10.12
```
export MACOSX_DEPLOYMENT_TARGET=10.12
```
11 changes: 11 additions & 0 deletions libmf/lib_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import re
import os
import sys


def find_lib_path():
path = os.environ["LIBMF_OBJ"] if "LIBMF_OBJ" in os.environ else sys.argv[1] if len(sys.argv) > 1 else \
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
for i in os.listdir(path):
if os.path.isfile(os.path.join(path, i)) and re.match('python-libmf\.cpython(.*)\.so', i):
return os.path.join(path, i)
7 changes: 3 additions & 4 deletions libmf/mf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import ctypes
import os
import sys
from . import lib_path

compiled_src = os.environ["LIBMF_OBJ"] if "LIBMF_OBJ" in os.environ else sys.argv[1] if len(sys.argv) > 1 else \
os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/python-libmf.so"
compiled_src = lib_path.find_lib_path()
mf = ctypes.CDLL(compiled_src)
c_float_p = ctypes.POINTER(ctypes.c_float)

Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(self, *args, **kwargs):
self._options = MFParam()
for kw in kwargs:
if kw not in [i[0] for i in get_default_options()]:
print "Unrecognized keyword argument '{0}={1}'".format(kw, kwargs[kw])
print("Unrecognized keyword argument '{0}={1}'".format(kw, kwargs[kw]))

for item in get_default_options():
if item[0] not in kwargs:
Expand Down Expand Up @@ -183,4 +183,3 @@ def __generate_test_data(xs, ys, k, indices_only=False):
ry = np.random.random_integers(0, ys, k)
rv = np.random.rand(k)
return np.vstack((rx, ry, rv)).transpose() if not indices_only else np.vstack((rx,ry)).transpose()

26 changes: 13 additions & 13 deletions mf_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@

test_data = mf.__generate_test_data(9000, 1000, 25000)

print "testing fit method"
print("testing fit method")
mf_engine = mf.MF()
try:
mf_engine.mf_fit(test_data)
print "OK"
print("OK")
except Exception as e:
print e
print "FAILED"
print(e)
print("FAILED")

print "testing predict method"
print("testing predict method")
try:
pred_data = mf.__generate_test_data(9000, 1000, 1000, indices_only=True)
print pred_data.shape
print(pred_data.shape)
mf_engine.mf_predict(pred_data)
print "OK"
print("OK")
except Exception as e:
print "FAILED"
print e
print("FAILED")
print(e)

print "testing cross validation"
print("testing cross validation")
try:
mf_engine.mf_cross_validation(test_data)
print "OK"
print("OK")
except Exception as e:
print "FAILED"
print e
print("FAILED")
print(e)