Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Allow Gap.__getattr__ to return GAP objects other than just functions
Browse files Browse the repository at this point in the history
There's no immediately obvious reason it should only be able to return
functions; there are some GAP globals that are not functions that might
still be of interest.

Cleans up the common_gap_functions list to remove entries that are either
not actually functions, or that no longer exist.  Added a common_gap_globals
list which includes common_gap_functions, but also other common globals
previously from common_gap_functions but that are not actually functions.
  • Loading branch information
embray committed Dec 12, 2018
1 parent 2820d4d commit 60d7eb6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 55 deletions.
50 changes: 5 additions & 45 deletions src/sage/libs/gap/gap_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"Gap functions"
"""Common global functions defined by GAP."""

###############################################################################
# Copyright (C) 2009, William Stein <wstein@gmail.com>
Expand All @@ -11,8 +11,9 @@
###############################################################################



# selected gap functions to use in tab completion
common_gap_functions = [
common_gap_functions = set([
'AbelianGroup',
'AbelianInvariants',
'AbelianInvariantsMultiplier',
Expand All @@ -37,13 +38,11 @@
'AppendTo',
'Apply',
'AsGroup',
'Assert',
'AtlasGroup',
'AutomorphismGroup',
'BaseOfGroup',
'Basis',
'BasisVectors',
'Bell',
'Bell',
'Binomial',
'BlockMatrix',
'Blocks',
Expand Down Expand Up @@ -125,7 +124,6 @@
'CyclicGroup',
'CyclotomicField',
'CyclotomicPolynomial',
'Cyclotomics',
'DefiningPolynomial',
'Degree',
'DegreeFFE',
Expand Down Expand Up @@ -210,8 +208,6 @@
'GaloisGroup',
'GaloisMat',
'GaloisStabilizer',
'GaussianIntegers',
'GaussianRationals',
'Gcd',
'GcdInt',
'GcdOp',
Expand All @@ -225,7 +221,6 @@
'GeneratorsOfField',
'GeneratorsOfGroup',
'GeneratorsOfIdeal',
'GlobalMersenneTwister',
'GroebnerBasis',
'Group',
'GroupHomomorphismByFunction',
Expand All @@ -243,23 +238,7 @@
'Image',
'Images',
'Index',
'InfoAlgebra',
'InfoAttributes',
'InfoBckt',
'InfoCharacterTable',
'InfoCoh',
'InfoComplement',
'InfoCoset',
'InfoFpGroup',
'InfoGroebner',
'InfoGroup',
'InfoLattice',
'InfoLevel',
'InfoMatrix',
'InfoMonomial',
'InfoNumtheor',
'InfoOptions',
'InfoPcSubgroup',
'InfoText',
'InnerAutomorphism',
'InnerAutomorphismsAutomorphismGroup',
Expand All @@ -269,7 +248,6 @@
'IntHexString',
'IntScalarProducts',
'IntVecFFE',
'Integers',
'IntersectSet',
'Intersection',
'InvariantBilinearForm',
Expand Down Expand Up @@ -319,7 +297,6 @@
'IsBinaryRelation',
'IsBlockMatrixRep',
'IsBool',
'IsBound',
'IsBoundGlobal',
'IsBrauerTable',
'IsBravaisGroup',
Expand Down Expand Up @@ -528,7 +505,6 @@
'IsTransitive',
'IsTransitiveBinaryRelation',
'IsTrivial',
'IsTuple',
'IsUniqueFactorizationRing',
'IsUnit',
'IsUnivariatePolynomial',
Expand Down Expand Up @@ -718,7 +694,6 @@
'MonomialGrevlexOrdering',
'MonomialGrlexOrdering',
'MonomialLexOrdering',
'MonomialTotalDegreeLess',
'MostFrequentGeneratorFpGroup',
'MovedPoints',
'MultRowVector',
Expand All @@ -742,7 +717,6 @@
'NextIterator',
'NextPrimeInt',
'NiceBasis',
'NiceBasisFiltersInfo',
'NiceFreeLeftModule',
'NiceFreeLeftModuleInfo',
'NiceMonomorphism',
Expand Down Expand Up @@ -933,7 +907,6 @@
'Position',
'PositionBound',
'PositionCanonical',
'PositionFirstComponent',
'PositionNonZero',
'PositionNot',
'PositionNthOccurrence',
Expand Down Expand Up @@ -976,7 +949,6 @@
'PrimePGroup',
'PrimePowersInt',
'PrimeResidues',
'Primes',
'PrimitiveElement',
'PrimitiveGroup',
'PrimitiveIdentification',
Expand Down Expand Up @@ -1047,7 +1019,6 @@
'RationalClass',
'RationalClasses',
'RationalizedMat',
'Rationals',
'Read',
'ReadAll',
'ReadAllLine',
Expand Down Expand Up @@ -1094,7 +1065,6 @@
'ReesMatrixSemigroupElement',
'ReesZeroMatrixSemigroup',
'ReesZeroMatrixSemigroupElement',
'ReesZeroMatrixSemigroupElementIsZero',
'RefinedPcGroup',
'RegularActionHomomorphism',
'RegularModule',
Expand Down Expand Up @@ -1124,7 +1094,6 @@
'Reread',
'RereadPackage',
'Reset',
'RestoreStateRandom',
'RestrictOutputsOfSLP',
'Restricted',
'RestrictedClassFunction',
Expand Down Expand Up @@ -1157,8 +1126,6 @@
'SSortedList',
'SU',
'SameBlock',
'SandwichMatrixOfReesMatrixSemigroup',
'SandwichMatrixOfReesZeroMatrixSemigroup',
'SaveWorkspace',
'ScalarProduct',
'SchurCover',
Expand Down Expand Up @@ -1249,7 +1216,6 @@
'StabilizerOfExternalSet',
'StabilizerPcgs',
'StandardAssociate',
'StandardGeneratorsInfo',
'StandardizeTable',
'StarCyc',
'Stirling1',
Expand Down Expand Up @@ -1296,7 +1262,6 @@
'SumIntersectionMat',
'SumX',
'SupersolvableResiduum',
'SupportedCharacterTableInfo',
'SurjectiveActionHomomorphismAttr',
'SuzukiGroup',
'SylowComplement',
Expand All @@ -1314,7 +1279,6 @@
'TableAutomorphisms',
'TableOfMarks',
'TableOfMarksByLattice',
'TableOfMarksComponents',
'TableOfMarksCyclic',
'TableOfMarksDihedral',
'TableOfMarksFrobenius',
Expand All @@ -1332,9 +1296,6 @@
'TracedCosetFpGroup',
'TransferDiagram',
'Transformation',
'TransformationData',
'TransformationRelation',
'TransformationType',
'TransformingPermutations',
'TransformingPermutationsCharacterTables',
'TransitiveClosureBinaryRelation',
Expand Down Expand Up @@ -1365,7 +1326,6 @@
'TrivialSubspace',
'Tuple',
'Tuples',
'Unbind',
'UnbindElmWPObj',
'UnbindGlobal',
'UnderlyingCharacterTable',
Expand Down Expand Up @@ -1443,4 +1403,4 @@
'ZeroSameMutability',
'GASMAN_STATS',
'GASMAN',
]
])
46 changes: 46 additions & 0 deletions src/sage/libs/gap/gap_globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Common globals defined by GAP."""

###############################################################################
# Copyright (C) 2009, William Stein <wstein@gmail.com>
# Copyright (C) 2012, Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
###############################################################################


from .gap_functions import common_gap_functions


# selected gap globals to use in tab completion
common_gap_globals = set([
'Assert',
'Cyclotomics',
'GaussianIntegers',
'GaussianRationals',
'GlobalMersenneTwister',
'GlobalRandomSource',
'InfoAlgebra',
'InfoAttributes',
'InfoBckt',
'InfoCharacterTable',
'InfoCoh',
'InfoComplement',
'InfoCoset',
'InfoFpGroup',
'InfoGroebner',
'InfoGroup',
'InfoLattice',
'InfoMatrix',
'InfoMonomial',
'InfoNumtheor',
'InfoOptions',
'InfoPcSubgroup',
'Integers',
'NiceBasisFiltersInfo',
'Primes',
'Rationals',
'TableOfMarksComponents'
]) | common_gap_functions
28 changes: 18 additions & 10 deletions src/sage/libs/gap/libgap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,13 @@ class Gap(Parent):
sage: 'OctaveAlgebra' in dir(libgap)
True
"""
from sage.libs.gap.gap_functions import common_gap_functions
return dir(self.__class__) + list(common_gap_functions)
from sage.libs.gap.gap_globals import common_gap_globals
return dir(self.__class__) + sorted(common_gap_globals)

