Skip to content
Merged
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
32 changes: 27 additions & 5 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,98 +26,121 @@ jobs:
- os: windows-2019
python: 36
platform_id: win_amd64
arch: AMD64
- os: windows-2019
python: 37
platform_id: win_amd64
arch: AMD64
- os: windows-2019
python: 38
platform_id: win_amd64
arch: AMD64
- os: windows-latest
python: 39
platform_id: win_amd64
arch: AMD64
- os: windows-latest
python: 310
platform_id: win_amd64
arch: AMD64

# Linux 64 bit manylinux2014
- os: ubuntu-latest
python: 36
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
arch: x86_64
- os: ubuntu-latest
python: 37
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
arch: x86_64
- os: ubuntu-latest
python: 38
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
arch: x86_64
- os: ubuntu-latest
python: 39
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
arch: x86_64
- os: ubuntu-latest
python: 310
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
arch: x86_64

# Linux 64 bit aarch64
- os: ubuntu-latest
python: 36
platform_id: manylinux_aarch64
manylinux_image: manylinux2014
arch: aarch64
- os: ubuntu-latest
python: 37
platform_id: manylinux_aarch64
manylinux_image: manylinux2014
arch: aarch64
- os: ubuntu-latest
python: 38
platform_id: manylinux_aarch64
manylinux_image: manylinux2014
arch: aarch64
- os: ubuntu-latest
python: 39
platform_id: manylinux_aarch64
manylinux_image: manylinux2014
arch: aarch64
- os: ubuntu-latest
python: 310
platform_id: manylinux_aarch64
manylinux_image: manylinux2014
arch: aarch64

# MacOS x86_64
- os: macos-latest
python: 36
platform_id: macosx_x86_64
macosx_deployment_target: 10.14
arch: x86_64
- os: macos-latest
python: 37
platform_id: macosx_x86_64
macosx_deployment_target: 10.14
arch: x86_64
- os: macos-latest
python: 38
platform_id: macosx_x86_64
macosx_deployment_target: 10.14
arch: x86_64
- os: macos-latest
python: 39
platform_id: macosx_x86_64
macosx_deployment_target: 10.14
arch: x86_64
- os: macos-latest
python: 310
platform_id: macosx_x86_64
macosx_deployment_target: 10.14
arch: x86_64

# MacOS arm64
- os: macos-latest
python: 38
platform_id: macosx_arm64
macosx_deployment_target: 11.0
macosx_deployment_target: 12.0
arch: arm64
- os: macos-latest
python: 39
platform_id: macosx_arm64
macosx_deployment_target: 11.0
macosx_deployment_target: 12.0
arch: arm64
- os: macos-latest
python: 310
platform_id: macosx_arm64
macosx_deployment_target: 11.0
macosx_deployment_target: 12.0
arch: arm64

steps:
- uses: actions/checkout@v2
Expand All @@ -136,14 +159,13 @@ jobs:
uses: pypa/[email protected]
env:
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }}
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_ARCHS: all
CIBW_TEST_SKIP: "*-macosx_arm64"
CIBW_BEFORE_BUILD: pip install pybind11
CIBW_TEST_COMMAND: pytest {project}/tests -vv
CIBW_TEST_REQUIRES: pytest numpy
CIBW_BUILD_VERBOSITY: 1
CIBW_ARCHS: ${{ matrix.arch }}
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macosx_deployment_target }}
- uses: actions/upload-artifact@v2
with:
Expand Down
89 changes: 43 additions & 46 deletions cpp/prtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ using Real = float;

namespace py = pybind11;

template <class T, class U>
using pair = std::pair<T, U>;

template <class T>
using vec = std::vector<T>;

Expand Down Expand Up @@ -92,37 +89,35 @@ template <int D = 2>
class BB
{
private:
std::array<Real, 2 * D> values;
Real values[2 * D];

public:
BB() { clear(); }

template <typename Iter>
BB(const Iter &minima, const Iter &maxima)
BB(const Real (&minima)[D], const Real (&maxima)[D])
{
std::array<Real, 2 * D> v;
if (unlikely(minima.size() != maxima.size()))
{
throw std::runtime_error("Invalid size");
}
const int n = minima.size();
if (unlikely(n != D))
{
throw std::runtime_error("Invalid size");
}
for (int i = 0; i < n; ++i)
Real v[2 * D];
for (int i = 0; i < D; ++i)
{
v[i] = -minima[i];
v[i + D] = maxima[i];
}
validate(v);
values = v;
for (int i = 0; i < D; ++i)
{
values[i] = v[i];
values[i + D] = v[i + D];
}
}

BB(const std::array<Real, 2 * D> v)
BB(const Real (&v)[2 * D])
{
validate(v);
values = v;
for (int i = 0; i < D; ++i)
{
values[i] = v[i];
values[i + D] = v[i + D];
}
}

Real min(const int dim) const
Expand All @@ -142,7 +137,7 @@ class BB
return values[dim + D];
}

bool validate(const std::array<Real, 2 * D> &v) const
bool validate(const Real (&v)[2 * D]) const
{
bool flag = false;
for (int i = 0; i < 2; ++i)
Expand All @@ -159,11 +154,17 @@ class BB
}
return flag;
}
void clear() { std::fill_n(values.begin(), 2 * D, -1e100); }
void clear()
{
for (int i = 0; i < 2 * D; ++i)
{
values[i] = -1e100;
}
}

