diff --git a/NDTensors/src/tensor/tensor.jl b/NDTensors/src/tensor/tensor.jl index 351e86d9c6..4dfa483030 100644 --- a/NDTensors/src/tensor/tensor.jl +++ b/NDTensors/src/tensor/tensor.jl @@ -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 diff --git a/NDTensors/test/test_dense.jl b/NDTensors/test/test_dense.jl index 382661c140..78368d2841 100644 --- a/NDTensors/test/test_dense.jl +++ b/NDTensors/test/test_dense.jl @@ -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)