|
3 | 3 | from .deepxir import DeepxIR |
4 | 4 | OpNode.register("add") |
5 | 5 |
|
6 | | -@tensor_method |
7 | | -def add(self, other): |
8 | | - resultnode = self.graph.add_tensor("", self) |
9 | | - opnode = self.graph.add_op("add") |
10 | | - opnode.add_input(self.node) |
11 | | - opnode.add_input(other.node) |
12 | | - resultnode.add_input(opnode) |
13 | | - if self.graph.eager: |
14 | | - ir=DeepxIR("add", self._dtype, [self.node.name, other.node.name], [resultnode.name]) |
| 6 | +def add(a:Tensor,b:Tensor,out:Tensor): |
| 7 | + opnode = a.graph.add_op("add") |
| 8 | + opnode.add_input(a.node) |
| 9 | + opnode.add_input(b.node) |
| 10 | + out.node.add_input(opnode) |
| 11 | + if a.graph.eager: |
| 12 | + ir=DeepxIR("add", a.dtype, [a.node.name, b.node.name], [out.node.name]) |
15 | 13 | print(ir) |
16 | | - return resultnode |
| 14 | + |
| 15 | +@tensor_method |
| 16 | +def add_(self, other): |
| 17 | + result = Tensor(dtype=self.dtype,shape=self.shape) |
| 18 | + result._node = self.graph.add_tensor("", self) |
| 19 | + add(self,other,result) |
| 20 | + return result |
17 | 21 |
|
18 | 22 | OpNode.register("mul") |
19 | 23 |
|
| 24 | +def mul(a:Tensor,b:Tensor,out:Tensor): |
| 25 | + opnode = a.graph.add_op("mul") |
| 26 | + opnode.add_input(a.node) |
| 27 | + opnode.add_input(b.node) |
| 28 | + out.node.add_input(opnode) |
| 29 | + if a.graph.eager: |
| 30 | + ir=DeepxIR("mul", a.dtype, [a.node.name, b.node.name], [out.node.name]) |
| 31 | + print(ir) |
| 32 | + |
20 | 33 | @tensor_method |
21 | | -def mul(self, other): |
22 | | - result = self.graph.add_tensor("", self.dtype, self.shape, self.requires_grad) |
23 | | - op = self.graph.add_op("mul") |
24 | | - op.add_input(self.node) |
25 | | - op.add_input(other.node) |
26 | | - result.add_input(op) |
| 34 | +def mul_(self, other): |
| 35 | + result = Tensor(dtype=self.dtype,shape=self.shape) |
| 36 | + result._node = self.graph.add_tensor("", self) |
| 37 | + mul(self,other,result) |
27 | 38 | return result |
28 | 39 |
|
29 | 40 |
|
|
0 commit comments