On Fri, Dec 14, 2018 at 12:32 PM E. Madison Bray <erik.m.b...@gmail.com> wrote: > > I'm not exactly sure what you mean by "function factorised" but regardless I > don't think it's a deep mystery. Just look at Gap.__getattr__
I see. By the way, could you explain the need for Length = libgap.function_factory('Length') FlagsType = libgap.function_factory('FlagsType') TypeObj = libgap.function_factory('TypeObj') IS_SUBSET_FLAGS = libgap.function_factory('IS_SUBSET_FLAGS') GET_OPER_FLAGS = libgap.function_factory('GET_OPER_FLAGS') OPERATIONS = libgap.get_global('OPERATIONS') NameFunction = libgap.function_factory('NameFunction') in src/sage/libs/gap/operations.py ? With Gap.__getattr__ they seem to be not needed. This is what confused me into thinking that the only way to get a GAP function into libgap is to explicitly wrap it in function_factory(). One has similar explicit calls to function_factory() in src/sage/libs/gap/assigned_names.py (the latter can go completely, right?) Dima > > On Fri, Dec 14, 2018, 13:30 Dima Pasechnik <dimp...@gmail.com wrote: >> >> On Fri, Dec 14, 2018 at 11:54 AM E. Madison Bray <erik.m.b...@gmail.com> >> wrote: >> > >> > On Fri, Dec 14, 2018 at 12:17 PM Dima Pasechnik <dimp...@gmail.com> wrote: >> > > >> > > On Fri, Dec 14, 2018 at 11:10 AM E. Madison Bray <erik.m.b...@gmail.com> >> > > wrote: >> > > > >> > > > On Fri, Dec 14, 2018 at 11:55 AM Dima Pasechnik <dimp...@gmail.com> >> > > > wrote: >> > > > > >> > > > > On Fri, Dec 14, 2018 at 10:19 AM E. Madison Bray >> > > > > <erik.m.b...@gmail.com> wrote: >> > > > > > >> > > > > > There is also an existing hard-coded list of function names that >> > > > > > are >> > > > > > actually what's used for dir() and tab-completion, completely >> > > > > > separate >> > > > > > from this module. AFAICT this all_documented_functions module >> > > > > > isn't >> > > > > > really used anywhere in Sage, and doesn't turn up much in the >> > > > > > documentation. As Alex Konovalov pointed out to me, the >> > > > > > "example" in >> > > > > > all_documented_functions of doing `from >> > > > > > sage.libs.gaps.all_documented_functions import *` is probably not a >> > > > > > good idea in most cases anyways. For example: >> > > > > > >> > > > > > sage: DihedralGroup(8) >> > > > > > Dihedral group of order 16 as a permutation group >> > > > > > sage: type(_) >> > > > > > <class >> > > > > > 'sage.groups.perm_gps.permgroup_named.DihedralGroup_with_category'> >> > > > > > sage: from sage.libs.gap.all_documented_functions import * >> > > > > > sage: DihedralGroup(8) >> > > > > > <pc group of size 8 with 3 generators> >> > > > > > sage: type(_) >> > > > > > <type 'sage.libs.gap.element.GapElement'> >> > > > > > >> > > > > > Oops, this clobbers multiple existing built-ins in Sage. Alex also >> > > > > > suggested that using IsDocumentedWord like this was perhaps >> > > > > > ill-considered in the first place. >> > > > > > >> > > > > > Given that it isn't actually used anywhere in Sage, and is not >> > > > > > particularly documented, and mostly seems to cause problems, it >> > > > > > would >> > > > > > be best just to remove this? Does anyone use it? >> > > > > >> > > > > it's used for tab completion and as well for directly calling libgap >> > > > > functions >> > > > > (otherwise you need to call libgap's function_factory on them): >> > > > >> > > > It isn't though. You and Volker both seem to be confusing two >> > > > different things, unless I'm missing something. >> > > In all_documented_functions.py you see >> > > >> > > for _f in _FUNCTIONS: >> > > globals()[_f] = libgap.function_factory(_f) >> > >> > ... yes, but, module-level code still does not get executed unless the >> > module is actually imported at some point, which it isn't. I thought >> > the grep output I showed demonstrated this but go ahead and try it >> > yourself. Remove both sage.libs.gap.assigned_names and >> > sage.libs.gap.all_documented_functions. These modules are not used at >> > all by anything. >> > >> > > and this is exactly the "function_factorisation" of everything in >> > > sage.libs.gap.gap_functions >> > > >> > > So simply removing all_documented_functions.py will break a hell of a >> > > lot of code. >> > > >> > > (although there is of course nothing against merging >> > > sage.libs.gap.gap_functions >> > > and sage.libs.gap.all_documented_functions - unless I miss something) >> > >> > I think you're definitely missing something. >> >> Indeed, my bad, sorry. I was confusing these with libgap-prefixed things. >> I'm OK with removing sage.libs.gap.all_documented_functions >> >> It's still a mystery to me how some GAP functions are >> "function_factorised" though. >> >> >> >> > >> > >> > > > Grep the sources >> > > > yourself: The module sage.libs.gap.all_documented_functions is not >> > > > referenced anywhere outside of itself: >> > > > >> > > > $ grep -R all_documented_functions src/sage >> > > > src/sage/libs/gap/all_documented_functions.py: sage: from >> > > > sage.libs.gap.all_documented_functions import * >> > > > >> > > > What *is* used to provide directory/tab-completion is a different >> > > > module called sage.libs.gap.gap_functions, which just contains a >> > > > hard-coded list of strings naming various GAP functions. In fact I >> > > > recently updated [1] this list because it contained some globals which >> > > > are not functions, as well as a few that no longer exist: >> > > > https://git.sagemath.org/sage.git/commit/?id=60d7eb69ffa7d402495717148879906639324244 >> > > > >> > > > Actually, it would be good at least if the list in this module were >> > > > tested to ensure it remains valid. When I updated it I did something >> > > > like >> > > > >> > > > for name in common_gap_functions: >> > > > try: >> > > > func = libgap.eval(name) >> > > > except Exception as exc: >> > > > print("{} possibly missing? Error: {}".format(name, exc) >> > > > continue >> > > > >> > > > if not IsFunction(func): >> > > > print("{}: not a function".format(func)) >> > > > >> > > > >> > > > >> > > > >> > > > > > On Tue, Dec 11, 2018 at 4:52 PM Volker Braun >> > > > > > <vbraun.n...@gmail.com> wrote: >> > > > > > > >> > > > > > > This is basically the tab completion list in the Sage/libgap >> > > > > > > interface. As you found out, creating it on the fly is way too >> > > > > > > slow. Hence we cache a reasonable list of names. >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > On Tuesday, December 11, 2018 at 9:52:53 AM UTC-5, E. Madison >> > > > > > > Bray wrote: >> > > > > > >> >> > > > > > >> In the sage.libs.gap package, in the assigned_names.py module, >> > > > > > >> there >> > > > > > >> is a function called just list_functions() [1] which is >> > > > > > >> documented to >> > > > > > >> "Return the GAP documented global functions". >> > > > > > >> >> > > > > > >> This is used in the all_documented_functions.py [2] module to >> > > > > > >> create >> > > > > > >> Python wrappers for "all documented GAP functions, they can be >> > > > > > >> thought >> > > > > > >> of as the official API of GAP". >> > > > > > >> >> > > > > > >> This turns out to create a bit of a problem: The GAP function >> > > > > > >> IsDocumentedWord, which this code uses to determine if a >> > > > > > >> function is >> > > > > > >> "documented", works by searching for the function's name in all >> > > > > > >> documentation known to GAP. By default this is just the >> > > > > > >> standard GAP >> > > > > > >> reference docs. However, if you have any GAP packages >> > > > > > >> installed, it >> > > > > > >> will *also* search the docs for those packages. >> > > > > > >> >> > > > > > >> If you have lots of packages installed that means this is >> > > > > > >> *extremely* >> > > > > > >> slow, even if we're just searching for terms that we only care >> > > > > > >> about >> > > > > > >> being in the main GAP docs. >> > > > > > >> >> > > > > > >> Though perhaps it is a faulty assumption that this is "the >> > > > > > >> official >> > > > > > >> API of GAP" in the first place. Or at the very least, perhaps >> > > > > > >> we >> > > > > > >> don't really need to care about whether or not the function is >> > > > > > >> "documented", and that just returning all global functions is >> > > > > > >> good >> > > > > > >> enough for a first pass. >> > > > > > >> >> > > > > > >> But I'm not sure. Volker wrote this code originally so he >> > > > > > >> would know >> > > > > > >> best. But what do we want to present as the "API" provided by >> > > > > > >> Sage's >> > > > > > >> GAP interface? >> > > > > > >> >> > > > > > >> >> > > > > > >> >> > > > > > >> >> > > > > > >> >> > > > > > >> >> > > > > > >> [1] >> > > > > > >> https://gitlab.com/sagemath/sage/blob/master/src/sage/libs/gap/assigned_names.py#L118 >> > > > > > >> [2] >> > > > > > >> https://gitlab.com/sagemath/sage/blob/master/src/sage/libs/gap/all_documented_functions.py >> > > > > > > >> > > > > > > -- >> > > > > > > You received this message because you are subscribed to the >> > > > > > > Google Groups "sage-devel" group. >> > > > > > > To unsubscribe from this group and stop receiving emails from >> > > > > > > it, send an email to sage-devel+unsubscr...@googlegroups.com. >> > > > > > > To post to this group, send email to sage-devel@googlegroups.com. >> > > > > > > Visit this group at https://groups.google.com/group/sage-devel. >> > > > > > > For more options, visit https://groups.google.com/d/optout. >> > > > > > >> > > > > > -- >> > > > > > You received this message because you are subscribed to the Google >> > > > > > Groups "sage-devel" group. >> > > > > > To unsubscribe from this group and stop receiving emails from it, >> > > > > > send an email to sage-devel+unsubscr...@googlegroups.com. >> > > > > > To post to this group, send email to sage-devel@googlegroups.com. >> > > > > > Visit this group at https://groups.google.com/group/sage-devel. >> > > > > > For more options, visit https://groups.google.com/d/optout. >> > > > > >> > > > > -- >> > > > > You received this message because you are subscribed to the Google >> > > > > Groups "sage-devel" group. >> > > > > To unsubscribe from this group and stop receiving emails from it, >> > > > > send an email to sage-devel+unsubscr...@googlegroups.com. >> > > > > To post to this group, send email to sage-devel@googlegroups.com. >> > > > > Visit this group at https://groups.google.com/group/sage-devel. >> > > > > For more options, visit https://groups.google.com/d/optout. >> > > > >> > > > -- >> > > > You received this message because you are subscribed to the Google >> > > > Groups "sage-devel" group. >> > > > To unsubscribe from this group and stop receiving emails from it, send >> > > > an email to sage-devel+unsubscr...@googlegroups.com. >> > > > To post to this group, send email to sage-devel@googlegroups.com. >> > > > Visit this group at https://groups.google.com/group/sage-devel. >> > > > For more options, visit https://groups.google.com/d/optout. >> > > >> > > -- >> > > You received this message because you are subscribed to the Google >> > > Groups "sage-devel" group. >> > > To unsubscribe from this group and stop receiving emails from it, send >> > > an email to sage-devel+unsubscr...@googlegroups.com. >> > > To post to this group, send email to sage-devel@googlegroups.com. >> > > Visit this group at https://groups.google.com/group/sage-devel. >> > > For more options, visit https://groups.google.com/d/optout. >> > >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "sage-devel" group. >> > To unsubscribe from this group and stop receiving emails from it, send an >> > email to sage-devel+unsubscr...@googlegroups.com. >> > To post to this group, send email to sage-devel@googlegroups.com. >> > Visit this group at https://groups.google.com/group/sage-devel. >> > For more options, visit https://groups.google.com/d/optout. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sage-devel" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sage-devel+unsubscr...@googlegroups.com. >> To post to this group, send email to sage-devel@googlegroups.com. >> Visit this group at https://groups.google.com/group/sage-devel. >> For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.