Path: blob/main/src/auxiliary/vector_of_arrays.jl
2055 views
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).1# Since these FMAs can increase the performance of many numerical algorithms,2# we need to opt-in explicitly.3# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.4@muladd begin5#! format: noindent67# Wraps a Vector of Arrays, forwards `getindex` to the underlying Vector.8# Implements `Adapt.adapt_structure` to allow offloading to the GPU which is9# not possible for a plain Vector of Arrays.10struct VecOfArrays{T <: AbstractArray}11arrays::Vector{T}12end13Base.getindex(v::VecOfArrays, i::Int) = Base.getindex(v.arrays, i)14Base.IndexStyle(v::VecOfArrays) = Base.IndexStyle(v.arrays)15Base.size(v::VecOfArrays) = Base.size(v.arrays)16Base.length(v::VecOfArrays) = Base.length(v.arrays)17Base.eltype(v::VecOfArrays{T}) where {T} = T18function Adapt.adapt_structure(to, v::VecOfArrays)19return VecOfArrays([Adapt.adapt(to, arr) for arr in v.arrays])20end21function Adapt.parent_type(::Type{<:VecOfArrays{T}}) where {T}22return T23end24function Adapt.unwrap_type(A::Type{<:VecOfArrays})25Adapt.unwrap_type(Adapt.parent_type(A))26end27function Base.convert(::Type{<:VecOfArrays}, v::Vector{<:AbstractArray})28VecOfArrays(v)29end30end # @muladd313233