Commit 55965160 by liyinqiao

Remove dataP in XTensor and use const_cast to modify the const data.

parent 893a0938
......@@ -87,7 +87,6 @@ int MakeTensorID()
XTensor::XTensor()
{
Init();
SetDataPointer();
id = MakeTensorID();
isDefaultDType = true;
......@@ -100,7 +99,6 @@ XTensor::XTensor()
XTensor::XTensor(const XTensor* reference)
{
Init();
SetDataPointer();
id = MakeTensorID();
InitTensorV2(this, reference);
......@@ -117,7 +115,6 @@ XTensor::XTensor(const int myOrder, int myDevID, XMem* myMem)
CheckNTErrors((myOrder >= 0), "Illegal tensor order!");
Init();
SetDataPointer();
id = MakeTensorID();
order = myOrder;
......@@ -138,7 +135,6 @@ XTensor::XTensor(const int myOrder, const int * myDimSize, const TENSOR_DATA_TYP
const float myDenseRatio, int myDevID, XMem * myMem)
{
Init();
SetDataPointer();
id = MakeTensorID();
order = myOrder;
......@@ -153,7 +149,6 @@ XTensor::XTensor(const int myOrder, const int * myDimSize, const TENSOR_DATA_TYP
XTensor::XTensor(const XTensor& reference)
{
Init();
SetDataPointer();
id = MakeTensorID();
ShallowCopy(reference);
data = NULL;
......@@ -164,13 +159,7 @@ XTensor::XTensor(const XTensor& reference)
mem = reference.mem;
data = reference.data;
signature = reference.signature;
/* what we really want to do is "reference.data = NULL;"
As "reference" is constant, we cannot reset "reference.data"
here. So we save the ADDRESS of "reference.data" in
"reference.dataP", and do this work by updating "*reference.dataP".
This is VERY tricky and there might be better solutions :) */
*reference.dataP = NULL;
const_cast<XTensor&>(reference).data = NULL;
}
else{
devID = reference.devID;
......@@ -196,7 +185,6 @@ XTensor::XTensor(const XTensor& reference)
XTensor::XTensor(const XTensor&& reference)
{
Init();
SetDataPointer();
id = MakeTensorID();
ShallowCopy(reference);
data = NULL;
......@@ -206,13 +194,7 @@ XTensor::XTensor(const XTensor&& reference)
mem = reference.mem;
data = reference.data;
signature = reference.signature;
/* what we really want to do is "reference.data = NULL;"
As "reference" is constant, we cannot reset "reference.data"
here. So we save the ADDRESS of "reference.data" in
"reference.dataP", and do this work by updating "*reference.dataP".
This is VERY tricky and there might be better solutions :) */
*reference.dataP = NULL;
const_cast<XTensor&>(reference).data = NULL;
if (reference.enableGrad) {
XLink::Replace(&reference, this);
......@@ -268,7 +250,6 @@ void XTensor::Init()
signature = 0;
data = NULL;
dataHost = NULL;
dataP = NULL;
devID = -1;
order = -1;
memset(dimSize, 0, sizeof(int) * MAX_TENSOR_DIM_NUM);
......@@ -452,13 +433,7 @@ XTensor& XTensor::operator= (const XTensor&& tensor)
mem = tensor.mem;
data = tensor.data;
signature = tensor.signature;
/* what we really want to do is "reference.data = NULL;"
As "reference" is constant, we cannot reset "reference.data"
here. So we save the ADDRESS of "reference.data" in
"reference.dataP", and do this work by updating "*reference.dataP".
This is VERY tricky and there might be better solutions :) */
*tensor.dataP = NULL;
const_cast<XTensor&>(tensor).data = NULL;
if (enableGrad) {
XLink::Copy(&tensor, this);
......@@ -909,12 +884,6 @@ void XTensor::SetDataBatchedWithValues(MTYPE* offsets, void* values, int num)
_SetDataWithOffsetAndValue(this, offsets, values, num);
}
/* set the pointer to "data" */
void XTensor::SetDataPointer()
{
dataP = &data;
}
/*
get the value of a cell with the index
>> index - index of each dimension
......
......@@ -82,10 +82,6 @@ public:
when the tensor is operated on GPUs */
void * dataHost;
/* a pointer to data (i.e., a pointer to the address of "data".
This is for reset "data" when XTensor is used as a const variable. */
void ** dataP;
/*
device id
<0: CPU memory
......@@ -331,9 +327,6 @@ public:
/* set tensor items with an array of values */
void SetDataBatchedWithValues(MTYPE * offsets, void * values, int num);
/* set the pointer to "data" */
void SetDataPointer();
/* get the value of a cell with the index */
DTYPE Get(int index[], int size = -1) const;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论