Commit 9ac1028a by xiaotong

better check of input

parent 11ef8164
......@@ -35,16 +35,19 @@ copy s to t
*/
void _CopyValues(const XTensor * s, XTensor * t, XStream * stream)
{
CheckNTErrors((s != NULL && t != NULL), "The input tensor and output tensor must be nonempty!");
CheckNTErrors((s->data != NULL), "Cannot copy an empty data array!");
CheckNTErrors((t->data != NULL), "Cannot copy to an empty data array!");
CheckNTErrors((s->unitNum == t->unitNum), "Unmatched data item number!");
if(s->data == NULL && t->data == NULL)
return;
CheckNTErrors(s != NULL && t != NULL, "The input tensor and output tensor must be nonempty!");
CheckNTErrors(s->data != NULL, "Cannot copy an empty data array!");
CheckNTErrors(t->data != NULL, "Cannot copy to an empty data array!");
CheckNTErrors(s->unitNum == t->unitNum, "Unmatched data item number!");
if ((s->dataType == X_FLOAT16 && t->dataType == X_FLOAT) ||
(s->dataType == X_FLOAT && t->dataType == X_FLOAT16)) {
CheckNTErrors(((s->devID < 0 && t->devID < 0) || s->devID == t->devID),
CheckNTErrors((s->devID < 0 && t->devID < 0) || s->devID == t->devID,
"The code must be run on the same device!");
CheckNTErrors((s->isSparse || t->isSparse), "TODO!");
CheckNTErrors(s->isSparse || t->isSparse, "TODO!");
ConvertDataType(s->devID, s->data, s->dataType, t->data, t->dataType, s->unitNum);
}
......@@ -81,8 +84,12 @@ copy s to t
*/
void _CopyValues(const XTensor * s, const int sBeg, const int sLen, XTensor * t, const int tBeg, XStream * stream)
{
if(s->data == NULL && t->data == NULL)
return;
CheckNTErrors(s != NULL && t != NULL, "The input tensor and output tensor must be nonempty!");
CheckNTErrors(s->data != NULL && t->data != NULL, "Cannot copy an empty data array!");
CheckNTErrors(s->data != NULL, "Cannot copy an empty data array!");
CheckNTErrors(t->data != NULL, "Cannot copy to an empty data array!");
CheckNTErrors(s->unitSize == t->unitSize, "The input tensors must be of the same unit size!");
CheckNTErrors(s->order > sBeg && sBeg >= 0 && sLen <= s->unitNum, "Wrong segment on the source side");
CheckNTErrors(t->order > tBeg && tBeg >= 0, "Wrong segment on the target side");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论