1
0

WIP: complex solver uses Eigen::Array

This commit is contained in:
David Allemang
2021-11-12 23:07:42 -05:00
parent 840928136e
commit 897f7fe38b
3 changed files with 33 additions and 61 deletions

View File

@@ -9,11 +9,11 @@ template<class G>
void test(const G &group, unsigned int N) { void test(const G &group, unsigned int N) {
auto s = std::clock(); auto s = std::clock();
auto combos = tc::combinations(group.gens, N - 1); auto combos = tc::combinations(group.gens, N - 1);
auto data = tc::merge(tc::hull(group, combos, {})); auto data = tc::merge(tc::hull(group, combos));
auto e = std::clock(); auto e = std::clock();
double diff = (double) (e - s) / CLOCKS_PER_SEC; double diff = (double) (e - s) / CLOCKS_PER_SEC;
int count = data.size(); int count = data.cols();
std::cout std::cout
<< std::setw(2) << N << ", " << std::setw(2) << N << ", "

View File

@@ -31,22 +31,16 @@ namespace tc {
return combos; return combos;
} }
std::vector<Symbol> fan(const std::vector<Symbol>& prims, int root) { ArrayXui fan(const ArrayXui &prims, int root) {
std::vector<Symbol> res; ArrayXui res(prims.rows() + 1, prims.cols());
res.reserve(prims.size()); res.topRows(prims.rows()) << prims;
for (const auto &prim: prims) { res.bottomRows(1).fill(root);
Symbol s(prim.size() + 1);
s << prim, root;
res.push_back(s);
}
return res; return res;
} }
void apply(const tc::Cosets &table, unsigned int gen, std::vector<Symbol> &prims) { void apply(const tc::Cosets &table, unsigned int gen, ArrayXui &prims) {
for (auto &prim: prims) { for (Eigen::Index i = 0; i < prims.size(); ++i) {
for (auto &ind : prim) { prims(i) = table.get(prims(i), gen);
ind = table.get(ind, gen);
}
} }
} }
@@ -54,7 +48,7 @@ namespace tc {
* Convert the indexes of this mesh to those of a different context, using g_gens to build the parent context and sg_gens to build this context. * Convert the indexes of this mesh to those of a different context, using g_gens to build the parent context and sg_gens to build this context.
*/ */
void recontext( void recontext(
std::vector<Symbol> &prims, ArrayXui &prims,
const tc::Group &context, const tc::Group &context,
const Symbol &g_gens, const Symbol &g_gens,
const Symbol &sg_gens const Symbol &sg_gens
@@ -68,33 +62,32 @@ namespace tc {
return table.get(coset, gen); return table.get(coset, gen);
}); });
for (Symbol &prim: prims) { for (Eigen::Index i = 0; i < prims.size(); ++i) {
for (auto &ind: prim) { prims(i) = map[prims(i)];
ind = map[ind];
}
} }
} }
/** /**
* Union several meshes of the same dimension * Union several meshes of the same dimension
*/ */
std::vector<Symbol> merge(const std::vector<std::vector<Symbol>> &meshes) { ArrayXui merge(const std::vector<ArrayXui> &meshes) {
size_t size = 0; Eigen::Index cols = 0;
for (const auto &mesh: meshes) { for (const auto &mesh: meshes) {
size += mesh.size(); cols += mesh.cols();
} }
std::vector<Symbol> res; ArrayXui res(meshes[0].rows(), cols);
res.reserve(size); Eigen::Index offset = 0;
for (const auto &mesh: meshes) { for (const auto &mesh: meshes) {
res.insert(res.end(), mesh.begin(), mesh.end()); res.middleCols(offset, mesh.cols()) << mesh;
offset += mesh.cols();
} }
return res; return res;
} }
std::vector<std::vector<Symbol>> each_tile( std::vector<ArrayXui> each_tile(
std::vector<Symbol> base, ArrayXui base,
const tc::Group &context, const tc::Group &context,
const Symbol &g_gens, const Symbol &g_gens,
const Symbol &sg_gens const Symbol &sg_gens
@@ -114,63 +107,41 @@ namespace tc {
return res; return res;
} }
[[nodiscard]] /**
std::vector<Symbol> tile(
std::vector<Symbol> base,
const tc::Group &context,
const Symbol &g_gens,
const Symbol &sg_gens
) {
auto res = each_tile(std::move(base), context, g_gens, sg_gens);
return merge(res);
}
/**
* Produce a mesh of primitives that fill out the volume of the subgroup generated by generators g_gens within the group context * Produce a mesh of primitives that fill out the volume of the subgroup generated by generators g_gens within the group context
*/ */
std::vector<Symbol> triangulate( ArrayXui triangulate(
const tc::Group &context, const tc::Group &context,
const Symbol &g_gens const Symbol &g_gens
) { ) {
if (g_gens.size() == 0) { if (g_gens.size() == 0) {
std::vector<Symbol> res; ArrayXui res(1, 1);
Symbol prims(1); res.setZero();
prims.setZero();
res.push_back(prims);
return res; return res;
} }
const auto &combos = combinations(g_gens, g_gens.size() - 1); const auto &combos = combinations(g_gens, g_gens.size() - 1);
std::vector<std::vector<Symbol>> meshes; std::vector<ArrayXui> meshes;
for (const auto &sg_gens: combos) { for (const auto &sg_gens: combos) {
auto base = triangulate(context, sg_gens); auto base = triangulate(context, sg_gens);
auto raised = tile(base, context, g_gens, sg_gens); auto tiles = each_tile(base, context, g_gens, sg_gens);
raised.erase(raised.begin(), raised.begin() + base.size()); tiles.erase(tiles.begin(), tiles.begin() + 1);
auto raised = merge(tiles);
auto fanned = fan(raised, 0); auto fanned = fan(raised, 0);
meshes.push_back(fanned); meshes.push_back(fanned);
} }
const std::vector<Symbol> &result = merge(meshes); const ArrayXui &result = merge(meshes);
return result; return result;
} }
template<class T> template<class T>
auto hull(const tc::Group &group, T all_sg_gens, const std::vector<Symbol> &exclude) { auto hull(const tc::Group &group, T all_sg_gens) {
std::vector<std::vector<Symbol>> parts; std::vector<ArrayXui> parts;
auto g_gens = group.gens; auto g_gens = group.gens;
for (const Symbol &sg_gens: all_sg_gens) { for (const Symbol &sg_gens: all_sg_gens) {
bool excluded = false;
for (const auto &test: exclude) {
if (sg_gens == test) {
excluded = true;
break;
}
}
if (excluded) continue;
const auto &base = triangulate(group, sg_gens); const auto &base = triangulate(group, sg_gens);
const auto &tiles = each_tile(base, group, g_gens, sg_gens); const auto &tiles = each_tile(base, group, g_gens, sg_gens);
for (const auto &tile: tiles) { for (const auto &tile: tiles) {

View File

@@ -19,6 +19,7 @@ namespace tc {
using Symbol = Eigen::Vector<unsigned int, Eigen::Dynamic>; using Symbol = Eigen::Vector<unsigned int, Eigen::Dynamic>;
using MatrixXui = Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic>; using MatrixXui = Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic>;
using ArrayXui = Eigen::Array<unsigned int, Eigen::Dynamic, Eigen::Dynamic>;
/// A Coxeter Matrix /// A Coxeter Matrix
class Group : public MatrixXui { class Group : public MatrixXui {