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) {
auto s = std::clock();
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();
double diff = (double) (e - s) / CLOCKS_PER_SEC;
int count = data.size();
int count = data.cols();
std::cout
<< std::setw(2) << N << ", "

View File

@@ -31,22 +31,16 @@ namespace tc {
return combos;
}
std::vector<Symbol> fan(const std::vector<Symbol>& prims, int root) {
std::vector<Symbol> res;
res.reserve(prims.size());
for (const auto &prim: prims) {
Symbol s(prim.size() + 1);
s << prim, root;
res.push_back(s);
}
ArrayXui fan(const ArrayXui &prims, int root) {
ArrayXui res(prims.rows() + 1, prims.cols());
res.topRows(prims.rows()) << prims;
res.bottomRows(1).fill(root);
return res;
}
void apply(const tc::Cosets &table, unsigned int gen, std::vector<Symbol> &prims) {
for (auto &prim: prims) {
for (auto &ind : prim) {
ind = table.get(ind, gen);
}
void apply(const tc::Cosets &table, unsigned int gen, ArrayXui &prims) {
for (Eigen::Index i = 0; i < prims.size(); ++i) {
prims(i) = table.get(prims(i), 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.
*/
void recontext(
std::vector<Symbol> &prims,
ArrayXui &prims,
const tc::Group &context,
const Symbol &g_gens,
const Symbol &sg_gens
@@ -68,33 +62,32 @@ namespace tc {
return table.get(coset, gen);
});
for (Symbol &prim: prims) {
for (auto &ind: prim) {
ind = map[ind];
}
for (Eigen::Index i = 0; i < prims.size(); ++i) {
prims(i) = map[prims(i)];
}
}
/**
* Union several meshes of the same dimension
*/
std::vector<Symbol> merge(const std::vector<std::vector<Symbol>> &meshes) {
size_t size = 0;
ArrayXui merge(const std::vector<ArrayXui> &meshes) {
Eigen::Index cols = 0;
for (const auto &mesh: meshes) {
size += mesh.size();
cols += mesh.cols();
}
std::vector<Symbol> res;
res.reserve(size);
ArrayXui res(meshes[0].rows(), cols);
Eigen::Index offset = 0;
for (const auto &mesh: meshes) {
res.insert(res.end(), mesh.begin(), mesh.end());
res.middleCols(offset, mesh.cols()) << mesh;
offset += mesh.cols();
}
return res;
}
std::vector<std::vector<Symbol>> each_tile(
std::vector<Symbol> base,
std::vector<ArrayXui> each_tile(
ArrayXui base,
const tc::Group &context,
const Symbol &g_gens,
const Symbol &sg_gens
@@ -114,63 +107,41 @@ namespace tc {
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
*/
std::vector<Symbol> triangulate(
ArrayXui triangulate(
const tc::Group &context,
const Symbol &g_gens
) {
if (g_gens.size() == 0) {
std::vector<Symbol> res;
Symbol prims(1);
prims.setZero();
res.push_back(prims);
ArrayXui res(1, 1);
res.setZero();
return res;
}
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) {
auto base = triangulate(context, sg_gens);
auto raised = tile(base, context, g_gens, sg_gens);
raised.erase(raised.begin(), raised.begin() + base.size());
auto tiles = each_tile(base, context, g_gens, sg_gens);
tiles.erase(tiles.begin(), tiles.begin() + 1);
auto raised = merge(tiles);
auto fanned = fan(raised, 0);
meshes.push_back(fanned);
}
const std::vector<Symbol> &result = merge(meshes);
const ArrayXui &result = merge(meshes);
return result;
}
template<class T>
auto hull(const tc::Group &group, T all_sg_gens, const std::vector<Symbol> &exclude) {
std::vector<std::vector<Symbol>> parts;
auto hull(const tc::Group &group, T all_sg_gens) {
std::vector<ArrayXui> parts;
auto g_gens = group.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 &tiles = each_tile(base, group, g_gens, sg_gens);
for (const auto &tile: tiles) {

View File

@@ -19,6 +19,7 @@ namespace tc {
using Symbol = Eigen::Vector<unsigned int, 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
class Group : public MatrixXui {