def __getattr__(self, name):
r"""
The attributes of the Gap object are the Gap functions.
The attributes of the Gap object are the Gap functions, and in some
cases other global variables from GAP.
INPUT:
Expand All @@ -645,24 +646,31 @@ class Gap(Parent):
OUTPUT:
A :class:`GapElement_Function`. A ``AttributeError`` is raised
if there is no such function.
A :class:`GapElement`. A ``AttributeError`` is raised
if there is no such function or global variable.
EXAMPLES::
sage: libgap.List
<Gap function "List">
sage: libgap.GlobalRandomSource
<RandomSource in IsGlobalRandomSource>
"""
if name in dir(self.__class__):
return getattr(self.__class__, name)

from sage.libs.gap.gap_functions import common_gap_functions
from sage.libs.gap.gap_globals import common_gap_globals
if name in common_gap_functions:
f = make_GapElement_Function(self, gap_eval(str(name)))
assert f.is_function()
self.__dict__[name] = f
return f
g = make_GapElement_Function(self, gap_eval(name))
assert g.is_function()
elif name in common_gap_globals:
g = make_any_gap_element(self, gap_eval(name))
else:
raise AttributeError('No such attribute: '+name+'.')
raise AttributeError(f'No such attribute: {name}.')

self.__dict__[name] = g
return g

def show(self):
"""
Expand Down

0 comments on commit 60d7eb6

Please sign in to comment.