Commit 06053721 by xiaotong

c++ 11 by default

parent e184cac4
......@@ -266,10 +266,6 @@ XDevManager::XDevManager()
{
Clear();
Init();
#ifndef USE_CPP11
fprintf(stderr, "Warning!!! c++ 11 is RECOMMENDED for compilation.\n");
#endif
}
/* de-constructor */
......
......@@ -43,13 +43,9 @@
/* the nts (NiuTrans.Tensor) namespace */
namespace nts {
#if (__cplusplus >= 201103L || _MSC_VER >= 1700)
#define USE_CPP11
#endif
#define _XINLINE_
//#define DOUBELPRICSION
//#define DOUBELPRICSION
#ifdef DOUBELPRICSION
#define DTYPE double
......
......@@ -171,7 +171,7 @@ XTensor::XTensor(const XTensor &reference)
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 trick and might not be the best solution :) */
This is VERY tricky and might not be the best solution :) */
*reference.dataP = NULL;
}
else{
......@@ -193,7 +193,6 @@ XTensor::XTensor(const XTensor &reference)
}
/* copy constructor (with right value reference) */
#ifdef USE_CPP11
XTensor::XTensor(const XTensor &&reference)
{
Init();
......@@ -212,7 +211,7 @@ XTensor::XTensor(const XTensor &&reference)
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 trick and might not be the best solution :) */
This is VERY tricky and might not be the best solution :) */
*reference.dataP = NULL;
XLink::Replace(&reference, this);
......@@ -220,7 +219,6 @@ XTensor::XTensor(const XTensor &&reference)
isInit = true;
isTmp = reference.isTmp;
}
#endif
/* de-constructor */
XTensor::~XTensor()
......@@ -445,7 +443,7 @@ XTensor& XTensor::operator= (const XTensor&& tensor)
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 trick and might not be the best solution :) */
This is VERY tricky and might not be the best solution :) */
*tensor.dataP = NULL;
XLink::Replace(&tensor, this);
......@@ -520,6 +518,7 @@ void XTensor::SetDevice(int myDevId, XMem * myMem)
{
if (myMem != NULL) {
FlushToMem(myMem);
isInGlobalMem = false;
}
else {
ShowNTErrors("TODO!");
......@@ -1295,6 +1294,21 @@ bool XTensor::Set(DTYPE value, int index[], int size)
}
/*
set the value of a cell with its offset in the array
>> value - the value we intend to set
>> offset - the offset in the array
*/
bool XTensor::Set(DTYPE value, int offset)
{
CheckNTErrors(offset >= 0 && offset < unitNum, "Invalid index!");
CheckNTErrors(data != NULL, "Cannot use an uninitialized tensor!");
DTYPE * d = (DTYPE*)data + offset;
return SetToDevice(devID, d, value);
}
/*
set the value of a cell in a 1d tensor
>> value - value we tend to set
>> i - item offset
......
......@@ -194,9 +194,7 @@ public:
XTensor(const XTensor &reference);
/* copy constructor (with right value reference) */
#ifdef USE_CPP11
XTensor(const XTensor &&reference);
#endif
/* de-constructor */
~XTensor();
......@@ -217,9 +215,7 @@ public:
XTensor& operator= (const XTensor &tensor);
/* overloading of the equal-sign (with right value reference) */
#ifdef USE_CPP11
XTensor& operator= (const XTensor &&tensor);
#endif
/* overloading of the plus-sign */
XTensor operator+ (const XTensor &tensor) const;
......@@ -361,6 +357,9 @@ public:
/* set the value of a cell */
bool Set(DTYPE value, int index[], int size = -1);
/* set the value of a cell with its offset in the array */
bool Set(DTYPE value, int offset);
/* set the value of a cell in a 1d tensor */
bool Set1D(DTYPE value, int i);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论