From 23180b03a96d78068d54def426d4bfb855a4a026 Mon Sep 17 00:00:00 2001 From: Edgar Solomonik Date: Fri, 9 Aug 2019 16:50:11 -0500 Subject: [PATCH] handle std::move for uninitialized tensors --- src/interface/tensor.cxx | 11 +++++++++-- src/tensor/algstrct.cxx | 2 ++ src/tensor/algstrct.h | 4 ++-- src/tensor/untyped_tensor.cxx | 11 ++++++++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/interface/tensor.cxx b/src/interface/tensor.cxx index 032b41ca..d4ce3b42 100644 --- a/src/interface/tensor.cxx +++ b/src/interface/tensor.cxx @@ -1726,8 +1726,15 @@ NORM_INFTY_INST(double) Tensor& Tensor::operator=(Tensor A){ free_self(); - init(A.sr, A.order, A.lens, A.sym, A.wrld, 0, A.name, A.profile, A.is_sparse); - copy_tensor_data(&A); + if (A.order < 0){ + this->order = A.order; + if (A.order == -1){ + this->sr = A.sr->clone(); + } + } else { + init(A.sr, A.order, A.lens, A.sym, A.wrld, 0, A.name, A.profile, A.is_sparse); + copy_tensor_data(&A); + } return *this; /* sr = A.sr; diff --git a/src/tensor/algstrct.cxx b/src/tensor/algstrct.cxx index 601b5547..106a1e9e 100644 --- a/src/tensor/algstrct.cxx +++ b/src/tensor/algstrct.cxx @@ -66,6 +66,8 @@ namespace CTF_int { }; + algstrct::~algstrct(){ } + algstrct::algstrct(int el_size_){ el_size = el_size_; has_coo_ker = false; diff --git a/src/tensor/algstrct.h b/src/tensor/algstrct.h index d422f3ed..2b884a9e 100644 --- a/src/tensor/algstrct.h +++ b/src/tensor/algstrct.h @@ -66,7 +66,7 @@ namespace CTF_int { /** * \brief destructor */ - virtual ~algstrct() = 0; + virtual ~algstrct(); /** * \brief ''copy constructor'' @@ -447,7 +447,7 @@ namespace CTF_int { }; //http://stackoverflow.com/questions/630950/pure-virtual-destructor-in-c - inline algstrct::~algstrct(){} + //inline algstrct::~algstrct(){} /** * \brief depins keys of n pairs diff --git a/src/tensor/untyped_tensor.cxx b/src/tensor/untyped_tensor.cxx index ab8a2de2..e8673de2 100644 --- a/src/tensor/untyped_tensor.cxx +++ b/src/tensor/untyped_tensor.cxx @@ -73,8 +73,10 @@ namespace CTF_int { delete sr; cdealloc(name); } - if (order == -1) + if (order == -1){ delete sr; + order = -2; + } } tensor::~tensor(){ @@ -172,6 +174,13 @@ namespace CTF_int { } tensor::tensor(tensor const * other, bool copy, bool alloc_data){ + if (other->order < 0){ + this->order = other->order; + if (other->order == -1){ + this->sr = other->sr->clone(); + } + return; + } char * nname = (char*)alloc(strlen(other->name) + 2); char d[] = "\'"; strcpy(nname, other->name);