// // Semigroups package for GAP // Copyright (C) 2020-2022 James D. Mitchell // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. //
// This file contains specialisations of gapbind14::to_gap for various types // defined in the GAP package Semigroups and the corresponding types in // libsemigroups.
// Standard library #include <algorithm> // for sort #include <cstddef> // for size_t #include <cstdint> // for uint32_t #include <limits> // for numeric_limits #include <type_traits> // for enable_if_t, decay_t, is_same #include <vector> // for vector
// GAP headers #include"gap_all.h"// for Obj etc
// Semigroups package headers #include"bipart.hpp"// for bipart_new_obj #include"froidure-pin.hpp"// for WBMat8 #include"pkg.hpp"// for TYPES_PBR etc #include"semigroups-debug.hpp"// for SEMIGROUPS_ASSERT
// gapbind14 headers #include"gapbind14/gapbind14.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
using libsemigroups::IsBMat; using libsemigroups::IsIntMat; using libsemigroups::IsMatrix; using libsemigroups::IsMaxPlusMat; using libsemigroups::IsMaxPlusTruncMat; using libsemigroups::IsMinPlusMat; using libsemigroups::IsMinPlusTruncMat; using libsemigroups::IsNTPMat; using libsemigroups::IsProjMaxPlusMat;
using libsemigroups::Bipartition; using libsemigroups::MaxPlusTruncSemiring; using libsemigroups::MinPlusTruncSemiring; using libsemigroups::NTPSemiring;
using libsemigroups::IsBipartition; using libsemigroups::IsPPerm; using libsemigroups::IsTransf;
using libsemigroups::NEGATIVE_INFINITY; using libsemigroups::NegativeInfinity; using libsemigroups::POSITIVE_INFINITY; using libsemigroups::PositiveInfinity; using libsemigroups::UNDEFINED;
namespace gapbind14 {
namespace detail { template <typename T, typename F = to_gap<typename T::scalar_type>>
Obj
make_matrix(T const& x, Obj gap_t, size_t extra_capacity, F&& func = F()) {
size_t n = x.number_of_rows();
Obj result = NEW_PLIST(T_PLIST, n + extra_capacity);
SET_LEN_PLIST(result, n + extra_capacity);
for (size_t i = 0; i < n; i++) {
Obj row = NEW_PLIST_IMM(T_PLIST_CYC, n);
SET_LEN_PLIST(row, n); for (size_t j = 0; j < n; j++) {
AssPlist(row, j + 1, func(x(i, j)));
}
AssPlist(result, i + 1, row);
}
SEMIGROUPS_ASSERT(LEN_PLIST(result) == n + extra_capacity); if (gap_t != nullptr) {
RetypeBag(result, T_POSOBJ);
SET_TYPE_POSOBJ(result, gap_t);
CHANGED_BAG(result);
} return result;
}
} // namespace detail
template <> struct to_gap<libsemigroups::NTPMat<>> { using NTPMat_ = libsemigroups::NTPMat<>;
Obj operator()(NTPMat_ const& x) { using scalar_type = typename NTPMat_::scalar_type; 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<scalar_type>()(matrix_threshold(x)));
SET_ELM_PLIST(result,
x.number_of_rows() + 2,
to_gap<scalar_type>()(matrix_period(x))); return result;
}
};
namespace detail { template <typename S, typename T>
Obj make_transf(T const& x) {
static_assert(
std::is_same<S, UInt2>::value || std::is_same<S, UInt4>::value, "the template parameter S must be the same as UInt2 or UInt4");
static_assert(
IsTransf<T> #ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
|| std::is_same<T, HPCombi::Transf16>::value #endif
, "the template parameter T must be the same as Transf<> or Transf16");
autoconst N = libsemigroups::Degree<T>()(x);
Obj result = NEW_TRANS(N);
S* ptr = reinterpret_cast<S*>(static_cast<Obj*>(ADDR_OBJ(result) + 3)); for (S i = 0; i < N; ++i) {
ptr[i] = x[i];
} return result;
}
} // namespace detail
template <typename S, typename T>
Obj make_pperm(T const& x, S undef) {
static_assert(
std::is_same<S, UInt2>::value || std::is_same<S, UInt4>::value, "the template parameter T must be the same as UInt2 or UInt4");
static_assert(
IsPPerm<T> #ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
|| std::is_same<T, HPCombi::PPerm16>::value #endif
, "the template parameter T must be the same as PPerm<> or PPerm16");
S N = libsemigroups::Degree<T>()(x); // remove trailing 0s while (N > 0 && x[N - 1] == undef) {
N--;
}
Obj result = NEW_PPERM(N);
S* ptr
= reinterpret_cast<S*>(static_cast<Obj*>(ADDR_OBJ(result)) + 2) + 1; for (S i = 0; i < N; i++) { if (x[i] == undef) {
ptr[i] = 0;
} else {
ptr[i] = x[i] + 1;
}
} return result;
}
} // namespace detail
template <typename T> struct to_gap<libsemigroups::ActionDigraph<T>> { using ActionDigraph_ = libsemigroups::ActionDigraph<T>;
Obj operator()(ActionDigraph_ const& ad) const noexcept { using node_type = typename ActionDigraph_::node_type;
Obj result = NEW_PLIST(T_PLIST, ad.number_of_nodes()); // this is intentionally not IMMUTABLE // TODO(ActionDigraph) 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); if (val != UNDEFINED) {
AssPlist(next, j + 1, to_gap<node_type>()(val + 1));
}
}
SET_ELM_PLIST(result, i + 1, next);
CHANGED_BAG(result);
} return result;
}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.