From 7315192ca0a1d1fdbfcb85da97ee41b2c68cbc6e Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Fri, 10 Apr 2020 23:31:15 +0200 Subject: [PATCH] Update. --- poly.py | 5 +++++ 1 file changed, 5 insertions(+) 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]))) -- 2.39.5