Skip to content
Draft
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
25 changes: 25 additions & 0 deletions lib/JLArrays/src/JLArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,31 @@ function Base.unsafe_convert(::Type{Ptr{T}}, x::JLArray{T}) where {T}
error("Illegal conversion of a JLArray to a Ptr")
end

"""
lu(A::JLArray, args...; kwargs...)

Compute an LU factorization using the host representation of `A`.
"""
function LinearAlgebra.lu(A::JLArray{T, 2}, args...; kwargs...) where {T}
return LinearAlgebra.lu(Array(A), args...; kwargs...)
end

function LinearAlgebra.ldiv!(
F::LinearAlgebra.LU{T, <:StridedMatrix{T}}, B::JLArray{T, N}
) where {T <: LinearAlgebra.BlasFloat, N}
B_cpu = Array(B)
LinearAlgebra.ldiv!(F, B_cpu)
copyto!(B, B_cpu)
return B
end

function LinearAlgebra.ldiv!(Y::JLArray, F::LinearAlgebra.LU, B::JLArray)
B_cpu = Array(B)
LinearAlgebra.ldiv!(F, B_cpu)
copyto!(Y, B_cpu)
return Y
end


## interop with Julia arrays

Expand Down
16 changes: 16 additions & 0 deletions test/jlarrays_lu.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Test, JLArrays, LinearAlgebra

@testset "JLArray LU" begin
A = jl([2.0 1.0; 1.0 3.0])
F = lu(A; check = false)

@test F isa LU{Float64, Matrix{Float64}, Vector{Int}}

b = jl([1.0, 2.0])
ldiv!(F, b)
@test Array(b) ≈ [0.2, 0.6]

y = similar(b)
ldiv!(y, F, jl([1.0, 2.0]))
@test Array(y) ≈ [0.2, 0.6]
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using ParallelTestRunner: runtests, parse_args
import GPUArrays

include("jlarrays_lu.jl")

include("testsuite.jl")

const init_worker_code = quote
Expand Down
Loading