Skip to content

Commit 4b3757c

Browse files
authored
Merge pull request #179 from ValeevGroup/evaleev/fix/tensor-converting-ctor-optimized-for-forward-iterables
optimize `Tensor(Boxtensor)` converting ctor ...
2 parents af41dd9 + 9bac603 commit 4b3757c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

btas/tensor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ namespace btas {
201201
/// copy constructor
202202
/// It will accept Tensors and TensorViews
203203
template <class _Tensor, class = typename std::enable_if<is_boxtensor<_Tensor>::value>::type>
204-
Tensor(const _Tensor& x) : range_(x.range().lobound(), x.range().upbound()), storage_(x.cbegin(), x.cend()) {}
204+
Tensor(const _Tensor& x) : range_(x.range().lobound(), x.range().upbound()){
205+
auto size = range_.area();
206+
array_adaptor<storage_type>::resize(storage_, size);
207+
std::copy(x.cbegin(), x.cend(), storage_.begin());
208+
}
205209

206210
/// copy constructor
207211
/// @note this makes a shallow copy of @п х if `storage_type` has shallow-copy semantics; if need a deep copy

0 commit comments

Comments
 (0)