From 01e734ff00bfb03d6cb7790fed5cf9d23dbad471 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Mon, 6 Feb 2023 14:20:35 -0500 Subject: [PATCH] ENH: Simplify recontext_gens --- vis/include/solver.hpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/vis/include/solver.hpp b/vis/include/solver.hpp index 760e7e5..9034a37 100644 --- a/vis/include/solver.hpp +++ b/vis/include/solver.hpp @@ -21,24 +21,17 @@ std::vector generators(const tc::Group &context) { /** * Determine which of g_gens are the correct names for sg_gens within the current context + * + * For example if g_gens contains {a, b, c, d} and sg_gens contains {b, d, a} then the result is {1, 3, 0} */ -std::vector recontext_gens(const tc::Group &context, std::vector g_gens, std::vector sg_gens) { - - std::sort(g_gens.begin(), g_gens.end()); - - int inv_gen_map[context.rank()]; - for (size_t i = 0; i < g_gens.size(); i++) { - inv_gen_map[g_gens[i]] = i; +std::vector recontext_gens(std::vector g_gens, std::vector sg_gens) { + for (size_t &gen: sg_gens) { + gen = std::distance( + g_gens.begin(), + std::find(g_gens.begin(), g_gens.end(), gen) + ); } - - std::vector s_sg_gens; - s_sg_gens.reserve(sg_gens.size()); - for (const auto gen: sg_gens) { - s_sg_gens.push_back(inv_gen_map[gen]); - } - std::sort(s_sg_gens.begin(), s_sg_gens.end()); - - return s_sg_gens; + return sg_gens; } /** @@ -48,7 +41,7 @@ template [[nodiscard]] Indices recontext(Indices prims, const tc::Group &context, const std::vector &g_gens, const std::vector &sg_gens) { - const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens); + const auto proper_sg_gens = recontext_gens(g_gens, sg_gens); const auto table = context.sub(g_gens).solve({}); const auto cosets = context.sub(sg_gens).solve({}); @@ -94,7 +87,7 @@ template std::vector> tile(Indices prims, const tc::Group &context, const std::vector &g_gens, const std::vector &sg_gens) { Indices base = recontext(prims, context, g_gens, sg_gens); - const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens); + const auto proper_sg_gens = recontext_gens(g_gens, sg_gens); const auto &table = context.sub(g_gens).solve({}); const auto &cosets = context.sub(g_gens).solve(proper_sg_gens);