Skip to content
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

Replace some calls to low-level GAP functions #782

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/src/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ GAP operations.
|--------------|----------|
| `length` | `Length` |
| `in` | `\in` |
| `zero` | `ZERO` |
| `one` | `ONE` |
| `-` (unary) | `AINV` |
| `zero` | `ZeroSameMutability` |
| `one` | `OneSameMutability` |
| `-` (unary) | `AdditiveInverseSameMutability` |
| `inv` | `InverseSameMutability` |
Comment on lines +43 to +46
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but perhaps we should instead switch the mapping:

Suggested change
| `zero` | `ZeroSameMutability` |
| `one` | `OneSameMutability` |
| `-` (unary) | `AdditiveInverseSameMutability` |
| `inv` | `InverseSameMutability` |
| `zero` | `Zero` |
| `one` | `One` |
| `-` (unary) | `AdditiveInverse` |
| `inv` | `Inverse` |

As that probably avoids further pain points. I am not sure if there is any good reason for mapping to the "same mutability" variants? Maybe @ThomasBreuer can think of any?

If we do such a switch, then I'd consider it a breaking change (i.e. for GAP.jl 0.8) as it at least in principle could break some existing code...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I had yesterday tried to add a comment here, but now I do not find it anymore. Strange. Anyhow, here it is again.)

In GAP, binary arithmetic operations return immutable results if and only if the two arguments are immutable.
Thus it is consistent if unary arithmetic operations return a result with the same mutability as the argument.
Of course, GAP has several variants of these unary operations, regarding the mutability of the result, but here we have to choose one behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, fair enough.

So, shall we merge this as-is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

| `+` | `SUM` |
| `-` (binary) | `DIFF` |
| `*` | `PROD` |
Expand Down
14 changes: 7 additions & 7 deletions src/adapter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ Base.hasproperty(x::GapObj, f::Union{AbstractString,Int64}) =
Wrappers.ISB_REC(x, RNamObj(f))

#
Base.zero(x::Union{GapObj,FFE}) = Wrappers.ZERO(x) # same mutability
Base.one(x::Union{GapObj,FFE}) = Wrappers.ONE_MUT(x) # same mutability
Base.inv(x::Union{GapObj,FFE}) = Wrappers.INV_MUT(x) # same mutability
Base.:-(x::Union{GapObj,FFE}) = Wrappers.AINV(x) # same mutability
Base.zero(x::Union{GapObj,FFE}) = Wrappers.ZeroSameMutability(x)
Base.one(x::Union{GapObj,FFE}) = Wrappers.OneSameMutability(x)
Base.inv(x::Union{GapObj,FFE}) = Wrappers.InverseSameMutability(x)
Base.:-(x::Union{GapObj,FFE}) = Wrappers.AdditiveInverseSameMutability(x)

#
Base.in(x::Any, y::GapObj) = Wrappers.IN(x, y)
Expand Down Expand Up @@ -325,11 +325,11 @@ Random.Sampler(::Type{<:AbstractGAPRNG}, x::AbstractVector, ::Random.Repetition)
Random.SamplerTrivial(julia_to_gap(x, recursive=false))


# The following bypasses GAP's redirection of `x^-1` to `INV_MUT(x)`.
# The following bypasses GAP's redirection of `x^-1` to `InverseSameMutability(x)`.
# Installing analogous methods for `x^0` and `x^1` would *not* be allowed,
# these terms are equivalent to `ONE_MUT(x)` and `x`, respectively,
# these terms are equivalent to `OneSameMutability(x)` and `x`, respectively,
# only if `x` is a multiplicative element in the sense of GAP.
Base.literal_pow(::typeof(^), x::GapObj, ::Val{-1}) = Wrappers.INV_MUT(x)
Base.literal_pow(::typeof(^), x::GapObj, ::Val{-1}) = Wrappers.InverseSameMutability(x)

# iteration

Expand Down
8 changes: 4 additions & 4 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Wrappers
using GAP
import GAP: @wrap

@wrap AINV(x::Any)::Any
@wrap AdditiveInverseSameMutability(x::Any)::Any
@wrap ASS_LIST(x::Any, i::Int, v::Any)::Nothing
@wrap ASS_MAT(x::Any, i::Int, j::Int, v::Any)::Nothing
@wrap ASS_REC(x::Any, y::Int, v::Any)::Nothing
Expand All @@ -21,7 +21,7 @@ import GAP: @wrap
@wrap EQ(x::Any, y::Any)::Bool
@wrap IN(x::Any, y::Any)::Bool
@wrap INT_CHAR(x::Any)::Int
@wrap INV_MUT(x::Any)::Any
@wrap InverseSameMutability(x::Any)::Any
@wrap IS_JULIA_FUNC(x::Any)::Bool
@wrap ISB_LIST(x::Any, i::Int)::Bool
@wrap ISB_REC(x::Any, y::Int)::Bool
Expand Down Expand Up @@ -49,7 +49,7 @@ import GAP: @wrap
@wrap NumberColumns(x::Any)::GapInt
@wrap NumberRows(x::Any)::GapInt
@wrap NumeratorRat(x::Any)::GapInt
@wrap ONE_MUT(x::Any)::Any
@wrap OneSameMutability(x::Any)::Any
@wrap PopOptions()::Nothing
@wrap POW(x::Any, y::Any)::Any
@wrap PROD(x::Any, y::Any)::Any
Expand All @@ -63,6 +63,6 @@ import GAP: @wrap
@wrap StringViewObj(x::Any)::Any
@wrap StructuralCopy(x::Any)::Any
@wrap SUM(x::Any, y::Any)::Any
@wrap ZERO(x::Any)::Any
@wrap ZeroSameMutability(x::Any)::Any

end