Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
Open
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
8 changes: 1 addition & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CUDAKernels = "72cfdca4-0801-4ab0-bf6a-d52aa10adc57"
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Expand All @@ -23,15 +20,12 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
Adapt = "3"
ArrayInterface = "3"
ArrayInterface = "3, 4"
CUDA = "3"
CUDAKernels = "0.2, 0.3"
ExprTools = "0.1"
FillArrays = "0.11, 0.12"
GPUArrays = "8"
KernelAbstractions = "0.6, 0.7"
LazyArrays = "0.20, 0.21, 0.22"
LoopVectorization = "0.11, 0.12"
StaticArrays = "0.12, 1"
StructArrays = "0.6"
Tullio = "0.2, 0.3"
Expand Down
2 changes: 0 additions & 2 deletions src/Bennu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ using CUDAKernels
using FillArrays
using GPUArrays
using KernelAbstractions
using LazyArrays
using LinearAlgebra
using LoopVectorization
using SparseArrays
using StaticArrays
using StaticArrays: tuple_prod, tuple_length, size_to_tuple
Expand Down
4 changes: 2 additions & 2 deletions src/cells.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function LobattoCell{T, A}(dims...) where {T, A}

derivatives = ntuple(N) do i
tup = ntuple(j->ifelse(i==j, o[i].derivative, Eye{T}(dims[j])), N)
return Kron(reverse(tup)...)
return Kron(reverse(tup))
end

mass = Diagonal(vec(.*(weights_1d...)))
Expand All @@ -81,7 +81,7 @@ function LobattoCell{T, A}(dims...) where {T, A}
repeat(vec(ω1 .* ω2), 2)))
end

toequallyspaced = Kron(reverse(ntuple(i->o[i].toequallyspaced, N))...)
toequallyspaced = Kron(reverse(ntuple(i->o[i].toequallyspaced, N)))

connectivity = adapt(A, materializeconnectivity(LobattoCell, dims...))

Expand Down
86 changes: 39 additions & 47 deletions src/kroneckeroperators.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
Adapt.adapt_structure(to, K::Kron) = Kron(map(x->Adapt.adapt(to, x), K.args)...)
components(K::Kron) = LazyArrays.arguments(K)
struct Kron{T}
args::T
Kron(args::Tuple) = new{typeof(args)}(args)
end

Adapt.adapt_structure(to, K::Kron) = Kron(map(x->Adapt.adapt(to, x), K.args))
components(K::Kron) = K.args
Base.collect(K::Kron) = collect(kron(K.args...))
Base.size(K::Kron, j::Int) = prod(size.(K.args, j))

import Base.==
==(J::Kron, K::Kron) = all(J.args .== K.args)

import Base.*

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{D}}, F}) where
{T, L, D <: AbstractMatrix{T}, F <: AbstractVecOrMat}
K, f = M.A, M.B
(d,) = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{D}}, f::F) where {D <: AbstractMatrix,
F <: AbstractVecOrMat}
(d,) = components(K)

g = reshape(f, size(d, 2), :)
r = similar(f, size(d, 1), size(g, 2))
Expand All @@ -15,11 +25,9 @@ function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
return F <: AbstractVector ? vec(r) : reshape(r, size(K, 1), size(f, 2))
end

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{E, D}}, F}) where
{T, L, D <: AbstractMatrix{T}, E <: Eye{T}, F <: AbstractVecOrMat}
K, f = M.A, M.B
e, d = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{E, D}}, f::F) where
{D <: AbstractMatrix, E <: Eye, F <: AbstractVecOrMat}
e, d = components(K)

g = reshape(f, size(d, 2), size(e, 1), :)
r = similar(f, size(d, 1), size(e, 1), size(g, 3))
Expand All @@ -29,11 +37,9 @@ function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
return F <: AbstractVector ? vec(r) : reshape(r, size(K, 1), size(f, 2))
end

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{D, E}}, F}) where
{T, L, D <: AbstractMatrix{T}, E <: Eye{T}, F <: AbstractVecOrMat}
K, f = M.A, M.B
d, e = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{D, E}}, f::F) where
{D <: AbstractMatrix, E <: Eye, F <: AbstractVecOrMat}
d, e = components(K)

g = reshape(f, size(e, 1), size(d, 2), :)
r = similar(f, size(e, 1), size(d, 1), size(g, 3))
Expand All @@ -43,12 +49,9 @@ function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
return F <: AbstractVector ? vec(r) : reshape(r, size(K, 1), size(f, 2))
end

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{B, A}}, F}) where
{T, L, A <: AbstractMatrix{T}, B <: AbstractMatrix{T},
F <: AbstractVecOrMat}
K, f = M.A, M.B
b, a = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{B, A}}, f::F) where
{A <: AbstractMatrix, B <: AbstractMatrix, F <: AbstractVecOrMat}
b, a = components(K)

