From 1757b0413d2d2fce046ab8b0d475bb834dcd6985 Mon Sep 17 00:00:00 2001 From: Ben Jeffery Date: Thu, 28 Apr 2022 14:29:17 +0100 Subject: [PATCH] Namespace subset flags --- c/CHANGELOG.rst | 8 ++++++-- c/tests/test_tables.c | 26 ++++++++++++++++---------- c/tskit/tables.c | 6 +++--- c/tskit/tables.h | 12 ++++++------ python/_tskitmodule.c | 6 +++--- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/c/CHANGELOG.rst b/c/CHANGELOG.rst index 2ed34d1395..fc34056b07 100644 --- a/c/CHANGELOG.rst +++ b/c/CHANGELOG.rst @@ -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. diff --git a/c/tests/test_tables.c b/c/tests/test_tables.c index ba5e0b3c3a..8a5d297f1c 100644 --- a/c/tests/test_tables.c +++ b/c/tests/test_tables.c @@ -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 @@ -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); @@ -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); @@ -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( @@ -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( @@ -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)); @@ -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); @@ -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)); diff --git a/c/tskit/tables.c b/c/tskit/tables.c index bb389140b3..0cda66dbb5 100644 --- a/c/tskit/tables.c +++ b/c/tskit/tables.c @@ -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) { @@ -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) { diff --git a/c/tskit/tables.h b/c/tskit/tables.h index e31ab0f4a9..716df8b268 100644 --- a/c/tskit/tables.h +++ b/c/tskit/tables.h @@ -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) @@ -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 @@ -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 diff --git a/python/_tskitmodule.c b/python/_tskitmodule.c index 454653afd7..f44631f620 100644 --- a/python/_tskitmodule.c +++ b/python/_tskitmodule.c @@ -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( @@ -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);