diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1f4c0c2..0d6643e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,30 +7,39 @@ on: - master jobs: - unittests: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.6, 3.7, 3.8] - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install torch numpy scikit-learn flake8 setuptools - - name: Build package - run: | - python setup.py build_ext --inplace - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with unittest - run: | - python -m unittest -v + unittests: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: [3.6, 3.7] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install numpy scikit-learn flake8 setuptools + + - name: Install torch windows + linux + if: ${{matrix.os != 'macos-latest'}} + run: pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html + - name: Install torch macos + if: ${{matrix.os == 'macos-latest'}} + run: pip install torch + + - name: Build package + run: | + python setup.py build_ext --inplace + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with unittest + run: | + python -m unittest -v diff --git a/CHANGELOG.md b/CHANGELOG.md index eccc6b1..6ffc6c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# UNRELEASED + +## Bug fix +- CPU version works for MacOS + # 0.6.2 ## Bug fix diff --git a/cpu/include/neighbors.h b/cpu/include/neighbors.h index ce4d27d..1c83851 100644 --- a/cpu/include/neighbors.h +++ b/cpu/include/neighbors.h @@ -9,15 +9,15 @@ using namespace std; template int nanoflann_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, float radius, + vector& neighbors_indices, vector& dists, float radius, int max_num, int mode, bool sorted); template int batch_nanoflann_neighbors(vector& queries, vector& supports, - vector& q_batches, vector& s_batches, - vector& neighbors_indices, vector& dists, float radius, - int max_num, int mode, bool sorted); + vector& q_batches, vector& s_batches, + vector& neighbors_indices, vector& dists, + float radius, int max_num, int mode, bool sorted); template void nanoflann_knn_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, int k); + vector& neighbors_indices, vector& dists, int k); diff --git a/cpu/src/ball_query.cpp b/cpu/src/ball_query.cpp index c9a4777..339ea74 100644 --- a/cpu/src/ball_query.cpp +++ b/cpu/src/ball_query.cpp @@ -15,7 +15,7 @@ std::pair ball_query(at::Tensor support, at::Tensor quer at::Tensor out; at::Tensor out_dists; - std::vector neighbors_indices(query.size(0), 0); + std::vector neighbors_indices(query.size(0), 0); std::vector neighbors_dists(query.size(0), -1); auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); @@ -34,7 +34,7 @@ std::pair ball_query(at::Tensor support, at::Tensor quer neighbors_dists, radius, max_num, mode, sorted); }); auto neighbors_dists_ptr = neighbors_dists.data(); - long* neighbors_indices_ptr = neighbors_indices.data(); + int64_t* neighbors_indices_ptr = neighbors_indices.data(); if (mode == 0) { out = @@ -73,7 +73,7 @@ std::pair batch_ball_query(at::Tensor support, at::Tenso at::Tensor idx; at::Tensor dist; - std::vector neighbors_indices; + std::vector neighbors_indices; std::vector neighbors_dists; auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); @@ -91,10 +91,11 @@ std::pair batch_ball_query(at::Tensor support, at::Tenso query_batch = at::cat({at::zeros(1, query_batch.options()), query_batch.cumsum(0)}, 0); support_batch = degree(support_batch, batch_size); support_batch = at::cat({at::zeros(1, support_batch.options()), support_batch.cumsum(0)}, 0); - std::vector query_batch_stl(query_batch.DATA_PTR(), - query_batch.DATA_PTR() + query_batch.numel()); - std::vector support_batch_stl(support_batch.DATA_PTR(), - support_batch.DATA_PTR() + support_batch.numel()); + std::vector query_batch_stl(query_batch.DATA_PTR(), + query_batch.DATA_PTR() + query_batch.numel()); + std::vector support_batch_stl(support_batch.DATA_PTR(), + support_batch.DATA_PTR() + + support_batch.numel()); AT_DISPATCH_ALL_TYPES(query.scalar_type(), "batch_radius_search", [&] { std::vector queries_stl(query.DATA_PTR(), @@ -107,7 +108,7 @@ std::pair batch_ball_query(at::Tensor support, at::Tenso neighbors_dists, radius, max_num, mode, sorted); }); auto neighbors_dists_ptr = neighbors_dists.data(); - long* neighbors_indices_ptr = neighbors_indices.data(); + int64_t* neighbors_indices_ptr = neighbors_indices.data(); if (mode == 0) { diff --git a/cpu/src/fps.cpp b/cpu/src/fps.cpp index f05364a..5454724 100644 --- a/cpu/src/fps.cpp +++ b/cpu/src/fps.cpp @@ -15,7 +15,7 @@ at::Tensor fps(at::Tensor points, const int nsamples, bool random) auto out_options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); auto batch_size = points.size(0); auto out = torch::empty({batch_size, nsamples}, out_options); - auto out_a = out.accessor(); + auto out_a = out.accessor(); for (ptrdiff_t b = 0; b < batch_size; b++) { diff --git a/cpu/src/interpolate.cpp b/cpu/src/interpolate.cpp index ae1f5f9..c241ed5 100644 --- a/cpu/src/interpolate.cpp +++ b/cpu/src/interpolate.cpp @@ -19,7 +19,7 @@ at::Tensor knn_interpolate(at::Tensor features, at::Tensor idx, at::Tensor weigh auto output_a = output.accessor(); auto features_a = features.accessor(); auto weight_a = weight.accessor(); - auto idx_a = idx.accessor(); + auto idx_a = idx.accessor(); auto batch_size = idx.size(0); for (auto b = 0; b < batch_size; b++) @@ -51,7 +51,7 @@ at::Tensor knn_interpolate_grad(at::Tensor grad_out, at::Tensor idx, at::Tensor auto output_a = output.accessor(); auto grad_out_a = grad_out.accessor(); auto weight_a = weight.accessor(); - auto idx_a = idx.accessor(); + auto idx_a = idx.accessor(); auto batch_size = idx.size(0); for (auto b = 0; b < batch_size; b++) diff --git a/cpu/src/knn.cpp b/cpu/src/knn.cpp index c0ff0e6..e64eba5 100644 --- a/cpu/src/knn.cpp +++ b/cpu/src/knn.cpp @@ -12,7 +12,7 @@ std::pair _single_batch_knn(at::Tensor support, at::Tens if (support.size(0) < k) TORCH_CHECK(false, "Not enough points in support to find " + std::to_string(k) + " neighboors") - std::vector neighbors_indices(query.size(0) * k, -1); + std::vector neighbors_indices(query.size(0) * k, -1); std::vector neighbors_dists(query.size(0) * k, -1); auto options = torch::TensorOptions().dtype(torch::kLong).device(torch::kCPU); @@ -29,7 +29,7 @@ std::pair _single_batch_knn(at::Tensor support, at::Tens neighbors_dists, k); }); auto neighbors_dists_ptr = neighbors_dists.data(); - long* neighbors_indices_ptr = neighbors_indices.data(); + int64_t* neighbors_indices_ptr = neighbors_indices.data(); auto out = torch::from_blob(neighbors_indices_ptr, {query.size(0), k}, options = options); auto out_dists = torch::from_blob(neighbors_dists_ptr, {query.size(0), k}, options = options_dist); diff --git a/cpu/src/neighbors.cpp b/cpu/src/neighbors.cpp index 449a85e..6265e03 100644 --- a/cpu/src/neighbors.cpp +++ b/cpu/src/neighbors.cpp @@ -7,7 +7,7 @@ template int nanoflann_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, float radius, + vector& neighbors_indices, vector& dists, float radius, int max_num, int mode, bool sorted) { // Initiate variables @@ -138,9 +138,9 @@ int nanoflann_neighbors(vector& queries, vector& supports, template int batch_nanoflann_neighbors(vector& queries, vector& supports, - vector& q_batches, vector& s_batches, - vector& neighbors_indices, vector& dists, float radius, - int max_num, int mode, bool sorted) + vector& q_batches, vector& s_batches, + vector& neighbors_indices, vector& dists, + float radius, int max_num, int mode, bool sorted) { // Initiate variables // ****************** @@ -187,7 +187,6 @@ int batch_nanoflann_neighbors(vector& queries, vector& suppo // Search params nanoflann::SearchParams search_params; search_params.sorted = sorted; - std::chrono::microseconds duration_search(0); for (size_t i = 0; i < num_query_points; i++) { // Check if we changed batch @@ -295,7 +294,7 @@ int batch_nanoflann_neighbors(vector& queries, vector& suppo template void nanoflann_knn_neighbors(vector& queries, vector& supports, - vector& neighbors_indices, vector& dists, int k) + vector& neighbors_indices, vector& dists, int k) { // Nanoflann related variables // *************************** diff --git a/setup.py b/setup.py index 2284e3a..d743f59 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,7 @@ def get_cmdclass(): requirements = ["torch>=1.1.0"] url = "https://github.com/nicolas-chaulet/torch-points-kernels" -__version__ = "0.6.3" +__version__ = "0.6.4" setup( name="torch-points-kernels", version=__version__,