Skip to content

Commit

Permalink
Add the most trivial unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ybubnov committed Sep 22, 2024
1 parent a7a0285 commit 0372213
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ include_directories(src)

aux_source_directory(src torch_delaunay_SOURCES)

# Add the testing directory.
add_subdirectory(test)


add_library(torch_delaunay SHARED ${torch_delaunay_SOURCES})
set_target_properties(torch_delaunay PROPERTIES CXX_STANDARD 17)
Expand Down
2 changes: 1 addition & 1 deletion include/torch_delaunay/torch_delaunay.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#include <torch_delaunay/triangle.h>
#include <torch_delaunay/predicates.h>
#include <torch_delaunay/triangle.h>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from setuptools import setup, Extension
from setuptools import setup
from torch.utils.cpp_extension import CppExtension, BuildExtension

setup(
Expand Down
10 changes: 4 additions & 6 deletions src/triangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ _lawson_flip_out(
auto index_twin = halfedges.index_select(0, pl).index_select(1, pr);
std::cout << "OPPOSITE" << std::endl << index_twin.to_dense() << std::endl;

// TODO: implement diag for sparse coo tensor.
// TODO: implement diag for sparse coordinate tensor.
auto twins = index_twin.to_dense().diag();
twins = twins - 1;
std::cout << "TWINS" << std::endl << twins << std::endl;
Expand Down Expand Up @@ -267,8 +267,7 @@ shull2d(const torch::Tensor& points)
// Find the third point such that forms the smallest circumcircle with i0 and i1.
{
// const auto radiuses = torch_delaunay::en::circumradius2d(points, p0, p1);
const auto radiuses
= circumradius2d(p0.repeat({n, 1}), p1.repeat({n, 1}), points);
const auto radiuses = circumradius2d(p0.repeat({n, 1}), p1.repeat({n, 1}), points);

torch::Tensor values, indices;
std::tie(values, indices)
Expand Down Expand Up @@ -420,9 +419,8 @@ shull2d(const torch::Tensor& points)
}

// Add a new triangle.
print_triangle("Te", iq, i, ie);
std::cout << " te " << orient2d(pi, pq, pe)[0].item<int64_t>()
<< std::endl;
print_triangle("T_e", iq, i, ie);
std::cout << " t_e " << orient2d(pi, pq, pe)[0].item<int64_t>() << std::endl;

faces.push_back(iq.item<int64_t>());
faces.push_back(ie.item<int64_t>());
Expand Down
22 changes: 22 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
find_package(Boost COMPONENTS unit_test_framework REQUIRED)

# Define the c++ standard.
add_definitions(-std=c++17)

include_directories()


file(GLOB torch_delaunay_TEST_SOURCES *.cc)

foreach(torch_delaunay_TEST_SOURCE ${torch_delaunay_TEST_SOURCES})
# Extract extension from the file name.
get_filename_component(torch_delaunay_TEST ${torch_delaunay_TEST_SOURCE} NAME_WE)

add_executable(${torch_delaunay_TEST} ${torch_delaunay_TEST_SOURCE})
target_link_libraries(${torch_delaunay_TEST} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
target_link_libraries(${torch_delaunay_TEST} "${TORCH_LIBRARIES}")
target_link_libraries(${torch_delaunay_TEST} torch_delaunay)

# Define a new test from the source file.
add_test(NAME ${torch_delaunay_TEST} COMMAND ${torch_delaunay_TEST})
endforeach(torch_delaunay_TEST_SOURCE)
26 changes: 26 additions & 0 deletions test/triangle_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE quadtree

#include <boost/test/included/unit_test.hpp>

#include <torch_delaunay.h>


using namespace torch_delaunay;


BOOST_AUTO_TEST_SUITE(TestShull)


BOOST_AUTO_TEST_CASE(test_shull2d)
{
auto options = torch::TensorOptions().dtype(torch::kFloat64).device(torch::kCPU);
auto points = torch::tensor({{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}}, options);

auto simplices = shull2d(points);

BOOST_CHECK_EQUAL(simplices.sizes(), torch::IntArrayRef({1, 3}));
}


BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 0372213

Please sign in to comment.