Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TensorProducts"
uuid = "decf83d6-1968-43f4-96dc-fdb3fe15fc6d"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.3"
version = "0.1.4"

[weakdeps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Expand Down
10 changes: 10 additions & 0 deletions src/onetoone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@
OneToOne() = OneToOne{Int}()
Base.first(a::OneToOne) = one(eltype(a))
Base.last(a::OneToOne) = one(eltype(a))

Base.to_shape(::OneToOne) = 1

Check warning on line 9 in src/onetoone.jl

View check run for this annotation

Codecov / codecov/patch

src/onetoone.jl#L9

Added line #L9 was not covered by tests

# extend Base.OneTo behavior to OneToOne
function Base.reshape(

Check warning on line 12 in src/onetoone.jl

View check run for this annotation

Codecov / codecov/patch

src/onetoone.jl#L12

Added line #L12 was not covered by tests
parent::AbstractArray,
shp::Tuple{Union{Integer,Base.OneTo,OneToOne},Vararg{Union{Integer,Base.OneTo,OneToOne}}},
)
return reshape(parent, Base.to_shape(shp))

Check warning on line 16 in src/onetoone.jl

View check run for this annotation

Codecov / codecov/patch

src/onetoone.jl#L16

Added line #L16 was not covered by tests
end
4 changes: 4 additions & 0 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ using TensorProducts: OneToOne
@test length(a0) == 1

@test blockaxes(OneToOne()) == (BlockRange(OneToOne()),)

@test reshape(ones(()), (OneToOne(),)) == ones((1,))
@test reshape(ones(()), (OneToOne(), Base.OneTo(1), 1)) == ones((1, 1, 1))
@test reshape(ones(()), OneToOne(), Base.OneTo(1), 1) == ones((1, 1, 1))
end
Loading