Skip to content

Commit 15ce5ef

Browse files
KlausCStefanKarpinski
authored andcommitted
oneunit of unitfull matrix should return a unitfull matrix (#30227)
1 parent a26031e commit 15ce5ef

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

base/array.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ function _one(unit::T, x::AbstractMatrix) where T
460460
# Matrix{T}(I, m, m)
461461
I = zeros(T, m, m)
462462
for i in 1:m
463-
I[i,i] = 1
463+
I[i,i] = unit
464464
end
465465
I
466466
end

stdlib/SparseArrays/test/sparse.jl

-1
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,6 @@ end
23352335
@test m2.module == SparseArrays
23362336
end
23372337

2338-
23392338
@testset "sprandn with type $T" for T in (Float64, Float32, Float16, ComplexF64, ComplexF32, ComplexF16)
23402339
@test sprandn(T, 5, 5, 0.5) isa AbstractSparseMatrix{T}
23412340
end

test/arrayops.jl

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using .Main.OffsetArrays
66
using SparseArrays
77

88
using Random, LinearAlgebra
9+
using Dates
910

1011
@testset "basics" begin
1112
@test length([1, 2, 3]) == 3
@@ -2577,3 +2578,7 @@ Base.view(::T25958, args...) = args
25772578
@test t[end,end,1] == @view(t[end,end,1]) == @views t[end,end,1]
25782579
@test t[end,end,end] == @view(t[end,end,end]) == @views t[end,end,end]
25792580
end
2581+
2582+
# Fix oneunit bug for unitful arrays
2583+
@test oneunit([Second(1) Second(2); Second(3) Second(4)]) == [Second(1) Second(0); Second(0) Second(1)]
2584+

0 commit comments

Comments
 (0)