It would be helpful to have generic functions setstorage and setinds that create a copy of a tensor with the specified storage or indices. For example, right now complex(::Tensor) is defined as:
Also a note that I would like to deprecate store(T) in favor of storage(T).
A similar generic code pattern would be to add setdata for storage types. This could help with making generic code across different storage types. For example right now there is a generic complex defined for all storage types:
Base.complex(S::T) where {T <: TensorStorage} = complex(T)(complex(data(S)))
but also more specialized versions for sparse storage types:
complex(D::BlockSparse{T}) where {T} =
BlockSparse{complex(T)}(complex(data(D)), blockoffsets(D))
Many functions like this only act on the data part of the storage and not the block offset list, so could be replaced by a single generic version:
Base.complex(S::T) where {T <: TensorStorage} = setdata(T, complex(data(S)))
where the generic function setdata would have to be defined for each storage type.
It would be helpful to have generic functions
setstorage
andsetinds
that create a copy of a tensor with the specified storage or indices. For example, right nowcomplex(::Tensor)
is defined as:which could be replaced by:
Also a note that I would like to deprecate
store(T)
in favor ofstorage(T)
.A similar generic code pattern would be to add
setdata
for storage types. This could help with making generic code across different storage types. For example right now there is a genericcomplex
defined for all storage types:but also more specialized versions for sparse storage types:
Many functions like this only act on the
data
part of the storage and not the block offset list, so could be replaced by a single generic version:where the generic function
setdata
would have to be defined for each storage type.