diff --git a/README.md b/README.md index f6a3607..dbeb36d 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 +``` diff --git a/libmf/lib_path.py b/libmf/lib_path.py new file mode 100644 index 0000000..d609b90 --- /dev/null +++ b/libmf/lib_path.py @@ -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) diff --git a/libmf/mf.py b/libmf/mf.py index 76f6e28..6e7abb7 100644 --- a/libmf/mf.py +++ b/libmf/mf.py @@ -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) @@ -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: @@ -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() - diff --git a/mf_tests.py b/mf_tests.py index 5605422..7d9ab1e 100644 --- a/mf_tests.py +++ b/mf_tests.py @@ -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)