Skip to content

Conversation

@kshyatt
Copy link
Member

@kshyatt kshyatt commented Nov 19, 2025

Pull over the logic from CUDA.jl so that we can use it on AMD and other backends.

@kshyatt kshyatt requested a review from maleadt November 19, 2025 11:32
@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic master) to apply these changes.

Click here to view the suggested changes.
diff --git a/src/host/linalg.jl b/src/host/linalg.jl
index 0cc40bf..f81460a 100644
--- a/src/host/linalg.jl
+++ b/src/host/linalg.jl
@@ -64,12 +64,12 @@ end
 
 ## diagm
 
-LinearAlgebra.diagm(kv::Pair{<:Integer,<:AbstractGPUVector}...) = _gpu_diagm(nothing, kv...)
-LinearAlgebra.diagm(m::Integer, n::Integer, kv::Pair{<:Integer,<:AbstractGPUVector}...) = _gpu_diagm((Int(m),Int(n)), kv...)
+LinearAlgebra.diagm(kv::Pair{<:Integer, <:AbstractGPUVector}...) = _gpu_diagm(nothing, kv...)
+LinearAlgebra.diagm(m::Integer, n::Integer, kv::Pair{<:Integer, <:AbstractGPUVector}...) = _gpu_diagm((Int(m), Int(n)), kv...)
 LinearAlgebra.diagm(v::AbstractGPUVector) = LinearAlgebra.diagm(0 => v)
 LinearAlgebra.diagm(m::Integer, n::Integer, v::AbstractGPUVector) = LinearAlgebra.diagm(m, n, 0 => v)
 
-function _gpu_diagm(size, kv::Pair{<:Integer,<:AbstractGPUVector}...)
+function _gpu_diagm(size, kv::Pair{<:Integer, <:AbstractGPUVector}...)
     A = LinearAlgebra.diagm_container(size, kv...)
     for p in kv
         inds = LinearAlgebra.diagind(A, p.first)
@@ -78,7 +78,7 @@ function _gpu_diagm(size, kv::Pair{<:Integer,<:AbstractGPUVector}...)
     return A
 end
 
-function LinearAlgebra.diagm_container(size, kv::Pair{<:Integer,<:AbstractGPUVector}...)
+function LinearAlgebra.diagm_container(size, kv::Pair{<:Integer, <:AbstractGPUVector}...)
     T = promote_type(map(x -> eltype(x.second), kv)...)
     U = promote_type(T, typeof(zero(T)))
     A = similar(kv[1].second, U, LinearAlgebra.diagm_size(size, kv...)...)
@@ -86,13 +86,13 @@ function LinearAlgebra.diagm_container(size, kv::Pair{<:Integer,<:AbstractGPUVec
     return A
 end
 
-function LinearAlgebra.diagm_size(size::Nothing, kv::Pair{<:Integer,<:AbstractGPUVector}...)
-    mnmax = mapreduce(x -> length(x.second) + abs(Int(x.first)), max, kv; init=0)
+function LinearAlgebra.diagm_size(size::Nothing, kv::Pair{<:Integer, <:AbstractGPUVector}...)
+    mnmax = mapreduce(x -> length(x.second) + abs(Int(x.first)), max, kv; init = 0)
     return mnmax, mnmax
 end
-function LinearAlgebra.diagm_size(size::Tuple{Int,Int}, kv::Pair{<:Integer,<:AbstractGPUVector}...)
-    mmax = mapreduce(x -> length(x.second) - min(0,Int(x.first)), max, kv; init=0)
-    nmax = mapreduce(x -> length(x.second) + max(0,Int(x.first)), max, kv; init=0)
+function LinearAlgebra.diagm_size(size::Tuple{Int, Int}, kv::Pair{<:Integer, <:AbstractGPUVector}...)
+    mmax = mapreduce(x -> length(x.second) - min(0, Int(x.first)), max, kv; init = 0)
+    nmax = mapreduce(x -> length(x.second) + max(0, Int(x.first)), max, kv; init = 0)
     m, n = size
     (m ≥ mmax && n ≥ nmax) || throw(DimensionMismatch(lazy"invalid size=$size"))
     return m, n

@kshyatt kshyatt merged commit d76ea88 into master Nov 19, 2025
18 of 19 checks passed
@kshyatt kshyatt deleted the ksh/diagm branch November 19, 2025 13:07
maleadt referenced this pull request Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants