Objects like NSL::map default construct a NSL::Tensor in order to assign them at a later point (see e.g. NSL::Lattice::SpatialLattice::exp_hopping_matrix_). The way default construction worked before prevented later assignment using the NSL::Tensor::operator= as the shape of the target tensor naturally doesn't match the shape of the source tensor.
In this PR a fix for this issue is provided. In order to do this the default construction is now updated to default constructing the underlying torch::Tensor. A default constructed torch::Tensor counts as "not defined", i.e. torch::Tensor::defined returns false. Leveraging this behavior the method operator= can check for defined-ness. If the torch::Tensor is already defined, the behavior remains unchanged if it is undefined, i.e. default constructed, a new memory space is created and the source Tensor is copied in it. The latter is not asynchronous!
Objects like
NSL::map
default construct aNSL::Tensor
in order to assign them at a later point (see e.g.NSL::Lattice::SpatialLattice::exp_hopping_matrix_
). The way default construction worked before prevented later assignment using theNSL::Tensor::operator=
as the shape of the target tensor naturally doesn't match the shape of the source tensor. In this PR a fix for this issue is provided. In order to do this the default construction is now updated to default constructing the underlyingtorch::Tensor
. A default constructedtorch::Tensor
counts as "not defined", i.e.torch::Tensor::defined
returns false. Leveraging this behavior the methodoperator=
can check for defined-ness. If thetorch::Tensor
is already defined, the behavior remains unchanged if it is undefined, i.e. default constructed, a new memory space is created and the source Tensor is copied in it. The latter is not asynchronous!