Skip to content

Commit

Permalink
Merge 00b5d0d into 381fef8
Browse files Browse the repository at this point in the history
  • Loading branch information
smmaurer committed Aug 2, 2019
2 parents 381fef8 + 00b5d0d commit 0f592c2
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 61 deletions.
2 changes: 1 addition & 1 deletion docs/installation.rst
Expand Up @@ -115,7 +115,7 @@ from source also requires `Microsoft Visual C++ Compiler for Python 2.7

.. _Anaconda: http://docs.continuum.io/anaconda/
.. _pip: https://pip.pypa.io/en/latest/
.. _OpenMP: http://openmp.org
.. _OpenMP: http://openmp.org/
.. _GNU GCC: https://gcc.gnu.org/
.. _Homebrew: http://brew.sh/
.. _MacPorts: https://www.macports.org/
Expand Down
10 changes: 5 additions & 5 deletions pandana/network.py
Expand Up @@ -92,16 +92,16 @@ def __init__(self, node_x, node_y, edge_from, edge_to, edge_weights,
self._node_indexes(edges_df["to"])], axis=1)

self.net = cyaccess(self.node_idx.values,
nodes_df.astype('double').as_matrix(),
edges.as_matrix(),
nodes_df.astype('double').values,
edges.values,
edges_df[edge_weights.columns].transpose()
.astype('double')
.as_matrix(),
.values,
twoway)

self._twoway = twoway

self.kdtree = KDTree(nodes_df.as_matrix())
self.kdtree = KDTree(nodes_df.values)

@classmethod
def from_hdf5(cls, filename):
Expand Down Expand Up @@ -381,7 +381,7 @@ def get_node_ids(self, x_col, y_col, mapping_distance=None):
"""
xys = pd.DataFrame({'x': x_col, 'y': y_col})

distances, indexes = self.kdtree.query(xys.as_matrix())
distances, indexes = self.kdtree.query(xys.values)
indexes = np.transpose(indexes)[0]
distances = np.transpose(distances)[0]

Expand Down
107 changes: 58 additions & 49 deletions setup.py
Expand Up @@ -12,6 +12,10 @@
from setuptools.command.build_ext import build_ext


###############################################
## Invoking tests
###############################################

class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

Expand Down Expand Up @@ -46,53 +50,62 @@ def run(self):
build_ext.run(self)


include_dirs = [
'.'
]
###############################################
## Building the C++ extension
###############################################

packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"])
extra_compile_args = ['-w', '-std=c++11', '-O3']
extra_link_args = []

# Mac compilation: flags are for the llvm compilers included with recent
# versions of Xcode Command Line Tools, or newer versions installed separately

if sys.platform.startswith('darwin'): # Mac

# This environment variable sets the earliest OS version that the compiled
# code will be compatible with. In certain contexts the default is too old
# to allow using libc++; supporting OS X 10.9 and later seems safe
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9'

extra_compile_args += ['-D NO_TR1_MEMORY', '-stdlib=libc++']
extra_link_args += ['-stdlib=libc++']

if os.environ.get('USEOPENMP'):
extra_compile_args += ['-fopenmp']

source_files = [
'src/accessibility.cpp',
'src/graphalg.cpp',
"src/cyaccess.pyx",
'src/contraction_hierarchies/src/libch.cpp'
]

extra_compile_args = [
'-w',
'-std=c++0x',
'-O3',
'-fpic',
'-g',
]
extra_link_args = None

# separate compiler options for Windows
if sys.platform.startswith('win'):
# Window compilation: flags are for Visual C++

elif sys.platform.startswith('win'): # Windows
extra_compile_args = ['/w', '/openmp']
# Use OpenMP if directed or not on a Mac
elif os.environ.get('USEOPENMP') or not sys.platform.startswith('darwin'):

# Linux compilation: flags are for gcc 4.8 and later

else: # Linux
extra_compile_args += ['-fopenmp']
extra_link_args = [
'-lgomp'
]

# recent versions of the OS X SDK don't have the tr1 namespace
# and we need to flag that during compilation.
# here we need to check what version of OS X is being targeted
# for the installation.
# this is potentially different than the version of OS X on the system.
if platform.system() == 'Darwin':
mac_ver = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
if mac_ver:
mac_ver = [int(x) for x in mac_ver.split('.')]
if mac_ver >= [10, 7]:
extra_compile_args += ['-D NO_TR1_MEMORY']
extra_compile_args += ['-stdlib=libc++']
extra_link_args += ['-lgomp']


cyaccess = Extension(
name='pandana.cyaccess',
sources=[
'src/accessibility.cpp',
'src/graphalg.cpp',
'src/cyaccess.pyx',
'src/contraction_hierarchies/src/libch.cpp'],
language='c++',
include_dirs=['.'],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)


###############################################
## Standard setup
###############################################

version = '0.4.1'

packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"])

# read long description from README
with open('README.rst', 'r') as f:
long_description = f.read()
Expand All @@ -107,14 +120,7 @@ def run(self):
'dataframes of network queries, quickly'),
long_description=long_description,
url='https://udst.github.io/pandana/',
ext_modules=[Extension(
'pandana.cyaccess',
source_files,
language="c++",
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)],
ext_modules=[cyaccess],
install_requires=[
'matplotlib>=1.3.1',
'numpy>=1.8.0',
Expand All @@ -125,7 +131,10 @@ def run(self):
'cython>=0.25.2',
'scikit-learn>=0.18.1'
],
tests_require=['pytest'],
tests_require=[
'pycodestyle',
'pytest'
],
cmdclass={
'test': PyTest,
'lint': Lint,
Expand Down
10 changes: 5 additions & 5 deletions src/contraction_hierarchies/src/DataStructures/Percent.h
Expand Up @@ -54,8 +54,8 @@ class Percent
_nextThreshold += _intervalPercent;
printPercent( currentValue / (double)_maxValue * 100 );
}
// if (currentValue + 1 == _maxValue)
// std::cout << " 100%" << std::endl;
if (currentValue + 1 == _maxValue)
std::cout << " 100%" << std::endl;
}

void printIncrement()
Expand All @@ -77,12 +77,12 @@ class Percent
while (percent >= _lastPercent+_step) {
_lastPercent+=_step;
if (_lastPercent % 10 == 0) {
// std::cout << " " << _lastPercent << "% ";
std::cout << " " << _lastPercent << "% ";
}
else {
// std::cout << ".";
std::cout << ".";
}
// std::cout.flush();
std::cout.flush();
}
}
};
Expand Down
4 changes: 4 additions & 0 deletions src/contraction_hierarchies/src/libch.cpp
Expand Up @@ -202,6 +202,10 @@ inline ostream& operator<< (ostream& os, const Edge& e) {
}
}
}

FILE_LOG(logINFO) << "Range graph removed " << edges.size() - edge
<< " edges of " << edges.size() << "\n";

//INFO("Range graph removed " << edges.size() - edge << " edges of " << edges.size());
assert(edge <= edges.size());
edges.resize( edge );
Expand Down
2 changes: 2 additions & 0 deletions src/contraction_hierarchies/src/libch.h
Expand Up @@ -34,6 +34,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "DataStructures/StaticGraph.h"
#include "POIIndex/POIIndex.h"

#define FILE_LOG(logINFO) (std::cout)

struct _HeapData {
NodeID parent;
_HeapData( NodeID p ) : parent(p) { }
Expand Down
10 changes: 10 additions & 0 deletions src/graphalg.cpp
Expand Up @@ -9,6 +9,10 @@ Graphalg::Graphalg(
this->numnodes = numnodes;

int num = omp_get_max_threads();

FILE_LOG(logINFO) << "Generating contraction hierarchies with "
<< num << " threads.\n";

ch = CH::ContractionHierarchies(num);

vector<CH::Node> nv;
Expand All @@ -20,6 +24,9 @@ Graphalg::Graphalg(
nv.push_back(n);
}

FILE_LOG(logINFO) << "Setting CH node vector of size "
<< nv.size() << "\n";

ch.SetNodeVector(nv);

vector<CH::Edge> ev;
Expand All @@ -30,6 +37,9 @@ Graphalg::Graphalg(
ev.push_back(e);
}

FILE_LOG(logINFO) << "Setting CH edge vector of size "
<< ev.size() << "\n";

ch.SetEdgeVector(ev);
ch.RunPreprocessing();
}
Expand Down
3 changes: 2 additions & 1 deletion src/shared.h
Expand Up @@ -8,4 +8,5 @@
#endif
#ifdef _OPENMP
#include <omp.h>
#endif
#endif
#define FILE_LOG(logINFO) (std::cout)

0 comments on commit 0f592c2

Please sign in to comment.