Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
97da3265
Commit
97da3265
authored
Mar 01, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates of GetItem and SetItem in List
parent
9b3209d8
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
101 行增加
和
2 行删除
+101
-2
source/tensor/XList.cpp
+77
-2
source/tensor/XList.h
+24
-0
没有找到文件。
source/tensor/XList.cpp
查看文件 @
97da3265
...
@@ -274,16 +274,64 @@ void TensorListBase<T>::Insert(int pos, T&& item)
...
@@ -274,16 +274,64 @@ void TensorListBase<T>::Insert(int pos, T&& item)
/* get the item at position i */
/* get the item at position i */
template
<
typename
T
>
template
<
typename
T
>
T
&
TensorListBase
<
T
>::
GetItem
(
int
i
)
const
inline
T
&
TensorListBase
<
T
>::
GetItem
(
int
i
)
const
{
{
CheckNTErrors
(
i
>=
-
count
&&
i
<
count
,
"Index of a list item is out of scope!"
);
CheckNTErrors
(
i
>=
-
count
&&
i
<
count
,
"Index of a list item is out of scope!"
);
CheckNTErrors
(
count
>
0
,
"Cannt index the item in an empty list!"
);
CheckNTErrors
(
count
>
0
,
"Cann
o
t index the item in an empty list!"
);
if
(
i
<
0
)
if
(
i
<
0
)
return
items
[
count
+
i
];
return
items
[
count
+
i
];
else
else
return
items
[
i
];
return
items
[
i
];
}
}
/* get the item at position i and force it to an integer */
template
<
typename
T
>
inline
int
TensorListBase
<
T
>::
GetItemInt
(
int
i
)
const
{
CheckNTErrors
(
i
>=
-
count
&&
i
<
count
,
"Index of a list item is out of scope!"
);
CheckNTErrors
(
count
>
0
,
"Cannot index the item in an empty list!"
);
if
(
i
<
0
)
return
0
;
else
{
T
r
=
items
[
i
];
void
*
p
=
&
r
;
return
*
(
int
*
)
p
;
}
}
/* get the item at position i and force it to a float number */
template
<
typename
T
>
inline
float
TensorListBase
<
T
>::
GetItemFloat
(
int
i
)
const
{
CheckNTErrors
(
i
>=
-
count
&&
i
<
count
,
"Index of a list item is out of scope!"
);
CheckNTErrors
(
count
>
0
,
"Cannot index the item in an empty list!"
);
if
(
i
<
0
)
return
0
;
else
{
T
r
=
items
[
i
];
void
*
p
=
&
r
;
return
*
(
float
*
)
p
;
}
}
/* get the item at position i and force it to an long long number */
template
<
typename
T
>
inline
long
long
TensorListBase
<
T
>::
GetItemLLong
(
int
i
)
const
{
CheckNTErrors
(
i
>=
-
count
&&
i
<
count
,
"Index of a list item is out of scope!"
);
CheckNTErrors
(
count
>
0
,
"Cannot index the item in an empty list!"
);
if
(
i
<
0
)
return
0
;
else
{
T
r
=
items
[
i
];
void
*
p
=
&
r
;
return
*
(
long
long
*
)
p
;
}
}
/* set the item at position i */
/* set the item at position i */
template
<
typename
T
>
template
<
typename
T
>
inline
void
TensorListBase
<
T
>::
SetItem
(
int
i
,
const
T
&
item
)
inline
void
TensorListBase
<
T
>::
SetItem
(
int
i
,
const
T
&
item
)
...
@@ -299,6 +347,33 @@ inline void TensorListBase<T>::SetItem(int i, T&& item)
...
@@ -299,6 +347,33 @@ inline void TensorListBase<T>::SetItem(int i, T&& item)
items
[
i
]
=
item
;
items
[
i
]
=
item
;
}
}
/* set the item (as an integer) at position i */
template
<
typename
T
>
inline
void
TensorListBase
<
T
>::
SetItemInt
(
int
i
,
const
int
item
)
{
if
(
i
>=
0
&&
i
<
count
)
{
*
(
int
*
)(
items
+
i
)
=
item
;
}
}
/* set the item (as a float) at position i */
template
<
typename
T
>
inline
void
TensorListBase
<
T
>::
SetItemFloat
(
int
i
,
const
float
item
)
{
if
(
i
>=
0
&&
i
<
count
)
{
*
(
float
*
)(
items
+
i
)
=
item
;
}
}
/* set the item (as a long long) at position i */
template
<
typename
T
>
inline
void
TensorListBase
<
T
>::
SetItemLLong
(
int
i
,
const
long
long
item
)
{
if
(
i
>=
0
&&
i
<
count
)
{
*
(
long
long
*
)(
items
+
i
)
=
item
;
}
}
/*
/*
find the position of the first matched item
find the position of the first matched item
>> item - the item for matching
>> item - the item for matching
...
...
source/tensor/XList.h
查看文件 @
97da3265
...
@@ -99,12 +99,30 @@ public:
...
@@ -99,12 +99,30 @@ public:
/* get the item at position i */
/* get the item at position i */
T
&
GetItem
(
int
i
)
const
;
T
&
GetItem
(
int
i
)
const
;
/* get the item at position i and force it to an integer */
int
GetItemInt
(
int
i
)
const
;
/* get the item at position i and force it to a float number */
float
GetItemFloat
(
int
i
)
const
;
/* get the item at position i and force it to an long long number */
long
long
GetItemLLong
(
int
i
)
const
;
/* set the item at position i */
/* set the item at position i */
void
SetItem
(
int
i
,
const
T
&
item
);
void
SetItem
(
int
i
,
const
T
&
item
);
/* set the item at position i */
/* set the item at position i */
void
SetItem
(
int
i
,
T
&&
item
);
void
SetItem
(
int
i
,
T
&&
item
);
/* set the item (as an integer) at position i */
void
SetItemInt
(
int
i
,
const
int
item
);
/* set the item (as a float) at position i */
void
SetItemFloat
(
int
i
,
const
float
item
);
/* set the item (as a long long) at position i */
void
SetItemLLong
(
int
i
,
const
long
long
item
);
/* find the position of the first matched item */
/* find the position of the first matched item */
int
FindFirst
(
const
T
&
item
);
int
FindFirst
(
const
T
&
item
);
...
@@ -135,7 +153,13 @@ public:
...
@@ -135,7 +153,13 @@ public:
/* short */
/* short */
T
&
operator
[]
(
int
i
)
const
{
return
GetItem
(
i
);
};
T
&
operator
[]
(
int
i
)
const
{
return
GetItem
(
i
);
};
T
&
Get
(
int
i
)
const
{
return
GetItem
(
i
);
};
T
&
Get
(
int
i
)
const
{
return
GetItem
(
i
);
};
int
GetInt
(
int
i
)
const
{
return
GetItemInt
(
i
);
};
float
GetFloat
(
int
i
)
const
{
return
GetItemFloat
(
i
);
};
long
long
GetLLong
(
int
i
)
const
{
return
GetItemLLong
(
i
);
};
void
Set
(
int
i
,
T
item
)
{
SetItem
(
i
,
item
);
};
void
Set
(
int
i
,
T
item
)
{
SetItem
(
i
,
item
);
};
void
SetInt
(
int
i
,
int
item
)
{
SetItemInt
(
i
,
item
);
};
void
SetFloat
(
int
i
,
float
item
)
{
SetItemFloat
(
i
,
item
);
};
void
SetLLong
(
int
i
,
long
long
item
)
{
SetItemLLong
(
i
,
item
);
};
};
};
struct
XTensor
;
struct
XTensor
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论