Commit 8fc25f38 by liyinqiao

Add Range function for XTensor.

parent 1d5cd56f
......@@ -2114,6 +2114,36 @@ void XTensor::FreeData(XTensor * tensor, XMem * myMem, bool useBuf)
tensor->isInGlobalMem = false;
}
/* set the tensor with an data array
>> tensor - XTensor. it must be on CPU
>> start - the begin of the array
>> end - the end of the array (not included self)
>> step - the step of two items
*/
void XTensor::Range(XTensor * tensor, int start, int end, int step)
{
if (tensor == NULL)
return;
/* get the length of tensor */
int length = tensor->GetDim(0);
/* compute the true length according to the (start, end, step) */
int a = abs(end - start);
int freq = ceil(1.0 * a / abs(step));
/* init a integer array to store the sequence */
int* index = new int[freq];
for (int i = 0; i < freq; i++)
index[i] = start + i * step;
CheckNTErrors((length == freq), "the length of the tensor is not matched");
/* set the data from the array */
tensor->SetData(index, freq);
delete[] index;
}
/*************************************************
* we define the "new and delete" functions below
*/
......
......@@ -443,6 +443,10 @@ public:
/* free the memory space of the matrix (in the global memory) */
static
void FreeData(XTensor * matrix, XMem * myMem = NULL, bool useBuf = false);
/* generate the range tensor by start, end and the step */
static
void Range(XTensor * tensor, int start, int end, int step);
};
/* we make a unique id for every tensor */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论