Skip to content

Commit 21aac12

Browse files
authored
Add Base.keys(::MatElem) (Nemocas#1906)
* Add `Base.keys(::MatElem)` * Bump version to 0.43.11 * Add test
1 parent 25a7ea8 commit 21aac12

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AbstractAlgebra"
22
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
3-
version = "0.43.10"
3+
version = "0.43.11"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/Matrix.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ end
567567

568568
Base.IteratorSize(::Type{<:MatrixElem}) = Base.HasShape{2}()
569569

570+
Base.keys(M::MatElem) = CartesianIndices(axes(M))
570571
Base.pairs(M::MatElem) = Base.pairs(IndexCartesian(), M)
571572
Base.pairs(::IndexCartesian, M::MatElem) = Base.Iterators.Pairs(M, CartesianIndices(axes(M)))
572573

test/Matrix-test.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ end
132132
@test Matrix(Sa) == a
133133
end
134134

135+
@testset "Matrix.keys and pairs" begin
136+
a = matrix(ZZ, 2, 3, [6, 3, 0, 10, 12, 14])
137+
@test keys(a) == CartesianIndices((2, 3))
138+
@test issetequal(
139+
keys(a),
140+
[CartesianIndex(1, 1), CartesianIndex(1, 2), CartesianIndex(1, 3),
141+
CartesianIndex(2, 1), CartesianIndex(2, 2), CartesianIndex(2, 3)],
142+
)
143+
@test issetequal(
144+
pairs(a),
145+
[CartesianIndex(1, 1) => 6, CartesianIndex(1, 2) => 3, CartesianIndex(1, 3) => 0,
146+
CartesianIndex(2, 1) => 10, CartesianIndex(2, 2) => 12, CartesianIndex(2, 3) => 14],
147+
)
148+
end
149+
135150
@testset "Strassen" begin
136151
S = matrix(QQ, rand(-10:10, 100, 100))
137152
T = S*S

0 commit comments

Comments
 (0)