--- /dev/null
+#!/usr/bin/env python
+
+# Any copyright is dedicated to the Public Domain.
+# https://creativecommons.org/publicdomain/zero/1.0/
+
+# Written by Francois Fleuret <francois@fleuret.org>
+
+######################################################################
+
+import torch
+
+def pol_prod(a, b):
+ m = a[:, None] * b[None, :]
+ mm = m.new()
+ mm.set_(m.storage(), 0, (m.size(0), m.size(0) + m.size(1) - 1), (m.size(1) - 1, 1))
+ k = torch.arange(a.size(0))[:, None] + torch.arange(b.size(0))[None, :]
+ kk = k.new()
+ kk.set_(k.storage(), 0, (k.size(0), k.size(0) + k.size(1) - 1), (k.size(1) - 1, 1))
+ q = (kk == torch.arange(a.size(0) + b.size(0) - 1)[None, :])
+ return (mm * q).sum(0)
+
+def pol_prim(a):
+ n = torch.arange(a.size(0) + 1).float()
+ n[1:] = a / n[1:]
+ return n
+
+######################################################################
+
+if __name__ == '__main__':
+ a = torch.tensor([1., 2., 3.])
+ b = torch.tensor([2., 5.])
+ print(pol_prod(a, b))
+ print(pol_prim(b))