3 # Any copyright is dedicated to the Public Domain.
4 # https://creativecommons.org/publicdomain/zero/1.0/
6 # Written by Francois Fleuret <francois@fleuret.org>
8 ######################################################################
13 m = a[:, None] * b[None, :]
15 mm.set_(m.storage(), 0, (m.size(0), m.size(0) + m.size(1) - 1), (m.size(1) - 1, 1))
16 k = torch.arange(a.size(0))[:, None] + torch.arange(b.size(0))[None, :]
18 kk.set_(k.storage(), 0, (k.size(0), k.size(0) + k.size(1) - 1), (k.size(1) - 1, 1))
19 q = (kk == torch.arange(a.size(0) + b.size(0) - 1)[None, :])
20 return (mm * q).sum(0)
23 d = torch.arange(a.size(0))
24 return (x[:, None].pow(d[None, :]) * a[None, :]).sum(1)
27 n = torch.arange(a.size(0) + 1).float()
31 ######################################################################
33 if __name__ == '__main__':
34 a = torch.tensor([1., 2., 3.])
35 b = torch.tensor([2., 5.])
38 print(pol_eval(a, torch.tensor([0.0, 1.0, 2.0])))