Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function get_solution_count. #72

Merged
merged 25 commits into from
Dec 1, 2023
Merged
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
58bb5dc
Add function get_solution_count.
jwg4 Nov 14, 2023
19687bf
Declare the function here.
jwg4 Nov 14, 2023
efc34e6
Remove two lines left over from copy-paste.
jwg4 Nov 14, 2023
6761cd9
Add a single test.
jwg4 Nov 15, 2023
584448d
Add numpy import back in.
jwg4 Nov 15, 2023
d214e73
Add two more similar tests.
jwg4 Nov 15, 2023
5525dfa
test solution_count on small_trimino problem
parmentelat Nov 15, 2023
26d8435
solution_count tested through another problem
parmentelat Nov 15, 2023
4faecc5
more tests
parmentelat Nov 15, 2023
40fa64b
Merge pull request #73 from parmentelat/all_solutions
jwg4 Nov 15, 2023
92066c6
Import the two new problems.
jwg4 Nov 15, 2023
f335125
Formatting cleanups.
jwg4 Nov 15, 2023
1dcf285
Count solutions in C code.
jwg4 Nov 18, 2023
d75da3f
Test solution count with blank rows and repeated rows.
jwg4 Nov 18, 2023
1515a2f
Comment these new tests.
jwg4 Nov 18, 2023
1d351f2
Add a test for solution count.
jwg4 Nov 18, 2023
7428322
Fix long lines.
jwg4 Nov 18, 2023
0561acc
Preminor version 1.4.0a0
jwg4 Nov 18, 2023
14d9cb0
remove declaration of unused variable that triggers a build-time war…
parmentelat Nov 19, 2023
12c94b9
trailing spaces and trailing newlines
parmentelat Nov 19, 2023
2737c18
trailing spaces in the .github area
parmentelat Nov 19, 2023
a9c94d3
Merge pull request #82 from parmentelat/unused-var
jwg4 Nov 30, 2023
d7975ff
Merge pull request #81 from parmentelat/spaces
jwg4 Nov 30, 2023
134ddfc
Import from exact_cover_impl.
jwg4 Nov 30, 2023
81a908f
Add some info about this function to the docs.
jwg4 Nov 30, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/c-tests.yml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ name: Tests for C code

on:
push:
branches:
branches:
- main
pull_request:
branches: '**'
2 changes: 1 addition & 1 deletion .github/workflows/poetry-publish-sdist.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Deploy sdist to pypi
on:
push:
branches:
branches:
- main

jobs:
2 changes: 1 addition & 1 deletion .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ name: Valgrind

on:
push:
branches:
branches:
- main
pull_request:
branches: '**'
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -130,5 +130,3 @@ Acknowledgements
Thanks very much to Moy Easwaran (https://github.com/moygit) for his inspiring work!

Munit aka µnit (https://nemequ.github.io/munit/) is a wonderful unit testing framework for C code.


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ numpy = [
setuptools = ">=51.1.2"

# When we build wheels, we always do so with an explicit pinned numpy version
#
#
[tool.poetry.group.wheel_builder]
optional = true

2 changes: 0 additions & 2 deletions src/dlx.c
Original file line number Diff line number Diff line change
@@ -100,5 +100,3 @@ int dlx_get_solution_count(int rows, int cols, char matrix[]) {
free(solution);
return solution_count;
}


1 change: 0 additions & 1 deletion src/dlx.h
Original file line number Diff line number Diff line change
@@ -9,4 +9,3 @@ int dlx_get_exact_cover(int, int, char [], int*);
int dlx_get_solution_count(int, int, char []);

#endif

8 changes: 4 additions & 4 deletions src/exact_cover.c
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ static bool not_2d_int_array(PyArrayObject *in_array) {
PyErr_SetString(PyExc_ValueError, _EXACT_COVER_NP_DIM_ERROR_);
return 1;
}
if (PyArray_TYPE(in_array) != NPY_BOOL) {
if (PyArray_TYPE(in_array) != NPY_BOOL) {
PyErr_SetString(PyExc_TypeError, _EXACT_COVER_NP_TYPE_ERROR_);
return 1;
}
if (!(PyArray_FLAGS(in_array) & NPY_ARRAY_C_CONTIGUOUS)) {
if (!(PyArray_FLAGS(in_array) & NPY_ARRAY_C_CONTIGUOUS)) {
PyErr_SetString(PyExc_TypeError, _EXACT_COVER_NP_ORDER_ERROR_);
return 1;
}
@@ -48,7 +48,7 @@ static PyObject* get_exact_cover(PyObject* self, PyObject* args)

/* Check that we got a 2-dimensional array of dtype='bool'. */
if (not_2d_int_array(in_array)) return NULL;

/* Get the data. */
dims = PyArray_DIMS(in_array);
rows = (int) dims[0], cols = (int) dims[1];
@@ -79,7 +79,7 @@ static PyObject* get_solution_count(PyObject* self, PyObject* args)

/* Check that we got a 2-dimensional array of dtype='bool'. */
if (not_2d_int_array(in_array)) return NULL;

/* Get the data. */
dims = PyArray_DIMS(in_array);
rows = (int) dims[0], cols = (int) dims[1];
5 changes: 2 additions & 3 deletions src/quad_linked_list.c
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ list insert_horizontally(list orig_list, node_ptr new_node_ptr) {
orig_list->left->right = new_node_ptr;
orig_list->left = new_node_ptr;
}

return new_node_ptr;
}

@@ -117,7 +117,7 @@ list insert_vertically(list orig_list, node_ptr new_node_ptr) {
orig_list->up->down = new_node_ptr;
orig_list->up = new_node_ptr;
}

return new_node_ptr;
}

@@ -242,4 +242,3 @@ void destroy_entire_grid (list grid) {
}
return;
}

2 changes: 0 additions & 2 deletions src/quad_linked_list.h
Original file line number Diff line number Diff line change
@@ -64,5 +64,3 @@ void destroy_column_unsafely (list);
void destroy_entire_grid (list);

#endif


2 changes: 0 additions & 2 deletions src/sparse_matrix.c
Original file line number Diff line number Diff line change
@@ -104,5 +104,3 @@ void print_column(list col, int row_count) {
for (; row_num < row_count; ++row_num) printf("0,");
putchar('\n');
}


1 change: 0 additions & 1 deletion src/sparse_matrix.h
Original file line number Diff line number Diff line change
@@ -15,4 +15,3 @@ void print_sparse_matrix_transpose(list, int);
void print_column(list, int);

#endif

10 changes: 5 additions & 5 deletions tests/test_quad_linked_list.c
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
static MunitResult test_new_list_is_empty(const MunitParameter params[], void* data)
{
list my_list = create_empty_list();

munit_assert(is_empty(my_list));
return MUNIT_OK;
}
@@ -17,7 +17,7 @@ static MunitResult test_add_one_item(const MunitParameter params[], void* data)
{
int item1 = 1;
list my_list = create_empty_list();

my_list = insert_horizontally(my_list, create_node(create_data(item1, NULL)));
munit_assert(not_empty(my_list));
return MUNIT_OK;
@@ -27,7 +27,7 @@ static MunitResult test_can_retrieve_one_item(const MunitParameter params[], voi
{
int item1 = 1;
list my_list = create_empty_list();

my_list = insert_horizontally(my_list, create_node(create_data(item1, NULL)));
munit_assert(get_data(my_list)->data == 1);
return MUNIT_OK;
@@ -37,7 +37,7 @@ static MunitResult test_quad_linked_list(const MunitParameter params[], void* da
{
int item1 = 1, item2 = 2, item3 = 3;
list save_list, my_list = create_empty_list();

munit_assert(is_empty(my_list));
my_list = insert_horizontally(my_list, create_node(create_data(item3, NULL)));
// Inserted one item; list should not be empty:
@@ -125,7 +125,7 @@ static MunitResult test_quad_linked_list(const MunitParameter params[], void* da
item1 = 1; item2 = 2; item3 = 3;
my_list = create_empty_list();
// New list should be empty:

//DEBUG_PRINT(1, "Check: emptiness.\n");
munit_assert(is_empty(my_list));
my_list = insert_vertically(my_list, create_node(create_data(item3, NULL)));
2 changes: 1 addition & 1 deletion tests/test_sparse_matrix.c
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

#define HSIZE 9
#define VSIZE 15


static MunitResult test_choose_column_with_min_data(const MunitParameter params[], void* data)
{