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

[NDTensors] Fix issue in Tensor constructor when storage involves wrapper types #1441

Merged
merged 7 commits into from
May 15, 2024
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
4 changes: 4 additions & 0 deletions NDTensors/src/tensor/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ function Tensor(as::AliasStyle, storage::TensorStorage, inds::Tuple)
)
end

function Tensor(as::NeverAlias, storage::TensorStorage, inds::Tuple)
return Tensor(AllowAlias(), copy(storage), inds)
end

# Automatically convert to Tuple if the indices are not a Tuple
# already (like a Vector). In the future this may be lifted
# to allow for very large tensor orders in which case Tuple
Expand Down
5 changes: 5 additions & 0 deletions NDTensors/test/test_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ NDTensors.dim(i::MyInd) = i.dim

Aview = A[2:3, 2:3]
@test dims(Aview) == (2, 2)
## Added for issue 1431 create a tensor from
## a sliced view of another tensor
Acopy = Tensor(NDTensors.storage(Aview), (1, 4))
@test NDTensors.cpu(data(Acopy)) == NDTensors.cpu(data(Aview))
@test dims(Acopy) == (1, 4)

B = dev(Tensor(elt, undef, (3, 4)))
randn!(B)
Expand Down
Loading