Skip to content

Commit

Permalink
add literal_pow overload (#151)
Browse files Browse the repository at this point in the history
* add literal_pow overload

* fix typo

* Update particles.jl

* add test

---------

Co-authored-by: Alexander Plavin <[email protected]>
  • Loading branch information
baggepinnen and aplavin authored Dec 20, 2024
1 parent 6ca57ed commit 4c886db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ for PT in ParticleSymbols
res = p.particles.^i
$PT{eltype(res),N}(res)
end

function Base.literal_pow(::typeof(^), p::$PT{T,N}, ::Val{i}) where {T,N,i}
res = Base.literal_pow.(^, p.particles, Val(i))
$PT{eltype(res),N}(res)
end

Base.:\(p::Vector{<:$PT}, p2::Vector{<:$PT}) = Matrix(p)\Matrix(p2) # Must be here to be most specific

function LinearAlgebra.eigvals(p::Matrix{$PT{T,N}}; kwargs...) where {T,N} # Special case to propte types differently
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ Random.seed!(0)


f = x -> x^2
f3 = x -> x^3
p = PT(100)
@test 0.9 < pmean(f(p)) < 1.1
@test 0.9 < pmean(f(p)) < 1.1
@test f(p) 1
@test f3(p) 1
@test !(f(p) 1)
@test f(p) 5
@test -3 f(p)
Expand Down

0 comments on commit 4c886db

Please sign in to comment.