BB operator+(const BB &rhs) const
{
std::array<Real, 2 * D> result;
Real result[2 * D];
for (int i = 0; i < 2 * D; ++i)
{
result[i] = std::max(values[i], rhs.values[i]);
Expand All @@ -180,7 +181,7 @@ class BB
return *this;
}

void expand(const std::array<Real, D> &delta)
void expand(const Real (&delta)[D])
{
for (int i = 0; i < D; ++i)
{
Expand All @@ -192,7 +193,7 @@ class BB
bool operator()(
const BB &target) const
{ // whether this and target has any intersect
std::array<Real, 2 * D> result;
Real result[2 * D];
for (int i = 0; i < 2 * D; ++i)
{
result[i] = std::min(values[i], target.values[i]);
Expand Down Expand Up @@ -350,7 +351,7 @@ template <class T, int B = 6, int D = 2>
class PseudoPRTreeNode
{
public:
std::array<Leaf<T, B, D>, 2 * D> leaves;
Leaf<T, B, D> leaves[2 * D];
std::unique_ptr<PseudoPRTreeNode> left, right;

PseudoPRTreeNode()
Expand Down Expand Up @@ -423,6 +424,7 @@ class PseudoPRTree
root = std::make_unique<PseudoPRTreeNode<T, B, D>>();
}
construct(root.get(), b, e, 0);
clean_data<T, D>(b, e);
}

template <class Archive>
Expand Down Expand Up @@ -496,7 +498,6 @@ class PseudoPRTree
if (cache_children.empty())
{
using U = PseudoPRTreeNode<T, B, D>;
vec<U *> leaf_nodes;
cache_children.reserve(hint);
auto node = root.get();
queue<U *> que;
Expand All @@ -506,7 +507,6 @@ class PseudoPRTree
{
node = que.front();
que.pop();
leaf_nodes.emplace_back(node);
node->address_of_leaves(cache_children);
if (node->left)
que.emplace(node->left.get());
Expand All @@ -517,8 +517,7 @@ class PseudoPRTree
return cache_children;
}

std::pair<DataType<T, D> *, DataType<T, D> *> as_X(void *placement,
const int hint)
std::pair<DataType<T, D> *, DataType<T, D> *> as_X(void *placement, const int hint)
{
DataType<T, D> *b, *e;
auto children = get_all_leaves(hint);
Expand Down Expand Up @@ -649,8 +648,8 @@ class PRTree

for (T i = 0; i < length; i++)
{
std::array<Real, D> minima;
std::array<Real, D> maxima;
Real minima[D];
Real maxima[D];
for (int j = 0; j < D; ++j)
{
minima[j] = rx(i, j);
Expand All @@ -663,8 +662,8 @@ class PRTree

for (size_t i = 0; i < length; i++)
{
std::array<Real, D> minima;
std::array<Real, D> maxima;
Real minima[D];
Real maxima[D];
for (int j = 0; j < D; ++j)
{
minima[j] = rx(i, j);
Expand Down Expand Up @@ -720,8 +719,8 @@ class PRTree
throw std::runtime_error("Given index is already included.");
}
{
std::array<Real, D> minima;
std::array<Real, D> maxima;
Real minima[D];
Real maxima[D];
for (int i = 0; i < D; ++i)
{
minima[i] = *x.data(i);
Expand All @@ -732,7 +731,7 @@ class PRTree
idx2bb.emplace(idx, bb);
set_obj(idx, objdumps);

std::array<Real, D> delta;
Real delta[D];
for (int i = 0; i < D; ++i)
{
delta[i] = bb.max(i) - bb.min(i) + 0.00000001;
Expand All @@ -751,7 +750,7 @@ class PRTree

while (likely(cands.size() == 0))
{
std::array<Real, D> d;
Real d[D];
for (int i = 0; i < D; ++i)
{
d[i] = delta[i] * c;
Expand Down Expand Up @@ -889,7 +888,6 @@ class PRTree

auto first_tree = PseudoPRTree<T, B, D>(b, e);
auto first_leaves = first_tree.get_all_leaves(e - b);
clean_data<T, D>(b, e);
for (auto &leaf : first_leaves)
{
auto pp = std::make_unique<PRTreeNode<T, B, D>>(leaf);
Expand All @@ -900,7 +898,6 @@ class PRTree
{
auto tree = PseudoPRTree<T, B, D>(bb, ee);
auto leaves = tree.get_all_leaves(ee - bb);
clean_data<T, D>(bb, ee);
auto leaves_size = leaves.size();

vec<std::unique_ptr<PRTreeNode<T, B, D>>> tmp_nodes;
Expand Down Expand Up @@ -988,8 +985,8 @@ class PRTree
if (ndim == 1)
{
{
std::array<Real, D> minima;
std::array<Real, D> maxima;
Real minima[D];
Real maxima[D];
for (int i = 0; i < D; ++i)
{
minima[i] = *x.data(i);
Expand All @@ -1012,8 +1009,8 @@ class PRTree
for (long int i = 0; i < shape_x[0]; i++)
{
{
std::array<Real, D> minima;
std::array<Real, D> maxima;
Real minima[D];
Real maxima[D];
for (int j = 0; j < D; ++j)
{
minima[j] = *x.data(i, j);
Expand Down Expand Up @@ -1047,8 +1044,8 @@ class PRTree
{
throw std::runtime_error("invalid shape");
}
std::array<Real, D> minima;
std::array<Real, D> maxima;
Real minima[D];
Real maxima[D];
if (x.size() == D)
{
is_point = true;
Expand Down
Loading