Skip to content

Commit c4dd694

Browse files
committed
minor optimization, promote number to Vector instead of Matrix
1 parent 37f4b87 commit c4dd694

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

stdlib/LinearAlgebra/src/uniformscaling.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ end
292292
# in A to matrices of type T and sizes given by n[k:end]. n is an array
293293
# so that the same promotion code can be used for hvcat. We pass the type T
294294
# so that we can re-use this code for sparse-matrix hcat etcetera.
295-
promote_to_arrays_(n::Int, ::Type{Matrix}, a::T) where {T<:Number} = copyto!(Matrix{T}(undef, 1, 1), a)
295+
promote_to_arrays_(n::Int, ::Type, a::T) where {T<:Number} = copyto!(Vector{T}(undef, 1), a)
296296
promote_to_arrays_(n::Int, ::Type{Matrix}, J::UniformScaling{T}) where {T} = copyto!(Matrix{T}(undef, n, n), J)
297297
promote_to_arrays_(n::Int, ::Type, A::AbstractVecOrMat) = A
298298
promote_to_arrays(n,k, ::Type) = ()
@@ -369,16 +369,16 @@ function hvcat(rows::Tuple{Vararg{Int}}, A::Union{AbstractVecOrMat,UniformScalin
369369
j = 0
370370
for i = 1:nr
371371
if rows[i] > 0 && n[j+1] == -1 # this row consists entirely of UniformScalings
372-
nci = nc ÷ rows[i]
373-
nci * rows[i] != nc && throw(DimensionMismatch("indivisible UniformScaling sizes"))
372+
nci, r = divrem(nc, rows[i])
373+
r != 0 && throw(DimensionMismatch("indivisible UniformScaling sizes"))
374374
for k = 1:rows[i]
375375
n[j+k] = nci
376376
end
377377
end
378378
j += rows[i]
379379
end
380380
end
381-
return hvcat(rows, promote_to_arrays(n,1, promote_to_array_type(A), A...)...)
381+
return hvcat(rows, promote_to_arrays(n, 1, promote_to_array_type(A), A...)...)
382382
end
383383

384384
## Matrix construction from UniformScaling

0 commit comments

Comments
 (0)