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
8 changes: 6 additions & 2 deletions c/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
- Rename TSK_TAKE_TABLES to TSK_TAKE_OWNERSHIP.
(:user:`benjeffery`, :issue:`2221`, :pr:`2222`)

- Rename all flags to ``simplify`` for example ``TSK_KEEP_INPUT_ROOTS`` becomes ``TSK_SIMPLIFY_KEEP_INPUT_ROOTS``
(:user:`benjeffery`, :issue:`1720`, :pr:`2226`))

- ``TSK_DEBUG``, ``TSK_NO_INIT``, ``TSK_NO_CHECK_INTEGRITY`` and ``TSK_TAKE_OWNERSHIP`` have moved to ``core.h``
(:user:`benjeffery`, :issue:`2218`, :pr:`2230`))

- Rename several flags:
- All flags to ``simplify`` for example ``TSK_KEEP_INPUT_ROOTS`` becomes ``TSK_SIMPLIFY_KEEP_INPUT_ROOTS``.
- All flags to ``subset`` for example ``TSK_KEEP_UNREFERENCED`` becomes ``TSK_SUBSET_KEEP_UNREFERENCED``.

(:user:`benjeffery`, :issue:`1720`, :pr:`2226`, :pr:`2229`)

**Features**

- Make dumping of tables and tree sequences to disk a zero-copy operation.
Expand Down
26 changes: 16 additions & 10 deletions c/tests/test_tables.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2021 Tskit Developers
* Copyright (c) 2019-2022 Tskit Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -8128,7 +8128,7 @@ test_sort_tables_canonical(void)
parse_sites(sites, &t1.sites);
parse_mutations(mutations, &t1.mutations);

ret = tsk_table_collection_canonicalise(&t1, TSK_KEEP_UNREFERENCED);
ret = tsk_table_collection_canonicalise(&t1, TSK_SUBSET_KEEP_UNREFERENCED);
CU_ASSERT_EQUAL_FATAL(ret, 0);

parse_nodes(nodes_sorted, &t2.nodes);
Expand Down Expand Up @@ -9414,7 +9414,8 @@ test_table_collection_subset_with_options(tsk_flags_t options)
// unless NO_CHANGE_POPULATIONS is provided
ret = tsk_table_collection_copy(&tables, &tables_copy, TSK_NO_INIT | options);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_subset(&tables_copy, NULL, 0, TSK_NO_CHANGE_POPULATIONS);
ret = tsk_table_collection_subset(
&tables_copy, NULL, 0, TSK_SUBSET_NO_CHANGE_POPULATIONS);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_EQUAL_FATAL(tables_copy.nodes.num_rows, 0);
CU_ASSERT_EQUAL_FATAL(tables_copy.individuals.num_rows, 0);
Expand All @@ -9426,7 +9427,8 @@ test_table_collection_subset_with_options(tsk_flags_t options)
// or KEEP_UNREFERENCED
ret = tsk_table_collection_copy(&tables, &tables_copy, TSK_NO_INIT | options);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_subset(&tables_copy, NULL, 0, TSK_KEEP_UNREFERENCED);
ret = tsk_table_collection_subset(
&tables_copy, NULL, 0, TSK_SUBSET_KEEP_UNREFERENCED);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_EQUAL_FATAL(tables_copy.nodes.num_rows, 0);
CU_ASSERT_FATAL(
Expand All @@ -9438,8 +9440,8 @@ test_table_collection_subset_with_options(tsk_flags_t options)
// or both
ret = tsk_table_collection_copy(&tables, &tables_copy, TSK_NO_INIT | options);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_subset(
&tables_copy, NULL, 0, TSK_KEEP_UNREFERENCED | TSK_NO_CHANGE_POPULATIONS);
ret = tsk_table_collection_subset(&tables_copy, NULL, 0,
TSK_SUBSET_KEEP_UNREFERENCED | TSK_SUBSET_NO_CHANGE_POPULATIONS);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_EQUAL_FATAL(tables_copy.nodes.num_rows, 0);
CU_ASSERT_FATAL(
Expand All @@ -9455,7 +9457,8 @@ test_table_collection_subset_with_options(tsk_flags_t options)
}
ret = tsk_table_collection_copy(&tables, &tables_copy, TSK_NO_INIT | options);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_subset(&tables_copy, nodes, 4, TSK_KEEP_UNREFERENCED);
ret = tsk_table_collection_subset(
&tables_copy, nodes, 4, TSK_SUBSET_KEEP_UNREFERENCED);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_FATAL(tsk_table_collection_equals(&tables, &tables_copy, 0));

Expand All @@ -9479,9 +9482,11 @@ test_table_collection_subset_with_options(tsk_flags_t options)
}
ret = tsk_table_collection_copy(&tables, &tables_copy, TSK_NO_INIT | options);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_subset(&tables_copy, nodes, 4, TSK_KEEP_UNREFERENCED);
ret = tsk_table_collection_subset(
&tables_copy, nodes, 4, TSK_SUBSET_KEEP_UNREFERENCED);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_subset(&tables_copy, nodes, 4, TSK_KEEP_UNREFERENCED);
ret = tsk_table_collection_subset(
&tables_copy, nodes, 4, TSK_SUBSET_KEEP_UNREFERENCED);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = (int) tsk_table_collection_check_integrity(&tables_copy, 0);
CU_ASSERT_EQUAL_FATAL(ret, 0);
Expand Down Expand Up @@ -9554,7 +9559,8 @@ test_table_collection_subset_unsorted(void)
}
ret = tsk_table_collection_copy(&tables, &tables_copy, TSK_NO_INIT);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = tsk_table_collection_subset(&tables_copy, nodes, 3, TSK_KEEP_UNREFERENCED);
ret = tsk_table_collection_subset(
&tables_copy, nodes, 3, TSK_SUBSET_KEEP_UNREFERENCED);
CU_ASSERT_EQUAL_FATAL(ret, 0);
CU_ASSERT_FATAL(tsk_table_collection_equals(&tables, &tables_copy, 0));

