projects
/
pytorch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Cleaning up the code a bit.
[pytorch.git]
/
poly.py
diff --git
a/poly.py
b/poly.py
index
818742b
..
1b157a8
100755
(executable)
--- a/
poly.py
+++ b/
poly.py
@@
-19,6
+19,10
@@
def pol_prod(a, b):
q = (kk == torch.arange(a.size(0) + b.size(0) - 1)[None, :])
return (mm * q).sum(0)
q = (kk == torch.arange(a.size(0) + b.size(0) - 1)[None, :])
return (mm * q).sum(0)
+def pol_eval(a, x):
+ d = torch.arange(a.size(0))
+ return (x[:, None].pow(d[None, :]) * a[None, :]).sum(1)
+
def pol_prim(a):
n = torch.arange(a.size(0) + 1).float()
n[1:] = a / n[1:]
def pol_prim(a):
n = torch.arange(a.size(0) + 1).float()
n[1:] = a / n[1:]
@@
-31,3
+35,4
@@
if __name__ == '__main__':
b = torch.tensor([2., 5.])
print(pol_prod(a, b))
print(pol_prim(b))
b = torch.tensor([2., 5.])
print(pol_prod(a, b))
print(pol_prim(b))
+ print(pol_eval(a, torch.tensor([0.0, 1.0, 2.0])))