From 53aad948430246ddb41cf9c3aae2dba9db6c4766 Mon Sep 17 00:00:00 2001 From: "James D. Mitchell" Date: Mon, 7 Apr 2025 18:25:13 +0200 Subject: [PATCH 1/2] Compiles --- GNUmakefile.in | 11 +-- gapbind14/include/gapbind14/cpp_fn.hpp | 27 ++++++ src/bipart.cpp | 41 +++++---- src/cong.cpp | 116 +++++++++++++------------ src/conglatt.cpp | 6 +- src/froidure-pin-base.cpp | 12 ++- src/froidure-pin-fallback.cpp | 4 +- src/froidure-pin.hpp | 22 +++-- src/pkg.cpp | 115 ++++++++---------------- src/pkg.hpp | 14 +-- src/to_cpp.hpp | 57 ++++++------ src/to_gap.hpp | 82 +++++++++-------- 12 files changed, 259 insertions(+), 248 deletions(-) diff --git a/GNUmakefile.in b/GNUmakefile.in index 7940cee7a..4e7a0b2b1 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -3,7 +3,7 @@ # KEXT_NAME = semigroups -KEXT_CXXFLAGS = @LIBSEMIGROUPS_CFLAGS@ -std=gnu++14 -O3 +KEXT_CXXFLAGS = @LIBSEMIGROUPS_CFLAGS@ -std=gnu++17 -O3 KEXT_LDFLAGS = @LIBSEMIGROUPS_RPATH@ @LIBSEMIGROUPS_LIBS@ # configure settings @@ -46,10 +46,11 @@ ifdef WITH_INCLUDED_LIBSEMIGROUPS # FIXME(later) all the include paths should point into bin/include/ and not to # the sources, or otherwise we should stop make installing into bin ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED -KEXT_CPPFLAGS += -Ilibsemigroups/extern/HPCombi/include -KEXT_CPPFLAGS += -Ilibsemigroups/extern/HPCombi/include/fallback +KEXT_CPPFLAGS += -Ilibsemigroups/third_party/HPCombi/include +KEXT_CPPFLAGS += -Ilibsemigroups/third_party/HPCombi/third_party/ endif -KEXT_CPPFLAGS += -Ilibsemigroups/extern/fmt-8.0.1/include +KEXT_CPPFLAGS += -Ilibsemigroups/third_party/fmt-11.1.4/include +KEXT_CPPFLAGS += -Ilibsemigroups/third_party/magic_enum-0.9.7/include KEXT_CPPFLAGS += -Ilibsemigroups/include endif KEXT_CPPFLAGS += -DFMT_HEADER_ONLY @@ -101,7 +102,7 @@ lint: etc/cpplint.sh format: - clang-format -i src/*.*pp + clang-format -i src/*.[hc] .PHONY: lint format diff --git a/gapbind14/include/gapbind14/cpp_fn.hpp b/gapbind14/include/gapbind14/cpp_fn.hpp index af973883f..d80d28bf4 100644 --- a/gapbind14/include/gapbind14/cpp_fn.hpp +++ b/gapbind14/include/gapbind14/cpp_fn.hpp @@ -42,6 +42,8 @@ namespace gapbind14 { // Overloading //////////////////////////////////////////////////////////////////////// + static constexpr auto const_ = std::true_type{}; + template struct overload_cast_impl { constexpr overload_cast_impl() {} @@ -94,6 +96,11 @@ namespace gapbind14 { using type = R(A...); }; + template + struct remove_class { + using type = R(A...); + }; + template struct strip_function_object { using type = typename remove_class::type; @@ -186,11 +193,21 @@ namespace gapbind14 { struct CppFunction : CppFunctionBase {}; + // noexcept free functions + template + struct CppFunction + : CppFunctionBase {}; + // Function pointers . . . template struct CppFunction : CppFunctionBase {}; + // noexcept function pointer + template + struct CppFunction + : CppFunctionBase {}; + // Member functions . . . template struct CppFunction @@ -201,6 +218,16 @@ namespace gapbind14 { struct CppFunction : CppMemFnBase {}; + // Const noexcept member functions + template + struct CppFunction + : CppMemFnBase {}; + + // Non-const noexcept member functions + template + struct CppFunction + : CppMemFnBase {}; + // std::function objects template struct CppFunction> diff --git a/src/bipart.cpp b/src/bipart.cpp index c9664fddb..389cd6b20 100644 --- a/src/bipart.cpp +++ b/src/bipart.cpp @@ -34,16 +34,15 @@ #include "compiled.h" // libsemigroups headers -#include "libsemigroups/bipart.hpp" // for Blocks, Bipartition, validate -#include "libsemigroups/report.hpp" // for Reporter, etc -#include "libsemigroups/timer.hpp" // for Timer -#include "semigroups-config.hpp" // for SEMIGROUPS_KERNEL_DEBUG +#include "libsemigroups/bipart.hpp" // for Blocks, Bipartition, validate +#include "libsemigroups/detail/report.hpp" // for Reporter, etc +#include "libsemigroups/detail/timer.hpp" // for Timer +#include "semigroups-config.hpp" // for SEMIGROUPS_KERNEL_DEBUG #include "gapbind14/gapbind14.hpp" // for GAPBIND14_TRY using libsemigroups::Bipartition; using libsemigroups::Blocks; -using libsemigroups::REPORTER; using libsemigroups::detail::Timer; // Global variables @@ -277,7 +276,7 @@ Obj BIPART_PROD(Obj x, Obj y) { Bipartition* yy = bipart_get_cpp(y); Bipartition* z = new Bipartition(xx->degree()); - z->product_inplace(*xx, *yy); + z->product_inplace_no_checks(*xx, *yy); return bipart_new_obj(static_cast(z)); } @@ -706,11 +705,11 @@ Obj BLOCKS_NC(Obj self, Obj gap_blocks) { SEMIGROUPS_ASSERT(IS_INTOBJ(ELM_LIST(block, j))); int jj = INT_INTOBJ(ELM_LIST(block, j)); if (jj < 0) { - blocks->set_block(-jj - 1, i - 1); - blocks->set_is_transverse_block(i - 1, false); + blocks->block(-jj - 1, i - 1); + blocks->is_transverse_block(i - 1, false); } else { - blocks->set_block(jj - 1, i - 1); - blocks->set_is_transverse_block(i - 1, true); + blocks->block(jj - 1, i - 1); + blocks->is_transverse_block(i - 1, true); } } } @@ -1000,8 +999,8 @@ Obj BLOCKS_LEFT_ACT(Obj self, Obj blocks_gap, Obj x_gap) { tab[j] = next; next++; } - out_blocks->set_block(i, tab[j]); - out_blocks->set_is_transverse_block(tab[j], _BUFFER_bool[j]); + out_blocks->block(i, tab[j]); + out_blocks->is_transverse_block(tab[j], _BUFFER_bool[j]); } #ifdef SEMIGROUPS_KERNEL_DEBUG @@ -1055,8 +1054,8 @@ Obj BLOCKS_RIGHT_ACT(Obj self, Obj blocks_gap, Obj x_gap) { tab[j] = next; next++; } - out_blocks->set_block(i - n, tab[j]); - out_blocks->set_is_transverse_block(tab[j], _BUFFER_bool[j]); + out_blocks->block(i - n, tab[j]); + out_blocks->is_transverse_block(tab[j], _BUFFER_bool[j]); } #ifdef SEMIGROUPS_KERNEL_DEBUG libsemigroups::validate(*out_blocks); @@ -1210,7 +1209,7 @@ Obj BLOCKS_INV_RIGHT(Obj self, Obj blocks_gap, Obj x_gap) { continue; } } - if (junk == static_cast(-1)) { + if (junk == (uint32_t) -1) { junk = next; next++; } @@ -1399,10 +1398,10 @@ class IdempotentCounter { } std::vector count() { - libsemigroups::THREAD_ID_MANAGER.reset(); - REPORT_DEFAULT("using %llu / %llu additional threads", - _nr_threads, - std::thread::hardware_concurrency()); + libsemigroups::detail::reset_thread_ids(); + libsemigroups::report_default("using {} / {} additional threads", + _nr_threads, + std::thread::hardware_concurrency()); Timer timer; for (size_t i = 0; i < _nr_threads; i++) { @@ -1414,7 +1413,7 @@ class IdempotentCounter { _threads[i].join(); } - REPORT_TIME(timer); + libsemigroups::report_elapsed_time("", timer); size_t max = *max_element(_ranks.begin(), _ranks.end()) + 1; std::vector out = std::vector(max, 0); @@ -1450,7 +1449,7 @@ class IdempotentCounter { } } } - REPORT_DEFAULT("finished in %llu", timer.string().c_str()); + libsemigroups::report_default("finished in {}", timer); } // This is basically the same as BLOCKS_E_TESTER, but is required because we diff --git a/src/cong.cpp b/src/cong.cpp index 572476d7f..1beb1b155 100644 --- a/src/cong.cpp +++ b/src/cong.cpp @@ -37,7 +37,6 @@ // libsemigroups headers #include "libsemigroups/bipart.hpp" // for Bipartition -#include "libsemigroups/cong-intf.hpp" // for congruence_kind #include "libsemigroups/cong.hpp" // for Congruence #include "libsemigroups/constants.hpp" // for UNDEFINED etc #include "libsemigroups/froidure-pin.hpp" // for FroidurePin @@ -54,7 +53,10 @@ namespace libsemigroups { namespace gapbind14 { template <> - struct IsGapBind14Type : std::true_type {}; + struct IsGapBind14Type> + : std::true_type { + static constexpr std::string_view name = "Congruence"; + }; } // namespace gapbind14 @@ -89,58 +91,60 @@ void init_cong(gapbind14::Module& m) { // Cannot use FroidurePinBase rather than the specialisations because there's // no constructor for a Congruence from a FroidurePinBase&. - gapbind14::class_("Congruence") - .def(gapbind14::init const&>{}, - "make_from_froidurepin_bipartition") - .def(gapbind14::init> const&>{}, - "make_from_froidurepin_bmat") - .def(gapbind14::init const&>{}, - "make_from_froidurepin_bmat8") - .def(gapbind14::init const&>{}, - "make_from_froidurepin_pbr") -#ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED - .def(gapbind14::init> const&>{}, - "make_from_froidurepin_leastpperm") - .def(gapbind14::init> const&>{}, - "make_from_froidurepin_leasttransf") -#endif - .def(gapbind14::init> const&>{}, - "make_from_froidurepin_transfUInt2") - .def(gapbind14::init> const&>{}, - "make_from_froidurepin_transfUInt4") - .def(gapbind14::init> const&>{}, - "make_from_froidurepin_ppermUInt2") - .def(gapbind14::init> const&>{}, - "make_from_froidurepin_ppermUInt4") - .def(gapbind14::init{}, - "make_from_fpsemigroup") - .def(gapbind14::init>{}, - "make_from_froidurepinbase") - .def(gapbind14::init{}, - "make_from_table") - .def("set_number_of_generators", &Congruence::set_number_of_generators) - .def("number_of_pairs", &Congruence::number_of_generating_pairs) - .def("add_pair", - overload_cast( - &Congruence::add_pair)) - .def("number_of_classes", &Congruence::number_of_classes) - .def("word_to_class_index", &Congruence::word_to_class_index) - .def("class_index_to_word", &Congruence::class_index_to_word) - .def("contains", &Congruence::contains) - .def("less", &Congruence::less) - .def("add_runner", - &Congruence::add_runner) - .def("is_quotient_obviously_infinite", - &Congruence::is_quotient_obviously_infinite) - .def("ntc", - [](Congruence& C) { - return gapbind14::make_iterator(C.cbegin_ntc(), C.cend_ntc()); - }) - .def("quotient_froidure_pin", &Congruence::quotient_froidure_pin); + // gapbind14::class_("Congruence") + // .def(gapbind14::init + // const&>{}, + // "make_from_froidurepin_bipartition") + // .def(gapbind14::init> const&>{}, + // "make_from_froidurepin_bmat") + // .def(gapbind14::init const&>{}, + // "make_from_froidurepin_bmat8") + // .def(gapbind14::init const&>{}, + // "make_from_froidurepin_pbr") + // #ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED + // .def(gapbind14::init> const&>{}, + // "make_from_froidurepin_leastpperm") + // .def(gapbind14::init> const&>{}, + // "make_from_froidurepin_leasttransf") + // #endif + // .def(gapbind14::init> const&>{}, + // "make_from_froidurepin_transfUInt2") + // .def(gapbind14::init> const&>{}, + // "make_from_froidurepin_transfUInt4") + // .def(gapbind14::init> const&>{}, + // "make_from_froidurepin_ppermUInt2") + // .def(gapbind14::init> const&>{}, + // "make_from_froidurepin_ppermUInt4") + // .def(gapbind14::init{}, + // "make_from_fpsemigroup") + // .def(gapbind14::init>{}, + // "make_from_froidurepinbase") + // .def(gapbind14::init{}, + // "make_from_table") + // .def("set_number_of_generators", + // &Congruence::set_number_of_generators) .def("number_of_pairs", + // &Congruence::number_of_generating_pairs) .def("add_pair", + // overload_cast( + // &Congruence::add_pair)) + // .def("number_of_classes", &Congruence::number_of_classes) + // .def("word_to_class_index", &Congruence::word_to_class_index) + // .def("class_index_to_word", &Congruence::class_index_to_word) + // .def("contains", &Congruence::contains) + // .def("less", &Congruence::less) + // .def("add_runner", + // &Congruence::add_runner) + // .def("is_quotient_obviously_infinite", + // &Congruence::is_quotient_obviously_infinite) + // .def("ntc", + // [](Congruence& C) { + // return gapbind14::make_iterator(C.cbegin_ntc(), C.cend_ntc()); + // }) + // .def("quotient_froidure_pin", &Congruence::quotient_froidure_pin); } diff --git a/src/conglatt.cpp b/src/conglatt.cpp index 24df0f30a..c78f50b2f 100644 --- a/src/conglatt.cpp +++ b/src/conglatt.cpp @@ -42,8 +42,8 @@ // libsemigroups headers #include "libsemigroups/adapters.hpp" // for Hash -#include "libsemigroups/report.hpp" // for should_report -#include "libsemigroups/string.hpp" // for group_digits +#include "libsemigroups/detail/report.hpp" // for should_report +#include "libsemigroups/detail/string.hpp" // for group_digits // namespace semigroups { @@ -215,7 +215,7 @@ namespace semigroups { auto start_time = std::chrono::high_resolution_clock::now(); auto last_report = start_time; uint32_t last_count = 1; - bool report = libsemigroups::report::should_report(); + bool report = libsemigroups::reporting_enabled(); std::vector gens; gens.reserve(LEN_LIST(list)); diff --git a/src/froidure-pin-base.cpp b/src/froidure-pin-base.cpp index 1e01da412..82b254e24 100644 --- a/src/froidure-pin-base.cpp +++ b/src/froidure-pin-base.cpp @@ -46,16 +46,20 @@ void init_froidure_pin_base(gapbind14::Module& m) { return S->right_cayley_graph(); }) .def("factorisation", - [](FroidurePin_ S, size_t i) { return S->factorisation(i); }) + [](FroidurePin_ S, size_t i) { + return libsemigroups::froidure_pin::factorisation(*S, i); + }) .def("minimal_factorisation", - [](FroidurePin_ S, size_t i) { return S->minimal_factorisation(i); }) + [](FroidurePin_ S, size_t i) { + return libsemigroups::froidure_pin::minimal_factorisation(*S, i); + }) .def("product_by_reduction", [](FroidurePin_ S, size_t i, size_t j) { - return S->product_by_reduction(i, j); + return libsemigroups::froidure_pin::product_by_reduction(*S, i, j); }) .def("current_position", [](FroidurePin_ S, libsemigroups::word_type const& w) { - return S->current_position(w); + return libsemigroups::froidure_pin::current_position(*S, w); }) .def("current_size", [](FroidurePin_ S) { return S->current_size(); }) .def("size", [](FroidurePin_ S) { return S->size(); }) diff --git a/src/froidure-pin-fallback.cpp b/src/froidure-pin-fallback.cpp index f8ab1af22..d6b29d43d 100644 --- a/src/froidure-pin-fallback.cpp +++ b/src/froidure-pin-fallback.cpp @@ -32,8 +32,8 @@ #include "semigroups-debug.hpp" // for SEMIGROUPS_ASSERT // libsemigroups headers -#include "libsemigroups/report.hpp" // for REPORTER, Reporter -#include "libsemigroups/timer.hpp" // for Timer +#include "libsemigroups/detail/report.hpp" // for REPORTER, Reporter +#include "libsemigroups/detail/timer.hpp" // for Timer using libsemigroups::detail::Timer; diff --git a/src/froidure-pin.hpp b/src/froidure-pin.hpp index d77c1bcec..5d94af043 100644 --- a/src/froidure-pin.hpp +++ b/src/froidure-pin.hpp @@ -20,7 +20,6 @@ #define SEMIGROUPS_SRC_FROIDURE_PIN_HPP_ #include // for size_t -#include // for shared_ptr #include // for string #include // for true_type #include // for pair @@ -62,26 +61,33 @@ void bind_froidure_pin(gapbind14::Module& m, std::string name) { gapbind14::class_(name) .def(gapbind14::init<>{}, "make") .def(gapbind14::init{}, "copy") - .def("add_generator", &FroidurePin_::add_generator) + .def("add_generator", + [](FroidurePin_& S, element_type const& x) { + return S.add_generator(x); + }) .def("generator", &FroidurePin_::generator) .def("closure", - &FroidurePin_::template closure>) + [](FroidurePin_& S, std::vector const& gens) { + return libsemigroups::froidure_pin::closure(S, gens); + }) .def("number_of_generators", &FroidurePin_::number_of_generators) .def("size", &FroidurePin_::size) .def("at", &FroidurePin_::at) .def("sorted_at", &FroidurePin_::sorted_at) .def("current_position", - gapbind14::overload_cast( - &FroidurePin_::current_position)) + [](FroidurePin_& S, const_reference x) { + return S.current_position(x); + }) .def("sorted_position", &FroidurePin_::sorted_position) .def("number_of_idempotents", &FroidurePin_::number_of_idempotents) .def("enumerate", &FroidurePin_::enumerate) .def("left_cayley_graph", &FroidurePin_::left_cayley_graph) .def("right_cayley_graph", &FroidurePin_::right_cayley_graph) .def("factorisation", - gapbind14::overload_cast(&FroidurePin_::factorisation)) - .def("position_to_sorted_position", - &FroidurePin_::position_to_sorted_position) + [](FroidurePin_& S, size_t i) { + return libsemigroups::froidure_pin::factorisation(S, i); + }) + .def("to_sorted_position", &FroidurePin_::to_sorted_position) .def("fast_product", &FroidurePin_::fast_product) .def("is_idempotent", &FroidurePin_::is_idempotent) .def("finished", &FroidurePin_::finished) diff --git a/src/pkg.cpp b/src/pkg.cpp index ae8317854..0c5c83597 100644 --- a/src/pkg.cpp +++ b/src/pkg.cpp @@ -50,18 +50,16 @@ #include "gapbind14/gapbind14.hpp" // for class_, InstallGlobalFunction // libsemigroups headers -#include "libsemigroups/bipart.hpp" // for Blocks, Bipartition -#include "libsemigroups/cong-intf.hpp" // for congruence_kind -#include "libsemigroups/digraph.hpp" // for ActionDigraph -#include "libsemigroups/fpsemi.hpp" // for FpSemigroup -#include "libsemigroups/freeband.hpp" // for freeband_equal_to -#include "libsemigroups/report.hpp" // for REPORTER, Reporter -#include "libsemigroups/sims1.hpp" // for Sims1 -#include "libsemigroups/todd-coxeter.hpp" // for ToddCoxeter, ToddCoxeter::table_type -#include "libsemigroups/types.hpp" // for word_type, letter_type - #include "libsemigroups/adapters.hpp" -#include "libsemigroups/uf.hpp" +#include "libsemigroups/bipart.hpp" // for Blocks, Bipartition +#include "libsemigroups/freeband.hpp" // for freeband_equal_to +#include "libsemigroups/presentation.hpp" // for Presentation +#include "libsemigroups/sims.hpp" // for Sims1 +#include "libsemigroups/todd-coxeter.hpp" // for ToddCoxeter, ToddCoxeter::word_graph_type +#include "libsemigroups/types.hpp" // for word_type, letter_type +#include "libsemigroups/word-graph.hpp" // for WordGraph + +#include "libsemigroups/detail/report.hpp" // for REPORTER, Reporter using libsemigroups::Bipartition; using libsemigroups::Blocks; @@ -69,22 +67,16 @@ using libsemigroups::Blocks; using libsemigroups::Hash; using libsemigroups::detail::Duf; -namespace { - void set_report(bool const val) { - libsemigroups::REPORTER.report(val); - } -} // namespace - namespace gapbind14 { template <> struct IsGapBind14Type> : std::true_type {}; template <> - struct IsGapBind14Type> : std::true_type {}; + struct IsGapBind14Type : std::true_type {}; template <> - struct IsGapBind14Type::iterator> + struct IsGapBind14Type : std::true_type {}; template <> @@ -96,9 +88,9 @@ GAPBIND14_MODULE(libsemigroups) { // Free functions //////////////////////////////////////////////////////////////////////// - gapbind14::InstallGlobalFunction("set_report", &set_report); - gapbind14::InstallGlobalFunction("should_report", - &libsemigroups::report::should_report); + // gapbind14::InstallGlobalFunction("set_report", &set_report); + gapbind14::InstallGlobalFunction("reporting_enabled", + &libsemigroups::reporting_enabled); gapbind14::InstallGlobalFunction("hardware_concurrency", &std::thread::hardware_concurrency); gapbind14::InstallGlobalFunction( @@ -126,37 +118,20 @@ GAPBIND14_MODULE(libsemigroups) { init_cong(gapbind14::module()); //////////////////////////////////////////////////////////////////////// - // FpSemigroup + // ToddCoxeter //////////////////////////////////////////////////////////////////////// - using libsemigroups::FpSemigroup; using libsemigroups::word_type; - gapbind14::class_("FpSemigroup") - .def(gapbind14::init<>{}) - .def("set_alphabet", - gapbind14::overload_cast(&FpSemigroup::set_alphabet)) - .def("add_rule", - gapbind14::overload_cast( - &FpSemigroup::add_rule)) - .def("set_identity", - gapbind14::overload_cast( - &FpSemigroup::set_identity)); - - //////////////////////////////////////////////////////////////////////// - // ToddCoxeter - //////////////////////////////////////////////////////////////////////// - using libsemigroups::congruence_kind; - using libsemigroups::congruence::ToddCoxeter; - using table_type = libsemigroups::congruence::ToddCoxeter::table_type; + using libsemigroups::Presentation; + using libsemigroups::ToddCoxeter; + + using word_graph_type + = libsemigroups::ToddCoxeter::word_graph_type; - gapbind14::class_("ToddCoxeter") - .def(gapbind14::init{}) - .def("set_number_of_generators", &ToddCoxeter::set_number_of_generators) - .def("number_of_generators", &ToddCoxeter::number_of_generators) - .def("prefill", - gapbind14::overload_cast(&ToddCoxeter::prefill)); + gapbind14::class_>("ToddCoxeter") + .def(gapbind14::init>{}); using libsemigroups::Presentation; @@ -176,7 +151,8 @@ GAPBIND14_MODULE(libsemigroups) { [](Presentation& thing, bool val) -> void { thing.contains_empty_word(val); }) - .def("validate", &Presentation::validate) + .def("throw_if_bad_alphabet_or_rules", + &Presentation::throw_if_bad_alphabet_or_rules) .def("number_of_rules", [](Presentation const& thing) -> size_t { return thing.rules.size(); @@ -191,40 +167,27 @@ GAPBIND14_MODULE(libsemigroups) { using libsemigroups::Sims1; - gapbind14::class_::iterator>("Sims1Iterator") - .def("increment", [](typename Sims1::iterator& it) { ++it; }) - .def("deref", - [](typename Sims1::iterator const& it) { return *it; }); + gapbind14::class_("Sims1Iterator") + .def("increment", [](typename Sims1::iterator& it) { ++it; }) + .def("deref", [](typename Sims1::iterator const& it) { return *it; }); - gapbind14::class_>("Sims1") - .def(gapbind14::init{}, "make") - .def("short_rules", - [](Sims1& s, Presentation const& p) { - s.short_rules(p); - }) - .def("extra", - [](Sims1& s, Presentation const& p) { - s.extra(p); - }) + gapbind14::class_("Sims1") + .def(gapbind14::init>{}, "make") .def("number_of_threads", - [](Sims1& s, size_t val) { s.number_of_threads(val); }) - .def("number_of_congruences", &Sims1::number_of_congruences) - .def("cbegin", &Sims1::cbegin); + [](Sims1& s, size_t val) { s.number_of_threads(val); }) + .def("number_of_congruences", &Sims1::number_of_congruences) + .def("cbegin", &Sims1::cbegin); using libsemigroups::RepOrc; gapbind14::class_("RepOrc") .def(gapbind14::init<>{}, "make") - .def("short_rules", - [](RepOrc& ro, Presentation const& p) { - ro.short_rules(p); - }) .def("number_of_threads", [](RepOrc& ro, size_t val) { ro.number_of_threads(val); }) .def("max_nodes", [](RepOrc& ro, size_t val) { ro.max_nodes(val); }) .def("min_nodes", [](RepOrc& ro, size_t val) { ro.min_nodes(val); }) .def("target_size", [](RepOrc& ro, size_t val) { ro.target_size(val); }) - .def("digraph", &RepOrc::digraph); + .def("word_graph", &RepOrc::word_graph); } //////////////////////////////////////////////////////////////////////// @@ -323,10 +286,10 @@ void TBlocksObjLoadFunc(Obj o) { Blocks* blocks = new Blocks(deg); for (size_t i = 0; i < deg; i++) { - blocks->set_block(i, LoadUInt4()); + blocks->block(i, LoadUInt4()); } for (size_t i = 0; i < nr_blocks; i++) { - blocks->set_is_transverse_block(i, static_cast(LoadUInt1())); + blocks->is_transverse_block(i, static_cast(LoadUInt1())); } #ifdef SEMIGROUPS_KERNEL_DEBUG libsemigroups::validate(*blocks); @@ -428,10 +391,8 @@ static StructGVarFilt GVarFilts[] = { typedef Obj (*GVarFunc)(/*arguments*/); -#define GVAR_ENTRY(srcfile, name, nparam, params) \ - { \ -#name, nparam, params, (GVarFunc) name, srcfile ":Func" #name \ - } +#define GVAR_ENTRY(srcfile, name, nparam, params) \ + {#name, nparam, params, (GVarFunc) name, srcfile ":Func" #name} // Table of functions to export @@ -596,7 +557,7 @@ static Int InitKernel(StructInitInfo* module) { } static Int PostRestore(StructInitInfo* module) { - set_report(false); + // TODO set_report(false); return 0; } diff --git a/src/pkg.hpp b/src/pkg.hpp index 03d1eefdb..1fa74c6c0 100644 --- a/src/pkg.hpp +++ b/src/pkg.hpp @@ -33,6 +33,9 @@ #include "gapbind14/gapbind14.hpp" +#include "libsemigroups/todd-coxeter.hpp" // for ToddCoxeter +#include "libsemigroups/types.hpp" // for word_type + extern UInt T_BIPART; extern UInt T_BLOCKS; @@ -75,19 +78,10 @@ extern Obj Integers; extern Obj NrRows; extern Obj Matrix; -namespace libsemigroups { - class FpSemigroup; - namespace congruence { - class ToddCoxeter; - } -} // namespace libsemigroups - namespace gapbind14 { - template <> - struct IsGapBind14Type : std::true_type {}; template <> - struct IsGapBind14Type + struct IsGapBind14Type> : std::true_type {}; } // namespace gapbind14 diff --git a/src/to_cpp.hpp b/src/to_cpp.hpp index cf1f19e13..52f34c514 100644 --- a/src/to_cpp.hpp +++ b/src/to_cpp.hpp @@ -49,15 +49,16 @@ #include "gapbind14/to_gap.hpp" // for gap_tnum_type // libsemigroups headers -#include "libsemigroups/adapters.hpp" // for Degree -#include "libsemigroups/bmat8.hpp" // for BMat8 -#include "libsemigroups/cong.hpp" // for Congruence -#include "libsemigroups/constants.hpp" // for NegativeInfinity, PositiveIn... -#include "libsemigroups/containers.hpp" // for DynamicArray2 -#include "libsemigroups/matrix.hpp" // for NTPMat, MaxPlusTruncMat, Min... -#include "libsemigroups/pbr.hpp" // for PBR -#include "libsemigroups/transf.hpp" // for PPerm, Transf, IsPPerm -#include "libsemigroups/types.hpp" // for congruence_kind, congruence_... +#include "libsemigroups/adapters.hpp" // for Degree +#include "libsemigroups/bmat8.hpp" // for BMat8 +#include "libsemigroups/cong.hpp" // for Congruence +#include "libsemigroups/constants.hpp" // for NegativeInfinity, PositiveIn... +#include "libsemigroups/matrix.hpp" // for NTPMat, MaxPlusTruncMat, Min... +#include "libsemigroups/pbr.hpp" // for PBR +#include "libsemigroups/transf.hpp" // for PPerm, Transf, IsPPerm +#include "libsemigroups/types.hpp" // for congruence_kind, congruence_... + +#include "libsemigroups/detail/containers.hpp" // for DynamicArray2 namespace libsemigroups { class Bipartition; @@ -171,7 +172,6 @@ namespace gapbind14 { } } } - GAPBIND14_TRY(libsemigroups::validate(x)); return x; } }; @@ -199,7 +199,7 @@ namespace gapbind14 { } for (size_t j = 0; j < m; j++) { if (ELM_BLIST(row, j + 1) == True) { - x.set(i, j, 1); + x(i, j) = 1; } } } @@ -251,7 +251,7 @@ namespace gapbind14 { x(i, j) = itm; } } - GAPBIND14_TRY(libsemigroups::validate(x)); + // TODO GAPBIND14_TRY(libsemigroups::validate(x)); return x; } } // namespace detail @@ -282,7 +282,7 @@ namespace gapbind14 { ELM_MAT(o, INTOBJ_INT(i + 1), INTOBJ_INT(j + 1))); } } - GAPBIND14_TRY(libsemigroups::validate(x)); + // TODO GAPBIND14_TRY(libsemigroups::validate(x)); return x; } }; @@ -388,15 +388,13 @@ namespace gapbind14 { static gap_tnum_type constexpr gap_type = T_STRING; cpp_type operator()(Obj o) const { - if (!IS_STRING_REP(o)) { + if (TNUM_OBJ(o) != T_STRING && TNUM_OBJ(o) != T_STRING + IMMUTABLE) { ErrorQuit("expected string but got %s!", (Int) TNAM_OBJ(o), 0L); } std::string stype = std::string(CSTR_STRING(o)); - if (stype == "left") { - return congruence_kind::left; - } else if (stype == "right") { - return congruence_kind::right; - } else if (stype == "2-sided") { + if (stype == "onesided") { + return congruence_kind::onesided; + } else if (stype == "twosided") { return congruence_kind::twosided; } else { ErrorQuit("Unrecognised type %s", (Int) stype.c_str(), 0L); @@ -405,20 +403,23 @@ namespace gapbind14 { }; template <> - struct to_cpp { - using cpp_type = libsemigroups::Congruence::options::runners; + struct to_cpp { + using cpp_type = libsemigroups::Order; + static gap_tnum_type constexpr gap_type = T_STRING; cpp_type operator()(Obj o) const { - if (!IS_STRING_REP(o)) { + using Order = libsemigroups::Order; + if (TNUM_OBJ(o) != T_STRING && TNUM_OBJ(o) != T_STRING + IMMUTABLE) { ErrorQuit("expected string but got %s!", (Int) TNAM_OBJ(o), 0L); } - std::string stype = std::string(CSTR_STRING(o)); - if (stype == "none") { - return cpp_type::none; - } else if (stype == "standard") { - return cpp_type::standard; + std::string_view stype = CSTR_STRING(o); + if (stype == "shortlex") { + return Order::shortlex; + } else if (stype == "lex") { + return Order::lex; + // TODO the other cases } else { - ErrorQuit("Unrecognised type %s", (Int) stype.c_str(), 0L); + ErrorQuit("Unrecognised type %s", (Int) stype.begin(), 0L); } } }; diff --git a/src/to_gap.hpp b/src/to_gap.hpp index 990963c20..5ebc1abe9 100644 --- a/src/to_gap.hpp +++ b/src/to_gap.hpp @@ -41,18 +41,18 @@ #include "semigroups-debug.hpp" // for SEMIGROUPS_ASSERT // gapbind14 headers -#include "gapbind14/gapbind14.hpp" // for gapbind14 +#include "gapbind14/to_gap.hpp" // for gapbind14 // libsemigroups headers -#include "libsemigroups/adapters.hpp" // for Degree -#include "libsemigroups/bipart.hpp" // for Bipartition, IsBipartition -#include "libsemigroups/bmat8.hpp" // for BMat8 -#include "libsemigroups/config.hpp" // for LIBSEMIGROUPS_HPCOMBI_ENABLED -#include "libsemigroups/constants.hpp" // for NEGATIVE_INFINITY etc -#include "libsemigroups/digraph.hpp" // for ActionDigraph -#include "libsemigroups/matrix.hpp" // for matrix_threshold etc -#include "libsemigroups/pbr.hpp" // for PBR -#include "libsemigroups/transf.hpp" // for IsPPerm, IsTransf +#include "libsemigroups/adapters.hpp" // for Degree +#include "libsemigroups/bipart.hpp" // for Bipartition, IsBipartition +#include "libsemigroups/bmat8.hpp" // for BMat8 +#include "libsemigroups/config.hpp" // for LIBSEMIGROUPS_HPCOMBI_ENABLED +#include "libsemigroups/constants.hpp" // for NEGATIVE_INFINITY etc +#include "libsemigroups/matrix.hpp" // for matrix_threshold etc +#include "libsemigroups/pbr.hpp" // for PBR +#include "libsemigroups/transf.hpp" // for IsPPerm, IsTransf +#include "libsemigroups/word-graph.hpp" // for WordGraph using libsemigroups::IsBMat; using libsemigroups::IsIntMat; @@ -169,7 +169,7 @@ namespace gapbind14 { Obj blist = NewBag(T_BLIST, SIZE_PLEN_BLIST(n)); SET_LEN_BLIST(blist, n); for (size_t j = 0; j < n; j++) { - if (x.first.get(i, j)) { + if (x.first(i, j)) { SET_BIT_BLIST(blist, j + 1); } } @@ -241,7 +241,7 @@ namespace gapbind14 { struct to_gap> { using MaxPlusTruncMat_ = libsemigroups::MaxPlusTruncMat<>; Obj operator()(MaxPlusTruncMat_ const& x) { - using libsemigroups::matrix_threshold; + using libsemigroups::matrix::threshold; using scalar_type = typename MaxPlusTruncMat_::scalar_type; auto result = detail::make_matrix( @@ -249,9 +249,8 @@ namespace gapbind14 { return (y == NEGATIVE_INFINITY ? to_gap()(y) : to_gap()(y)); }); - SET_ELM_PLIST(result, - x.number_of_rows() + 1, - to_gap()(matrix_threshold(x))); + SET_ELM_PLIST( + result, x.number_of_rows() + 1, to_gap()(threshold(x))); return result; } }; @@ -265,7 +264,7 @@ namespace gapbind14 { using MinPlusTruncMat_ = libsemigroups::MinPlusTruncMat<>; Obj operator()(MinPlusTruncMat_ const& x) { - using libsemigroups::matrix_threshold; + using libsemigroups::matrix::threshold; using scalar_type = typename MinPlusTruncMat_::scalar_type; auto result = detail::make_matrix( @@ -273,9 +272,8 @@ namespace gapbind14 { return (y == POSITIVE_INFINITY ? to_gap()(y) : to_gap()(y)); }); - SET_ELM_PLIST(result, - x.number_of_rows() + 1, - to_gap()(matrix_threshold(x))); + SET_ELM_PLIST( + result, x.number_of_rows() + 1, to_gap()(threshold(x))); return result; } }; @@ -309,16 +307,14 @@ namespace gapbind14 { Obj operator()(NTPMat_ const& x) { using scalar_type = typename NTPMat_::scalar_type; - using libsemigroups::matrix_period; - using libsemigroups::matrix_threshold; + using libsemigroups::matrix::period; + using libsemigroups::matrix::threshold; auto result = detail::make_matrix(x, NTPMatrixType, 2); - SET_ELM_PLIST(result, - x.number_of_rows() + 1, - to_gap()(matrix_threshold(x))); - SET_ELM_PLIST(result, - x.number_of_rows() + 2, - to_gap()(matrix_period(x))); + SET_ELM_PLIST( + result, x.number_of_rows() + 1, to_gap()(threshold(x))); + SET_ELM_PLIST( + result, x.number_of_rows() + 2, to_gap()(period(x))); return result; } }; @@ -515,24 +511,24 @@ namespace gapbind14 { }; //////////////////////////////////////////////////////////////////////// - // ActionDigraph + // WordGraph //////////////////////////////////////////////////////////////////////// template - struct to_gap> { - using ActionDigraph_ = libsemigroups::ActionDigraph; - Obj operator()(ActionDigraph_ const& ad) const noexcept { - using node_type = typename ActionDigraph_::node_type; + struct to_gap> { + using WordGraph_ = libsemigroups::WordGraph; + Obj operator()(WordGraph_ const& ad) const noexcept { + using node_type = typename WordGraph_::node_type; Obj result = NEW_PLIST(T_PLIST, ad.number_of_nodes()); // this is intentionally not IMMUTABLE - // TODO(ActionDigraph) handle case of zero nodes? + // TODO(WordGraph) handle case of zero nodes? SET_LEN_PLIST(result, ad.number_of_nodes()); for (size_t i = 0; i < ad.number_of_nodes(); ++i) { Obj next = NEW_PLIST(T_PLIST, 0); SET_LEN_PLIST(next, 0); for (size_t j = 0; j < ad.out_degree(); ++j) { - auto val = ad.unsafe_neighbor(i, j); + auto val = ad.target_no_checks(i, j); if (val != UNDEFINED) { AssPlist(next, j + 1, to_gap()(val + 1)); } @@ -544,5 +540,23 @@ namespace gapbind14 { } }; + // TODO could use magic_enum and make this generic + template <> + struct to_gap { + Obj operator()(libsemigroups::Order const& val) const noexcept { + using order = libsemigroups::Order; + switch (val) { + case order::shortlex: + return to_gap()("shortlex"); + case order::lex: + return to_gap()("lex"); + case order::none: + return to_gap()("none"); + case order::recursive: + return to_gap()("recursive"); + } + } + }; + } // namespace gapbind14 #endif // SEMIGROUPS_SRC_TO_GAP_HPP_ From b3b24be9423328726fac08703a0e00e58fa3effc Mon Sep 17 00:00:00 2001 From: "James D. Mitchell" Date: Tue, 8 Apr 2025 10:54:37 +0200 Subject: [PATCH 2/2] More --- src/cong.cpp | 97 ++-------------------------------------------------- src/cong.hpp | 1 + src/pkg.cpp | 44 ++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 97 deletions(-) diff --git a/src/cong.cpp b/src/cong.cpp index 1beb1b155..81d4893f3 100644 --- a/src/cong.cpp +++ b/src/cong.cpp @@ -36,21 +36,10 @@ #include "gapbind14/gapbind14.hpp" // for class_ etc // libsemigroups headers -#include "libsemigroups/bipart.hpp" // for Bipartition #include "libsemigroups/cong.hpp" // for Congruence -#include "libsemigroups/constants.hpp" // for UNDEFINED etc -#include "libsemigroups/froidure-pin.hpp" // for FroidurePin -#include "libsemigroups/matrix.hpp" // for BMat etc -#include "libsemigroups/todd-coxeter.hpp" // for ToddCoxeter -#include "libsemigroups/transf.hpp" // for PPerm etc +#include "libsemigroups/presentation.hpp" // for Presentation #include "libsemigroups/types.hpp" // for word_type -// Forward decls -namespace libsemigroups { - class FpSemigroup; - class PBR; -} // namespace libsemigroups - namespace gapbind14 { template <> struct IsGapBind14Type> @@ -60,91 +49,11 @@ namespace gapbind14 { } // namespace gapbind14 +// TODO rm this file //////////////////////////////////////////////////////////////////////// // Congruence //////////////////////////////////////////////////////////////////////// using gapbind14::overload_cast; -void init_cong(gapbind14::Module& m) { - using libsemigroups::Congruence; - using libsemigroups::congruence_kind; - using libsemigroups::FpSemigroup; - using libsemigroups::FroidurePin; - using libsemigroups::FroidurePinBase; - using libsemigroups::word_type; - - using libsemigroups::Bipartition; - using libsemigroups::BMat; - using libsemigroups::IntMat; - using libsemigroups::LeastPPerm; - using libsemigroups::LeastTransf; - using libsemigroups::MaxPlusMat; - using libsemigroups::MaxPlusTruncMat; - using libsemigroups::MinPlusMat; - using libsemigroups::MinPlusTruncMat; - using libsemigroups::NTPMat; - using libsemigroups::PBR; - using libsemigroups::PPerm; - using libsemigroups::ProjMaxPlusMat; - using libsemigroups::Transf; - - // Cannot use FroidurePinBase rather than the specialisations because there's - // no constructor for a Congruence from a FroidurePinBase&. - // gapbind14::class_("Congruence") - // .def(gapbind14::init - // const&>{}, - // "make_from_froidurepin_bipartition") - // .def(gapbind14::init> const&>{}, - // "make_from_froidurepin_bmat") - // .def(gapbind14::init const&>{}, - // "make_from_froidurepin_bmat8") - // .def(gapbind14::init const&>{}, - // "make_from_froidurepin_pbr") - // #ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED - // .def(gapbind14::init> const&>{}, - // "make_from_froidurepin_leastpperm") - // .def(gapbind14::init> const&>{}, - // "make_from_froidurepin_leasttransf") - // #endif - // .def(gapbind14::init> const&>{}, - // "make_from_froidurepin_transfUInt2") - // .def(gapbind14::init> const&>{}, - // "make_from_froidurepin_transfUInt4") - // .def(gapbind14::init> const&>{}, - // "make_from_froidurepin_ppermUInt2") - // .def(gapbind14::init> const&>{}, - // "make_from_froidurepin_ppermUInt4") - // .def(gapbind14::init{}, - // "make_from_fpsemigroup") - // .def(gapbind14::init>{}, - // "make_from_froidurepinbase") - // .def(gapbind14::init{}, - // "make_from_table") - // .def("set_number_of_generators", - // &Congruence::set_number_of_generators) .def("number_of_pairs", - // &Congruence::number_of_generating_pairs) .def("add_pair", - // overload_cast( - // &Congruence::add_pair)) - // .def("number_of_classes", &Congruence::number_of_classes) - // .def("word_to_class_index", &Congruence::word_to_class_index) - // .def("class_index_to_word", &Congruence::class_index_to_word) - // .def("contains", &Congruence::contains) - // .def("less", &Congruence::less) - // .def("add_runner", - // &Congruence::add_runner) - // .def("is_quotient_obviously_infinite", - // &Congruence::is_quotient_obviously_infinite) - // .def("ntc", - // [](Congruence& C) { - // return gapbind14::make_iterator(C.cbegin_ntc(), C.cend_ntc()); - // }) - // .def("quotient_froidure_pin", &Congruence::quotient_froidure_pin); -} +void init_cong(gapbind14::Module& m) {} diff --git a/src/cong.hpp b/src/cong.hpp index ce6cd4cc3..f5862b8cc 100644 --- a/src/cong.hpp +++ b/src/cong.hpp @@ -1,4 +1,5 @@ // +// TODO rm this file // Semigroups package for GAP // Copyright (C) 2021 James D. Mitchell // diff --git a/src/pkg.cpp b/src/pkg.cpp index 0c5c83597..a8387ee51 100644 --- a/src/pkg.cpp +++ b/src/pkg.cpp @@ -64,14 +64,22 @@ using libsemigroups::Bipartition; using libsemigroups::Blocks; -using libsemigroups::Hash; -using libsemigroups::detail::Duf; +namespace { + void LIBSEMIGROUPS_REPORTING_ENABLED(bool const val) { + static std::unique_ptr rg; + rg = std::make_unique(val); + } +} // namespace namespace gapbind14 { template <> struct IsGapBind14Type> : std::true_type {}; + template <> + struct IsGapBind14Type> + : std::true_type {}; + template <> struct IsGapBind14Type : std::true_type {}; @@ -88,7 +96,8 @@ GAPBIND14_MODULE(libsemigroups) { // Free functions //////////////////////////////////////////////////////////////////////// - // gapbind14::InstallGlobalFunction("set_report", &set_report); + gapbind14::InstallGlobalFunction("set_report", + &LIBSEMIGROUPS_REPORTING_ENABLED); gapbind14::InstallGlobalFunction("reporting_enabled", &libsemigroups::reporting_enabled); gapbind14::InstallGlobalFunction("hardware_concurrency", @@ -188,6 +197,35 @@ GAPBIND14_MODULE(libsemigroups) { .def("min_nodes", [](RepOrc& ro, size_t val) { ro.min_nodes(val); }) .def("target_size", [](RepOrc& ro, size_t val) { ro.target_size(val); }) .def("word_graph", &RepOrc::word_graph); + + using libsemigroups::Congruence; + using libsemigroups::congruence_kind; + using libsemigroups::FroidurePinBase; + using libsemigroups::Presentation; + using libsemigroups::word_type; + + gapbind14::class_>("Congruence") + .def(gapbind14::init>{}, "make"); + // .def("number_of_generating_pairs", + // &Congruence::number_of_generating_pairs) + // .def("add_generating_pair", + // [](Congruence& self, + // word_type const& u, + // word_type const& v) { + // return libsemigroups::congruence::add_generating_pair(self, u, v); + // }) + // .def("number_of_classes", &Congruence::number_of_classes) + // // .def("index_of", &Congruence::word_to_class_index) + // // .def("word_of", &Congruence::class_index_to_word) + // .def("contains", + // [](Congruence& self, + // word_type const& u, + // word_type const& v) { + // return libsemigroups::congruence::contains(self, u, v); + // }); + // .def("non_trivial_classes", [](Congruence& C) { + // return gapbind14::make_iterator(C.cbegin_ntc(), C.cend_ntc()); + // }); } ////////////////////////////////////////////////////////////////////////