Expand Down
6 changes: 3 additions & 3 deletions c/tskit/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -11617,7 +11617,7 @@ tsk_table_collection_canonicalise(tsk_table_collection_t *self, tsk_flags_t opti
tsk_id_t k;
tsk_id_t *nodes = NULL;
tsk_table_sorter_t sorter;
tsk_flags_t subset_options = options & TSK_KEEP_UNREFERENCED;
tsk_flags_t subset_options = options & TSK_SUBSET_KEEP_UNREFERENCED;

ret = tsk_table_sorter_init(&sorter, self, 0);
if (ret != 0) {
Expand Down Expand Up @@ -12174,8 +12174,8 @@ tsk_table_collection_subset(tsk_table_collection_t *self, const tsk_id_t *nodes,
tsk_population_t pop;
tsk_site_t site;
tsk_mutation_t mut;
bool keep_unreferenced = !!(options & TSK_KEEP_UNREFERENCED);
bool no_change_populations = !!(options & TSK_NO_CHANGE_POPULATIONS);
bool keep_unreferenced = !!(options & TSK_SUBSET_KEEP_UNREFERENCED);
bool no_change_populations = !!(options & TSK_SUBSET_NO_CHANGE_POPULATIONS);

ret = tsk_table_collection_copy(self, &tables, 0);
if (ret != 0) {
Expand Down
12 changes: 6 additions & 6 deletions c/tskit/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ typedef struct {
#define TSK_SIMPLIFY_KEEP_UNARY_IN_INDIVIDUALS (1 << 6)

/* Flags for subset() */
#define TSK_NO_CHANGE_POPULATIONS (1 << 0)
#define TSK_KEEP_UNREFERENCED (1 << 1)
#define TSK_SUBSET_NO_CHANGE_POPULATIONS (1 << 0)
#define TSK_SUBSET_KEEP_UNREFERENCED (1 << 1)

/* Flags for check_integrity */
#define TSK_CHECK_EDGE_ORDERING (1 << 0)
Expand Down Expand Up @@ -3804,7 +3804,7 @@ tree sequence sortedness requirements.
Options can be specified by providing one or more of the following bitwise
flags:

TSK_KEEP_UNREFERENCED
TSK_SUBSET_KEEP_UNREFERENCED
By default, this will remove any unreferenced sites, populations, and
individuals. If this flag is provided, these will be retained, with
unreferenced individuals and populations at the end of the tables, in
Expand Down Expand Up @@ -3918,14 +3918,14 @@ This function does *not* require the tables to be sorted.
Options can be specified by providing one or more of the following bitwise
flags:

TSK_NO_CHANGE_POPULATIONS
TSK_SUBSET_NO_CHANGE_POPULATIONS
If this flag is provided, the population table will not be changed
in any way.

TSK_KEEP_UNREFERENCED
TSK_SUBSET_KEEP_UNREFERENCED
If this flag is provided, then unreferenced sites, individuals, and populations
will not be removed. If so, the site and individual tables will not be changed,
and (unless TSK_NO_CHANGE_POPULATIONS is also provided) unreferenced
and (unless TSK_SUBSET_NO_CHANGE_POPULATIONS is also provided) unreferenced
populations will be placed last, in their original order.

.. note:: Migrations are currently not supported by susbset, and an error will
Expand Down
6 changes: 3 additions & 3 deletions python/_tskitmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6706,10 +6706,10 @@ TableCollection_subset(TableCollection *self, PyObject *args, PyObject *kwds)
shape = PyArray_DIMS(nodes_array);
num_nodes = (tsk_size_t) shape[0];
if (!reorder_populations) {
options |= TSK_NO_CHANGE_POPULATIONS;
options |= TSK_SUBSET_NO_CHANGE_POPULATIONS;
}
if (!remove_unreferenced) {
options |= TSK_KEEP_UNREFERENCED;
options |= TSK_SUBSET_KEEP_UNREFERENCED;
}

err = tsk_table_collection_subset(
Expand Down Expand Up @@ -6972,7 +6972,7 @@ TableCollection_canonicalise(TableCollection *self, PyObject *args, PyObject *kw
goto out;
}
if (!remove_unreferenced) {
options |= TSK_KEEP_UNREFERENCED;
options |= TSK_SUBSET_KEEP_UNREFERENCED;
}

err = tsk_table_collection_canonicalise(self->tables, options);
Expand Down