Skip to content

Commit 8476468

Browse files
author
Uwe Hernandez Acosta
committed
added utils for flattening of momenta to tests
1 parent 3660d29 commit 8476468

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/phase_spaces.jl

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ struct PhasespaceDefinition{CS<:AbstractCoordinateSystem,F<:AbstractFrameOfRefer
1919
frame::F
2020
end
2121

22+
"""
23+
_generate_momenta(
24+
proc::AbstractProcessDefinition,
25+
model::AbstractModelDefinition,
26+
in_phase_space_def::AbstractPhasespaceDefinition,
27+
in_phase_space::AbstractVector{T},
28+
out_phase_space_def::AbstractPhasespaceDefinition,
29+
out_phase_space::AbstractVector{T},
30+
) where {T<:Real}
31+
"""
32+
function _generate_momenta end
33+
34+
2235
# abstract type for generic phase spaces
2336
#
2437
# Currently, elements can be either four-momenta, or real numbers,

test/utils/utils.jl

+28
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,31 @@ include("test_implementations.jl")
66
_any_fail(x...) = true
77
_any_fail(::TestProcess, ::TestModel) = false
88
_any_fail(::TestProcess, ::TestModel, ::TestPhasespaceDef, ::TestPhasespaceDef) = false
9+
10+
# unrolls all elements of a list of four-momenta into vector of coordinates
11+
function _unroll_moms(ps_moms::AbstractVector{T}) where {T<:QEDbase.AbstractFourMomentum}
12+
collect(Iterators.flatten(ps_moms))
13+
end
14+
15+
function _unroll_moms(ps_moms::AbstractMatrix{T}) where {T<:QEDbase.AbstractFourMomentum}
16+
end
17+
18+
19+
# collect components of four-momenta from a vector of coordinates
20+
function __furl_moms(ps_coords::AbstractVector{T}) where {T<:Real}
21+
SFourMomentum.(eachcol(reshape(ps_coords,4,:)))
22+
end
23+
24+
function _furl_moms(ps_coords::AbstractVector{T}) where {T<:Real}
25+
@assert length(ps_coords)%4==0
26+
__furl_moms(ps_coords)
27+
end
28+
29+
function _furl_moms(ps_coords::AbstractMatrix{T}) where {T<:Real}
30+
@assert size(ps_coords,1)%4==0
31+
res = Matrix{SFourMomentum}(undef,Int(size(ps_coords,1)//4),size(ps_coords,2))
32+
for i in 1:size(ps_coords,2)
33+
res[:,i] .= __furl_moms(view(ps_coords,:,i))
34+
end
35+
return res
36+
end

0 commit comments

Comments
 (0)