g = reshape(f, size(a, 2), size(b, 2), :)
r = similar(f, size(a, 1), size(b, 1), size(g, 3))
Expand All @@ -58,12 +61,9 @@ function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
return F <: AbstractVector ? vec(r) : reshape(r, size(K, 1), size(f, 2))
end

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{E₃, E₂, D}}, F}) where
{T, L, D <: AbstractMatrix{T}, E₃ <: Eye{T}, E₂ <: Eye{T},
F <: AbstractVecOrMat}
K, f = M.A, M.B
e₃, e₂, d = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{E₃, E₂, D}}, f::F) where
{D <: AbstractMatrix, E₃ <: Eye, E₂ <: Eye, F <: AbstractVecOrMat}
e₃, e₂, d = components(K)

g = reshape(f, size(d, 2), size(e₂, 1), size(e₃, 1), :)
r = similar(f, size(d, 1), size(e₂, 1), size(e₃, 1), size(g, 4))
Expand All @@ -73,12 +73,9 @@ function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
return F <: AbstractVector ? vec(r) : reshape(r, size(K, 1), size(f, 2))
end

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{E₃, D, E₁}}, F}) where
{T, L, D <: AbstractMatrix{T}, E₁ <: Eye{T}, E₃ <: Eye{T},
F <: AbstractVecOrMat}
K, f = M.A, M.B
e₃, d, e₁ = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{E₃, D, E₁}}, f::F) where
{D <: AbstractMatrix, E₁ <: Eye, E₃ <: Eye, F <: AbstractVecOrMat}
e₃, d, e₁ = components(K)

g = reshape(f, size(e₁, 1), size(d, 2), size(e₃, 1), :)
r = similar(f, size(e₁, 1), size(d, 1), size(e₃, 1), size(g, 4))
Expand All @@ -88,12 +85,9 @@ function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
return F <: AbstractVector ? vec(r) : reshape(r, size(K, 1), size(f, 2))
end

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{D, E₂, E₁}}, F}) where
{T, L, D <: AbstractMatrix{T}, E₁ <: Eye{T}, E₂ <: Eye{T},
F <: AbstractVecOrMat}
K, f = M.A, M.B
d, e₂, e₁ = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{D, E₂, E₁}}, f::F) where
{D <: AbstractMatrix, E₁ <: Eye, E₂ <: Eye, F <: AbstractVecOrMat}
d, e₂, e₁ = components(K)

g = reshape(f, size(e₁, 1), size(e₂, 1), size(d, 2), :)
r = similar(f, size(e₁, 1), size(e₂, 1), size(d, 1), size(g, 4))
Expand All @@ -103,12 +97,10 @@ function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
return F <: AbstractVector ? vec(r) : reshape(r, size(K, 1), size(f, 2))
end

function Base.copy(M::Mul{LazyArrays.ApplyLayout{typeof(kron)},
L, Kron{T, 2, Tuple{C, B, A}}, F}) where
{T, L, A <: AbstractMatrix{T}, B <: AbstractMatrix{T},
C <: AbstractMatrix{T}, F <: AbstractVecOrMat}
K, f = M.A, M.B
c, b, a = LazyArrays.arguments(K)
function (*)(K::Kron{Tuple{C, B, A}}, f::F) where
{A <: AbstractMatrix, B <: AbstractMatrix,
C <: AbstractMatrix, F <: AbstractVecOrMat}
c, b, a = components(K)

g = reshape(f, size(a, 2), size(b, 2), size(c, 2), :)
r = similar(f, size(a, 1), size(b, 1), size(c, 1), size(g, 4))
Expand Down
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
10 changes: 5 additions & 5 deletions test/kroneckeroperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
(a, Eye{T}(4), Eye{T}(7)),
(a, b, c))

K = adapt(A, collect(Kron(adapt(Array, args)...)))
K = adapt(A, collect(Bennu.Kron(adapt(Array, args))))
d = adapt(A, rand(SVector{2, T}, size(K, 2), 6))
e = adapt(A, rand(SVector{2, T}, size(K, 2)))
@test Array(Kron(args...) * e) ≈ Array(K * e)
@test Array(Kron(args...) * d) ≈ Array(K * d)
@test Array(Bennu.Kron(args) * e) ≈ Array(K * e)
@test Array(Bennu.Kron(args) * d) ≈ Array(K * d)

if isbits(T)
f = rand(rng, T, size(K, 2), 3, 2)
f = adapt(A, reinterpret(reshape, SVector{2, T},
PermutedDimsArray(f, (3, 1, 2))))
@test Array(Kron(args...) * f) ≈ Array(K * f)
@test Array(Bennu.Kron(args) * f) ≈ Array(K * f)
end

@test adapt(Array, Kron(args...)) == Kron(adapt.(Array, args)...)
@test adapt(Array, Bennu.Kron(args)) == Bennu.Kron(adapt.(Array, args))
end
end
end
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ using EzXML: EzXML
using FastGaussQuadrature: FastGaussQuadrature
using FillArrays
using KernelAbstractions
using LazyArrays
using LinearAlgebra
using Random
using SparseArrays
Expand Down