Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement size for Tensor type #2

Merged
merged 1 commit into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ end

# for AbstractArray interface
Base.IndexStyle(::Type{<: Tensor}) = IndexLinear()
Base.size(x::Tensor) = size(serialindices(x))
@generated Base.size(::Type{TT}) where {TT <: Tensor}= :(size($(TensorIndices(TT))))
Base.size(x::Tensor) = size(typeof(x))

# helpers
Base.Tuple(x::Tensor) = x.data
Expand Down
8 changes: 8 additions & 0 deletions test/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,11 @@ end
@test count(==(v), x) == dups[i]
end
end

@testset "Tensor misc" begin
# size
TT = Tensor{Tuple{2, 3}}
@test (@inferred size(TT))::Tuple{Int, Int} == (2,3)
TT = Tensor{Tuple{2, 3, @Symmetry{3, 3}}}
@test (@inferred size(TT))::Tuple{Int, Int, Int, Int} == (2,3,3,3)
end