-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Helpers for Information about Operations and Filters #1593
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
## | ||
## Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany | ||
## (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland | ||
## Copyright (C) 2002 The GAP Group | ||
## | ||
## This software is licensed under the GPL 2 or later, please refer | ||
## to the COPYRIGHT.md and LICENSE files for details. | ||
## | ||
|
||
############################################################################# | ||
## | ||
#V IdOfFilter | ||
## | ||
## <#GAPDoc Label="IdOfFilter"> | ||
## <ManSection> | ||
## <Func Name="IdOfFilter" Arg="filter"/> | ||
## <Func Name="IdOfFilterByName" Arg="name"/> | ||
## | ||
## <Description> | ||
## finds the id of the filter <A>filter</A>, or the id of the filter | ||
## with name <A>name</A> respectively. | ||
## The id of a filter is equal to the | ||
## position of this filter in the global FILTERS list. | ||
## <P/> | ||
## Note that not every <C>filter</C> for which <C>IsFilter(filter)</C> | ||
## returns <C>true</C> has an ID, only elementary filters do. | ||
## </Description> | ||
## </ManSection> | ||
## <#/GAPDoc> | ||
## | ||
## Note that the filter ID is stored in FLAG1_FILTER for most filters, | ||
## testers have the ID stored in FLAG2_FILTER, so the code below is | ||
## more efficient than just iterating over the FILTERS list. | ||
## | ||
## | ||
BIND_GLOBAL( "IdOfFilter", | ||
function(filter) | ||
local fid; | ||
atomic readonly FILTER_REGION do | ||
fid := FLAG1_FILTER(filter); | ||
if fid > 0 and FILTERS[fid] = filter then | ||
return fid; | ||
fi; | ||
fid := FLAG2_FILTER(filter); | ||
if fid > 0 and FILTERS[fid] = filter then | ||
return fid; | ||
fi; | ||
od; | ||
return fail; | ||
end); | ||
|
||
BIND_GLOBAL( "IdOfFilterByName", | ||
name -> PositionProperty(FILTERS, f -> NAME_FUNC(f) = name) ); | ||
|
||
############################################################################# | ||
## | ||
#V FilterByName | ||
## | ||
## <#GAPDoc Label="FilterByName"> | ||
## <ManSection> | ||
## <Func Name="FilterByName" Arg="name"/> | ||
## | ||
## <Description> | ||
## finds the filter with name <A>name</A> in the global FILTERS list. This | ||
## is useful to find filters that were created but not bound to a global | ||
## variable. | ||
## </Description> | ||
## </ManSection> | ||
## <#/GAPDoc> | ||
## | ||
BIND_GLOBAL( "FilterByName", | ||
name -> First(FILTERS, f -> NAME_FUNC(f) = name) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
gap> test := x -> List([IsFilter, IsCategory, IsRepresentation, IsAttribute, IsProperty, IsOperation], f -> f(x));; | ||
gap> test(IsFinite); | ||
[ true, false, false, false, true, true ] | ||
|
||
# | ||
gap> test(IsMagma); | ||
[ true, true, false, false, false, true ] | ||
|
||
# | ||
gap> test(IsCommutative); | ||
[ true, false, false, false, true, true ] | ||
|
||
# | ||
gap> test(Size); | ||
[ false, false, false, true, false, true ] | ||
|
||
# | ||
gap> test(Group); | ||
[ false, false, false, false, false, false ] | ||
|
||
# | ||
gap> test((1,2,3)); | ||
[ false, false, false, false, false, false ] | ||
|
||
# | ||
gap> test("hello, world"); | ||
[ false, false, false, false, false, false ] | ||
|
||
# | ||
gap> FilterByName("IsCommutative"); | ||
<Property "IsCommutative"> | ||
gap> CategoryByName("IsMagma"); | ||
<Category "IsMagma"> | ||
|
||
# | ||
gap> atomic readonly FILTER_REGION do filters := Immutable(FILTERS); od; | ||
gap> ForAll([1..Length(filters)], id -> id = IdOfFilter(filters[id])); | ||
true | ||
|
||
# | ||
gap> TypeOfOperation(IsFilter); | ||
Error, <oper> must be an operation | ||
|
||
# | ||
gap> List([IsAbelian, HasIsAbelian, IsMutable, \+, Size, AbelianGroupCons, Setter(IS_MUTABLE_OBJ)], TypeOfOperation); | ||
[ "Property", "Filter", "Category", "Operation", "Attribute", "Constructor", | ||
"Setter" ] | ||
|
||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
## | ||
## Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany | ||
## (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland | ||
## Copyright (C) 2002 The GAP Group | ||
## | ||
## This software is licensed under the GPL 2 or later, please refer | ||
## to the COPYRIGHT.md and LICENSE files for details. | ||
## | ||
|
||
############################################################################# | ||
## | ||
#V IdOfFilter | ||
## | ||
## <#GAPDoc Label="IdOfFilter"> | ||
## <ManSection> | ||
## <Func Name="IdOfFilter" Arg="filter"/> | ||
## <Func Name="IdOfFilterByName" Arg="name"/> | ||
## | ||
## <Description> | ||
## finds the id of the filter <A>filter</A>, or the id of the filter | ||
## with name <A>name</A> respectively. | ||
## The id of a filter is equal to the | ||
## position of this filter in the global FILTERS list. | ||
## <P/> | ||
## Note that not every <C>filter</C> for which <C>IsFilter(filter)</C> | ||
## returns <C>true</C> has an ID, only elementary filters do. | ||
## </Description> | ||
## </ManSection> | ||
## <#/GAPDoc> | ||
## | ||
## Note that the filter ID is stored in FLAG1_FILTER for most filters, | ||
## testers have the ID stored in FLAG2_FILTER, so the code below is | ||
## more efficient than just iterating over the FILTERS list. | ||
## | ||
## | ||
BIND_GLOBAL( "IdOfFilter", | ||
function(filter) | ||
local fid; | ||
fid := FLAG1_FILTER(filter); | ||
if fid > 0 and FILTERS[fid] = filter then | ||
return fid; | ||
fi; | ||
fid := FLAG2_FILTER(filter); | ||
if fid > 0 and FILTERS[fid] = filter then | ||
return fid; | ||
fi; | ||
return fail; | ||
end); | ||
|
||
BIND_GLOBAL( "IdOfFilterByName", | ||
name -> PositionProperty(FILTERS, f -> NAME_FUNC(f) = name) ); | ||
|
||
############################################################################# | ||
## | ||
#V FilterByName | ||
## | ||
## <#GAPDoc Label="FilterByName"> | ||
## <ManSection> | ||
## <Func Name="FilterByName" Arg="name"/> | ||
## | ||
## <Description> | ||
## finds the filter with name <A>name</A> in the global FILTERS list. This | ||
## is useful to find filters that were created but not bound to a global | ||
## variable. | ||
## </Description> | ||
## </ManSection> | ||
## <#/GAPDoc> | ||
## | ||
BIND_GLOBAL( "FilterByName", | ||
name -> First(FILTERS, f -> NAME_FUNC(f) = name) ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I am not sure I understand this (both old and new version). Perhaps we can walk through it? (And perhaps the comment above it could be expanded to explain it, too?)
So first we handle
IS_OBJECT
/IsObject
, which is special. OK. next we exclude everything that is not an operation, also fine.But now in the old code, we look at
FLAG1_FILTER( x )
, and it is non-zero, we considerx
a filter. Aha. But this is not quite right, as we have:So I guess that's why you changed this to also requite
FLAGS_FILTER(x) <> false
? How about instead or additional usingNARG_FUNC(x)=1
? I simply suggest that as it is immediately clear to me why that's a necessary condition for a filter, whileFLAGS_FILTER(x) <> false
isn't (simply because I have to look up what it does). But anyway, if usingFLAGS_FILTER
is "correct", that's also fine.So... that leaves the question: Why do we need the final
or x in FILTERS
? Aha:Aha! So testers for attributes fall through:
Hmm...
At this point I got a headache, and started to wonder: Why don't we add a bit "isFilter" to the header of an operation, and add an
IS_FILTER
function to the kernel, which just returns that bit?Note that we don't even need to grow the operation header for this, we could split
ENABLED_ATTR
into a bitfield. (I'd start by adding anOperationHeader
struct, as described previously)Anyway: none of that is necessary for this PR: even adding a better comment can come in another PR. Let's just not forget...