Skip to content

Commit 94c1c8c

Browse files
authored
Fix replace for NaiveOrderedSet (#28)
1 parent a2a98ad commit 94c1c8c

File tree

7 files changed

+27
-1
lines changed

7 files changed

+27
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NamedDimsArrays"
22
uuid = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.3.11"
4+
version = "0.3.12"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/abstractnameddimsarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ end
207207
function Base.map(f::Function, s::NaiveOrderedSet)
208208
return NaiveOrderedSet(map(f, values(s)))
209209
end
210+
function Base.replace(f::Union{Function,Type}, s::NaiveOrderedSet; kwargs...)
211+
return NaiveOrderedSet(replace(f, values(s); kwargs...))
212+
end
213+
function Base.replace(s::NaiveOrderedSet, replacements::Pair...; kwargs...)
214+
return NaiveOrderedSet(replace(values(s), replacements...; kwargs...))
215+
end
210216

211217
function Base.axes(a::AbstractNamedDimsArray)
212218
return NaiveOrderedSet(map(named, axes(dename(a)), nameddimsindices(a)))
File renamed without changes.

test/basics/test_basics.jl renamed to test/test_basics.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using NamedDimsArrays:
33
NamedDimsArrays,
44
AbstractNamedDimsArray,
55
AbstractNamedDimsMatrix,
6+
NaiveOrderedSet,
67
Name,
78
NameMismatch,
89
NamedDimsCartesianIndex,
@@ -271,4 +272,23 @@ using Test: @test, @test_throws, @testset
271272
@test !iszero(na)
272273
end
273274
end
275+
@testset "NaiveOrderedSet" begin
276+
s = NaiveOrderedSet(("a", "b", "c"))
277+
@test values(s) == ("a", "b", "c")
278+
@test Tuple(s) == ("a", "b", "c")
279+
@test s[1] == "a"
280+
@test s[2] == "b"
281+
@test s[3] == "c"
282+
for s′ in (
283+
replace(x -> x == "b" ? "x" : x, s),
284+
replace(s, "b" => "x"),
285+
map(x -> x == "b" ? "x" : x, s),
286+
)
287+
@test s′ isa NaiveOrderedSet
288+
@test Tuple(s′) == ("a", "x", "c")
289+
@test s′[1] == "a"
290+
@test s′[2] == "x"
291+
@test s′[3] == "c"
292+
end
293+
end
274294
end
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)