Skip to content

Commit b213678

Browse files
authored
[ITensors] Extension implementing VectorInterface.jl for ITensors (#1373)
1 parent 7fd169f commit b213678

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@eval module $(gensym())
2+
using NDTensors.NamedDimsArrays: NamedDimsArray, dimnames
3+
using NDTensors: NDTensors
4+
using Test: @test, @testset
5+
6+
@testset "NDTensorsNamedDimsArraysExt" begin
7+
elt = Float64
8+
9+
a = NamedDimsArray(randn(elt, 2, 2), ("i", "j"))
10+
b = NDTensors.similar(a)
11+
@test b isa NamedDimsArray{elt}
12+
@test eltype(b) === elt
13+
@test dimnames(b) == ("i", "j")
14+
@test size(b) == (2, 2)
15+
16+
a = NamedDimsArray(randn(elt, 2, 2), ("i", "j"))
17+
b = NDTensors.similar(a, Float32)
18+
@test b isa NamedDimsArray{Float32}
19+
@test eltype(b) === Float32
20+
@test dimnames(b) == ("i", "j")
21+
@test size(b) == (2, 2)
22+
23+
a = NamedDimsArray(randn(elt, 2, 2), ("i", "j"))
24+
b = copy(a)
25+
α = randn(elt)
26+
b = NDTensors.fill!!(b, α)
27+
@test b isa NamedDimsArray{elt}
28+
@test eltype(b) === elt
29+
@test dimnames(b) == ("i", "j")
30+
@test size(b) == (2, 2)
31+
@test all(==(α), b)
32+
end
33+
end

0 commit comments

Comments
 (0)