File: perm2.cpp

package info (click to toggle)
regina-normal 7.4.1-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 154,244 kB
  • sloc: cpp: 295,026; xml: 9,992; sh: 1,344; python: 1,225; perl: 616; ansic: 138; makefile: 26
file content (133 lines) | stat: -rw-r--r-- 6,824 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

/**************************************************************************
 *                                                                        *
 *  Regina - A Normal Surface Theory Calculator                           *
 *  Python Interface                                                      *
 *                                                                        *
 *  Copyright (c) 1999-2025, Ben Burton                                   *
 *  For further details contact Ben Burton (bab@debian.org).              *
 *                                                                        *
 *  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 2 of the    *
 *  License, or (at your option) any later version.                       *
 *                                                                        *
 *  As an exception, when this program is distributed through (i) the     *
 *  App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or     *
 *  (iii) Google Play by Google Inc., then that store may impose any      *
 *  digital rights management, device limits and/or redistribution        *
 *  restrictions that are required by its terms of service.               *
 *                                                                        *
 *  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/>. *
 *                                                                        *
 **************************************************************************/

#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/stl.h>
#include "maths/perm.h"
#include "utilities/typeutils.h"
#include "../helpers.h"
#include "../docstrings/maths/perm2.h"

using pybind11::overload_cast;
using regina::Perm;

namespace {
    static const int nPerms_1 = 1; // supporting deprecated constant below
}

void addPerm2(pybind11::module_& m) {
    RDOC_SCOPE_BEGIN(Perm)

    auto c = pybind11::class_<Perm<2>>(m, "Perm2", rdoc_scope)
        .def(pybind11::init<>(), rdoc::__default)
        .def(pybind11::init<int, int>(), rdoc::__init)
        .def(pybind11::init<const Perm<2>&>(), rdoc::__copy)
        // The std::array constructor must come last.  Otherwise an attempt to
        // use the copy constructor throws an exception: Perm has no len()
        .def(pybind11::init<const std::array<int, 2>&>(), rdoc::__init_2)
        .def_static("precompute", &Perm<2>::precompute, rdoc::precompute)
        .def("permCode", &Perm<2>::permCode, rdoc::permCode)
        .def("setPermCode", &Perm<2>::setPermCode, rdoc::setPermCode)
        .def_static("fromPermCode", &Perm<2>::fromPermCode, rdoc::fromPermCode)
        .def_static("isPermCode", &Perm<2>::isPermCode, rdoc::isPermCode)
        .def(pybind11::self * pybind11::self, rdoc::__mul)
        .def("cachedComp", overload_cast<const Perm<2>&>(
            &Perm<2>::cachedComp, pybind11::const_), rdoc::cachedComp)
        .def("cachedComp", [](Perm<2> p, Perm<2> q, Perm<2> r) { // deprecated
            return p.cachedComp(q).cachedComp(r);
        }, rdoc::cachedComp_2)
        .def("inverse", &Perm<2>::inverse, rdoc::inverse)
        .def("cachedInverse", &Perm<2>::cachedInverse, rdoc::cachedInverse)
        .def("conjugate", &Perm<2>::conjugate, rdoc::conjugate)
        .def("cachedConjugate", &Perm<2>::cachedConjugate,
            rdoc::cachedConjugate)
        .def("pow", &Perm<2>::pow, rdoc::pow)
        .def("cachedPow", &Perm<2>::cachedPow, rdoc::cachedPow)
        .def("order", &Perm<2>::order, rdoc::order)
        .def("cachedOrder", &Perm<2>::cachedOrder, rdoc::cachedOrder)
        .def("reverse", &Perm<2>::reverse, rdoc::reverse)
        .def("sign", &Perm<2>::sign, rdoc::sign)
        .def("__getitem__", &Perm<2>::operator[], rdoc::__array)
        .def("pre", &Perm<2>::pre, rdoc::pre)
        .def("compareWith", &Perm<2>::compareWith, rdoc::compareWith)
        .def("isIdentity", &Perm<2>::isIdentity, rdoc::isIdentity)
        .def("inc", [](Perm<2>& p) {
            return p++;
        }, rdoc::__inc)
        .def_static("rot", &Perm<2>::rot, rdoc::rot)
        .def_static("rand", static_cast<Perm<2>(&)(bool)>(Perm<2>::rand),
            pybind11::arg("even") = false, rdoc::rand)
        .def("trunc", &Perm<2>::trunc, rdoc::trunc)
        .def("clear", &Perm<2>::clear, rdoc::clear)
        .def("S2Index", &Perm<2>::S2Index, rdoc::S2Index)
        .def("SnIndex", &Perm<2>::SnIndex, rdoc::SnIndex)
        .def("orderedS2Index", &Perm<2>::orderedS2Index, rdoc::orderedS2Index)
        .def("orderedSnIndex", &Perm<2>::orderedSnIndex, rdoc::orderedSnIndex)
        .def("isConjugacyMinimal", &Perm<2>::isConjugacyMinimal,
            rdoc::isConjugacyMinimal)
        .def_readonly_static("degree", &Perm<2>::degree)
        .def_readonly_static("codeType", &Perm<2>::codeType)
        .def_readonly_static("nPerms", &Perm<2>::nPerms)
        .def_readonly_static("nPerms_1", &nPerms_1) // deprecated
        .def_readonly_static("S2", &Perm<2>::S2)
        .def_readonly_static("Sn", &Perm<2>::Sn)
        .def_readonly_static("orderedS2", &Perm<2>::orderedS2)
        .def_readonly_static("orderedSn", &Perm<2>::orderedSn)
    ;
    #if defined(__GNUC__)
    // The following members are deprecated, but we still need to bind
    // them.  Silence the inevitable deprecation warnings that will occur.
    #pragma GCC diagnostic push
    #if defined(__clang__)
    #pragma GCC diagnostic ignored "-Wdeprecated"
    #else
    #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    #endif
    #endif
    c.def_readonly_static("S1", &Perm<2>::S1) // deprecated
        .def_readonly_static("Sn_1", &Perm<2>::S1) // deprecated
    ;
    #if defined(__GNUC__)
    #pragma GCC diagnostic pop
    #endif
    regina::for_constexpr<3, 17>([&c](auto i) {
        c.def_static("contract", &Perm<2>::template contract<i>,
            rdoc::contract);
    });
    regina::python::add_output_basic(c, rdoc::str);
    regina::python::add_tight_encoding(c, rdoc::tightEncoding,
        rdoc::tightDecoding, rdoc::hash);
    regina::python::add_eq_operators(c, rdoc::__eq);
    regina::python::add_cmp_operators(c, rdoc::__cmp);

    RDOC_SCOPE_END
}