diff --git a/CMakeLists.txt b/CMakeLists.txt index 60119bf..c570cdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,17 +13,20 @@ if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register") endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -std=c++0x") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++0x") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter -Wno-strict-aliasing") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -mfpmath=sse -msse4.1") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -funsafe-math-optimizations") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math -ffinite-math-only -fvect-cost-model -mrecip") -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx") # on sandy bridge and later + if(DEFINED ENV{CXX_FLAGS}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXX_FLAGS}") # for testing + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXX_FLAGS}") endif() message("CXX_FLAGS =${CMAKE_CXX_FLAGS}") +set(CMAKE_DEBUG_POSTFIX _dbg) +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -DDIST_DEBUG_LEVEL=3 -DDIST_THROW_ON_ERROR") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG=1") + if(DEFINED EXTRA_INCLUDE_PATH) include_directories(${EXTRA_INCLUDE_PATH}) endif() diff --git a/Makefile b/Makefile index 1521061..ce340b4 100644 --- a/Makefile +++ b/Makefile @@ -20,14 +20,12 @@ ifdef VIRTUAL_ENV library_path=$(LIBRARY_PATH):$(VIRTUAL_ENV)/lib/ nose_env+=$(ld_library_path)=$($(ld_library_path)):$(VIRTUAL_ENV)/lib/ else - cmake_args=-DCMAKE_INSTALL_PREFIX=.. + cmake_args=-DCMAKE_INSTALL_PREFIX=../.. library_path=$(LIBRARY_PATH):`pwd`/lib/ nose_env+=$(ld_library_path)=$($(ld_library_path)):`pwd`/lib/ endif - -cy_deps= -ifdef PYDISTRIBUTIONS_USE_LIB - cy_deps=install_cc +ifdef CMAKE_INSTALL_PREFIX + cmake_args=-DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX) endif all: test @@ -40,16 +38,23 @@ src/test_headers.cc: $(headers) echo 'int main () { return 0; }' >> src/test_headers.cc configure_cc: src/test_headers.cc FORCE - mkdir -p build lib - cd build && cmake $(cmake_args) .. + mkdir -p build/debug build/release lib + cd build/debug \ + && cmake -DCMAKE_BUILD_TYPE=Debug $(cmake_args) ../.. + cd build/release \ + && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo $(cmake_args) ../.. + +debug_cc: configure_cc FORCE + cd build/debug && $(MAKE) -build_cc: configure_cc FORCE - cd build && $(MAKE) +release_cc: configure_cc FORCE + cd build/release && $(MAKE) -install_cc: build_cc FORCE - cd build && $(MAKE) install +install_cc: debug_cc release_cc FORCE + cd build/debug && $(MAKE) install + cd build/release && $(MAKE) install -deps_cy: $(cy_deps) FORCE +deps_cy: install_cc FORCE pip install -r requirements.txt dev_cy: deps_cy FORCE @@ -60,7 +65,7 @@ install_cy: deps_cy FORCE install: install_cc install_cy FORCE -package: build_cc FORCE +package: debug_cc release_cc FORCE cd build && $(MAKE) package install_cc_examples: install_cc FORCE diff --git a/README.md b/README.md index f5b871e..acf3c9a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ and now powers machine learning infrastructure at Salesforce.com. ## Installation -distributions with pip: +For python-only support (no C++) you can install with pip: pip install distributions diff --git a/doc/installation.rst b/doc/installation.rst index b63245f..15cb475 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -31,19 +31,21 @@ Install requirements:: sudo apt-get install cmake libeigen3-dev -Then:: +To install in ``./lib``:: - mkdir build; cd build - cmake -DCMAKE_INSTALL_PREFIX=/my/prefix .. make install +Alternatively, set a custom install location:: + + CMAKE_INSTALL_PREFIX=/my/prefix make install + Python wrapping libdistributions -------------------------------- Follow instructions for C++ Standalone. Install numpy and scipy. Then:: - PYDISTRIBUTIONS_USE_LIB=1 LIBRARY_PATH=/my/prefix/lib pip install distributions + LIBRARY_PATH=/my/prefix/lib pip install distributions .. warning:: @@ -77,12 +79,6 @@ Install cmake. Install numpy, scipy, cython, and nosetests so that they're available within a python virtualenv. Activate that virtualenv. Then:: - PYDISTRIBUTIONS_USE_LIB=1 make test - -The top-level ``Makefile`` provides many targets useful for -development. - -To use distributions in CMake targest, and to make the distributions unit -tests run faster, set the environment variable ``DISTRIBUTIONS_PATH`` to your git cloned location, for example + make test - echo 'export DISTRIBUTIONS_PATH=/path/to/distributions' >> $VIRTUAL_ENV/bin/postactivate +The top-level ``Makefile`` provides many targets useful for development. diff --git a/setup.py b/setup.py index 44a0cda..500f287 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,6 @@ ]) -use_libdistributions = 'PYDISTRIBUTIONS_USE_LIB' in os.environ use_protobuf = 'DISTRIBUTIONS_USE_PROTOBUF' in os.environ @@ -111,23 +110,7 @@ def make_extension(name): if use_protobuf: libraries.append('protobuf') if name.startswith('lp'): - if use_libdistributions: - libraries = ['distributions_shared'] + libraries - else: - sources += [ - 'src/common.cc', - 'src/special.cc', - 'src/random.cc', - 'src/vector_math.cc', - ] - if name == 'lp.clustering': - sources.append('src/clustering.cc') - elif name in ('lp.models.nich', 'lp.models._nich'): - sources.append('src/models/nich.cc') - elif name in ('lp.models.niw', 'lp.models._niw'): - sources.append('src/models/niw.cc') - elif name in ('lp.models.gp', 'lp.models._gp'): - sources.append('src/models/gp.cc') + libraries = ['distributions_shared_dbg'] + libraries return Extension( module, sources=sources,