From: Francois Fleuret Date: Fri, 10 Apr 2020 21:31:15 +0000 (+0200) Subject: Update. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=7315192ca0a1d1fdbfcb85da97ee41b2c68cbc6e;p=pytorch.git Update. --- diff --git a/poly.py b/poly.py index 818742b..1b157a8 100755 --- 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) +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:] @@ -31,3 +35,4 @@ if __name__ == '__main__': 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])))