Skip to content

Commit

Permalink
Generalize or restrict a few basic operators
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Mar 11, 2022
1 parent 8076517 commit 4cd4033
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,9 @@ julia> identity("Well, what did you expect?")
"""
identity(x) = x

+(x::Number) = x
*(x::Number) = x
+(x) = x
-(x) = (-1)*x
*(x) = x
(&)(x::Integer) = x
(|)(x::Integer) = x
xor(x::Integer) = x
Expand Down Expand Up @@ -626,7 +627,7 @@ julia> inv(A) * x
-7.0
```
"""
\(x,y) = adjoint(adjoint(y)/adjoint(x))
\(x::Number, y::Number) = conj(conj(y)/conj(x))

# Core <<, >>, and >>> take either Int or UInt as second arg. Signed shift
# counts can shift in either direction, and are translated here to unsigned
Expand Down
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ pinv(v::TransposeAbsVec, tol::Real = 0) = pinv(conj(v.parent)).parent

## left-division \
\(u::AdjOrTransAbsVec, v::AdjOrTransAbsVec) = pinv(u) * v
\(u::AdjointAbsVec, y::Number) = adjoint(conj(y) / u.parent)
\(u::TransposeAbsVec, y::Number) = transpose(y / u.parent)


## right-division /
Expand Down
5 changes: 1 addition & 4 deletions stdlib/LinearAlgebra/test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,13 @@ Base.:*(a::ModInt{n}, b::ModInt{n}) where {n} = ModInt{n}(a.k * b.k)
Base.:-(a::ModInt{n}) where {n} = ModInt{n}(-a.k)
Base.inv(a::ModInt{n}) where {n} = ModInt{n}(invmod(a.k, n))
Base.:/(a::ModInt{n}, b::ModInt{n}) where {n} = a*inv(b)
Base.:\(a::ModInt{n}, b::ModInt{n}) where {n} = inv(a)*b

Base.zero(::Type{ModInt{n}}) where {n} = ModInt{n}(0)
Base.zero(::ModInt{n}) where {n} = ModInt{n}(0)
Base.one(::Type{ModInt{n}}) where {n} = ModInt{n}(1)
Base.one(::ModInt{n}) where {n} = ModInt{n}(1)
Base.conj(a::ModInt{n}) where {n} = a
Base.adjoint(a::ModInt{n}) where {n} = ModInt{n}(conj(a))
Base.transpose(a::ModInt{n}) where {n} = a # see Issue 20978
LinearAlgebra.Adjoint(a::ModInt{n}) where {n} = adjoint(a)
LinearAlgebra.Transpose(a::ModInt{n}) where {n} = transpose(a)

@testset "Issue 22042" begin
A = [ModInt{2}(1) ModInt{2}(0); ModInt{2}(1) ModInt{2}(1)]
Expand Down

0 comments on commit 4cd4033

Please sign in to comment.