Commit f1e69d00 by xiaotong

copy constructor

parent 561a9e58
...@@ -197,8 +197,7 @@ XTensor::XTensor(const XTensor &reference) ...@@ -197,8 +197,7 @@ XTensor::XTensor(const XTensor &reference)
SetDataPointer(); SetDataPointer();
id = MakeTensorID(); id = MakeTensorID();
ShallowCopy(reference); ShallowCopy(reference);
isInit = false; data = NULL;
isTmp = false;
dataHost = NULL; dataHost = NULL;
if(reference.isTmp){ if(reference.isTmp){
...@@ -214,15 +213,14 @@ XTensor::XTensor(const XTensor &reference) ...@@ -214,15 +213,14 @@ XTensor::XTensor(const XTensor &reference)
*reference.dataP = NULL; *reference.dataP = NULL;
} }
else{ else{
DestroyData(); devID = reference.devID;
if(isInit){ mem = reference.mem;
devID = reference.devID;
mem = reference.mem;
}
InitTensor(this, &reference); InitTensor(this, &reference);
CopyValues(&reference, this); CopyValues(&reference, this);
} }
isInit = false;
isTmp = false;
} }
/* de-constructor */ /* de-constructor */
...@@ -985,7 +983,7 @@ increase the value of a cell in a 2d tensor ...@@ -985,7 +983,7 @@ increase the value of a cell in a 2d tensor
} }
/* get the number of non-zero elements (in a sparse tensor) */ /* get the number of non-zero elements (in a sparse tensor) */
const int XTensor::GetNonzeroSize() int XTensor::GetNonzeroSize()
{ {
if(!isSparse){ if(!isSparse){
XPRINT(1, stderr, "WARNING! Counting non-zero elements in a dense tensor might be slow!\n"); XPRINT(1, stderr, "WARNING! Counting non-zero elements in a dense tensor might be slow!\n");
......
...@@ -55,10 +55,8 @@ struct XLink; ...@@ -55,10 +55,8 @@ struct XLink;
#define UNSAFE_BUT_FAST_MEM #define UNSAFE_BUT_FAST_MEM
#define FAST_MATRIX #define FAST_MATRIX
/* /* XTensor is a class to do everything a tensor can do :) */
We implemente the tensor class here. struct XTensor
*/
class XTensor
{ {
public: public:
/* id */ /* id */
...@@ -282,7 +280,7 @@ public: ...@@ -282,7 +280,7 @@ public:
bool Add2D(DTYPE value, int ni, int mi); bool Add2D(DTYPE value, int ni, int mi);
/* get the number of non-zero elements (in a sparse tensor) */ /* get the number of non-zero elements (in a sparse tensor) */
const int GetNonzeroSize(); int GetNonzeroSize();
/* set the tensor as "temporary" */ /* set the tensor as "temporary" */
void SetTMP(bool myIsTmp = true); void SetTMP(bool myIsTmp = true);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论