Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make lu results have same storage mode as input #435

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions lib/mps/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ LinearAlgebra.ipiv2perm(v::MtlVector{T}, maxi::Integer) where T =
dev = device()
queue = global_queue(dev)

At = MtlMatrix{T,PrivateStorage}(undef, (N, M))
At = similar(A, (N, M))
mps_a = MPSMatrix(A)
mps_at = MPSMatrix(At)

Expand All @@ -137,7 +137,7 @@ LinearAlgebra.ipiv2perm(v::MtlVector{T}, maxi::Integer) where T =
encode!(cbuf, kernel, mps_at, mps_at, mps_p, status)
end

B = MtlMatrix{T}(undef, M, N)
B = similar(A, M, N)

commit!(cmdbuf) do cbuf
mps_b = MPSMatrix(B)
Expand Down Expand Up @@ -176,7 +176,7 @@ end
dev = device()
queue = global_queue(dev)

At = MtlMatrix{T,PrivateStorage}(undef, (N, M))
christiangnrd marked this conversation as resolved.
Show resolved Hide resolved
At = similar(A, (N, M))
mps_a = MPSMatrix(A)
mps_at = MPSMatrix(At)

Expand Down
7 changes: 7 additions & 0 deletions test/mps/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,29 @@ end
end

@testset "decompositions" begin
testreturntype(_,_) = false
testreturntype(luobj::LU{<:Any,<:MtlArray{<:Any,<:Any,S},<:MtlArray{<:Any,<:Any,S}},::MtlArray{<:Any,<:Any,S}) where S = true

christiangnrd marked this conversation as resolved.
Show resolved Hide resolved
A = MtlMatrix(rand(Float32, 1024, 1024))
lua = lu(A)
@test testreturntype(lua,A)
@test lua.L * lua.U ≈ MtlMatrix(lua.P) * A

A = MtlMatrix(rand(Float32, 1024, 512))
lua = lu(A)
@test testreturntype(lua,A)
@test lua.L * lua.U ≈ MtlMatrix(lua.P) * A

A = MtlMatrix(rand(Float32, 512, 1024))
lua = lu(A)
@test testreturntype(lua,A)
@test lua.L * lua.U ≈ MtlMatrix(lua.P) * A

a = rand(Float32, 1024, 1024)
A = MtlMatrix(a)
B = MtlMatrix(a)
lua = lu!(A)
@test testreturntype(lua,A)
@test lua.L * lua.U ≈ MtlMatrix(lua.P) * B

A = MtlMatrix{Float32}([1 2; 0 0])
Expand Down