From: Francois Fleuret Date: Fri, 10 Apr 2020 21:21:18 +0000 (+0200) Subject: Update. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=cb2bd8ee4853aed17754ef97f53434d63caa1828;p=python.git Update. --- diff --git a/poly.py b/poly.py deleted file mode 100755 index 818742b..0000000 --- a/poly.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python - -# Any copyright is dedicated to the Public Domain. -# https://creativecommons.org/publicdomain/zero/1.0/ - -# Written by Francois Fleuret - -###################################################################### - -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))