Skip to content

Commit 18bbc45

Browse files
committed
feat(csharp/Tensor.NET): add mod, and, or, xor methods in csharp.
1 parent 60479a4 commit 18bbc45

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

csharp/Tensor.NET/Operators/And.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Tensornet.Common;
2+
3+
namespace Tensornet{
4+
public partial class Tensor<T>{
5+
public static Tensor<T> operator&(Tensor<T> lhs, Tensor<T> rhs){
6+
return InterElemOperation.Execute<T>(lhs, rhs, InterElemOperationType.And);
7+
}
8+
public static Tensor<T> operator&(Tensor<T> lhs, T rhs){
9+
return InterElemOperation.Execute<T>(lhs, (Tensor<T>)rhs, InterElemOperationType.And);
10+
}
11+
public static Tensor<T> operator&(T lhs, Tensor<T> rhs){
12+
return InterElemOperation.Execute<T>((Tensor<T>)lhs, rhs, InterElemOperationType.And);
13+
}
14+
}
15+
}

csharp/Tensor.NET/Operators/Mod.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Tensornet.Common;
2+
3+
namespace Tensornet{
4+
public partial class Tensor<T>{
5+
public static Tensor<T> operator%(Tensor<T> lhs, Tensor<T> rhs){
6+
return InterElemOperation.Execute<T>(lhs, rhs, InterElemOperationType.Mod);
7+
}
8+
public static Tensor<T> operator%(Tensor<T> lhs, T rhs){
9+
return InterElemOperation.Execute<T>(lhs, (Tensor<T>)rhs, InterElemOperationType.Mod);
10+
}
11+
public static Tensor<T> operator%(T lhs, Tensor<T> rhs){
12+
return InterElemOperation.Execute<T>((Tensor<T>)lhs, rhs, InterElemOperationType.Mod);
13+
}
14+
}
15+
}

csharp/Tensor.NET/Operators/Or.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Tensornet.Common;
2+
3+
namespace Tensornet{
4+
public partial class Tensor<T>{
5+
public static Tensor<T> operator|(Tensor<T> lhs, Tensor<T> rhs){
6+
return InterElemOperation.Execute<T>(lhs, rhs, InterElemOperationType.Or);
7+
}
8+
public static Tensor<T> operator|(Tensor<T> lhs, T rhs){
9+
return InterElemOperation.Execute<T>(lhs, (Tensor<T>)rhs, InterElemOperationType.Or);
10+
}
11+
public static Tensor<T> operator|(T lhs, Tensor<T> rhs){
12+
return InterElemOperation.Execute<T>((Tensor<T>)lhs, rhs, InterElemOperationType.Or);
13+
}
14+
}
15+
}

csharp/Tensor.NET/Operators/Xor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Tensornet.Common;
2+
3+
namespace Tensornet{
4+
public partial class Tensor<T>{
5+
public static Tensor<T> operator^(Tensor<T> lhs, Tensor<T> rhs){
6+
return InterElemOperation.Execute<T>(lhs, rhs, InterElemOperationType.Xor);
7+
}
8+
public static Tensor<T> operator^(Tensor<T> lhs, T rhs){
9+
return InterElemOperation.Execute<T>(lhs, (Tensor<T>)rhs, InterElemOperationType.Xor);
10+
}
11+
public static Tensor<T> operator^(T lhs, Tensor<T> rhs){
12+
return InterElemOperation.Execute<T>((Tensor<T>)lhs, rhs, InterElemOperationType.Xor);
13+
}
14+
}
15+
}

csharp/Tensor.NET/Tensor/Common/InterElemOperation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ internal enum InterElemOperationType{
77
Add = 1,
88
Sub = 2,
99
Mul = 3,
10-
Div = 4
10+
Div = 4,
11+
Mod = 5,
12+
And = 6,
13+
Or = 7,
14+
Xor = 8
1115
}
1216
internal static class InterElemOperation{
1317
public static unsafe Tensor<T> Execute<T>(Tensor<T> a, Tensor<T> b, InterElemOperationType operationType)

doc/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
| Add zeros_like, ones_like, fill_like methods | | p0 | Complete ✅ |
5656
| Add flatten method | | p0 | Complete ✅ |
5757
| Add max, min, mean op | | p0 | Complete ✅ |
58-
| Add mod, and, or, xor operators in csharp | | p0 | Waiting 🔵 |
58+
| Add mod, and, or, xor operators in csharp | | p0 | Complete ✅ |
5959

6060

6161
✅ ❌ 🚀 🔵

0 commit comments

Comments
 (0)