Skip to content

Commit 25a307d

Browse files
test
1 parent 78a22b1 commit 25a307d

File tree

5 files changed

+22
-37
lines changed

5 files changed

+22
-37
lines changed

CPythonTensor/CPythonTensor.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@
7373
<PropertyGroup Label="UserMacros" />
7474
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
7575
<TargetExt>.pyd</TargetExt>
76-
<TargetName>tensor_d</TargetName>
76+
<TargetName>tensor_bind</TargetName>
7777
</PropertyGroup>
7878
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
7979
<TargetExt>.pyd</TargetExt>
80-
<TargetName>tensor</TargetName>
80+
<TargetName>tensor_bind</TargetName>
8181
</PropertyGroup>
8282
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
8383
<ClCompile>

CPythonTensor/tensor_bind.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ std::string tensor_to_string(const Tensor t)
3030
return osstream.str();
3131
}
3232

33-
PYBIND11_MODULE(tensor, m)
33+
PYBIND11_MODULE(tensor_bind, m)
3434
{
3535
pybind11::class_<Tensor>(m, "TensorC")
3636
.def(pybind11::init())
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1 @@
1-
import numpy as np
2-
import tensor as t
3-
4-
class Tensor:
5-
def __init__(self, arr):
6-
self.temp_tensor = t.TensorC(arr)
7-
8-
def __add__(self, other):
9-
result = Tensor(0);
10-
result.temp_tensor = self.temp_tensor + other.temp_tensor
11-
return result;
12-
13-
def __sub__(self, other):
14-
result = Tensor(0);
15-
result.temp_tensor = self.temp_tensor - other.temp_tensor
16-
return result;
17-
18-
def __matmul__(self, other):
19-
result = Tensor(0);
20-
result.temp_tensor = self.temp_tensor @ other.temp_tensor
21-
return result;
22-
23-
def __str__(self) -> str:
24-
return self.temp_tensor.__str__()
25-
26-
1+
from .tensor import *
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import numpy as np
2+
import tensor_bind as t
3+
4+
def tensor_decorator(cls):
5+
return t.TensorC
6+
7+
@tensor_decorator
8+
class Tensor:
9+
def __init__(self):
10+
pass
11+

PythonTensorTesting/main.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
# import os
2-
3-
# os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin'))
4-
51
import PyTensorArray as py_t_arr
62

73
import numpy as np
84

95
if __name__ == '__main__':
10-
t3 = np.array([[1, 2, 3], [4, 5, 6]])
11-
t1 = py_t_arr.Tensor([[1, 2.5, 3], [4, 5, 6]])
12-
t2 = py_t_arr.Tensor([[1, 2.5], [4, 5], [7.5, 8]])
13-
t3 = t1 @ t2
6+
t4 = np.array([[1, 2, 3], [4, 5, 6]])
7+
t1 = py_t_arr.tensor.Tensor(t4)
8+
t2 = py_t_arr.tensor.Tensor(t4)
9+
t3 = t1 + t2
1410
print("Hello")
11+
print(t1)
12+
print(t2)
1513
print(t3)
14+
print(t1 == t2)

0 commit comments

Comments
 (0)