From afa78655b87d63a6e04d0376db976557586c3a80 Mon Sep 17 00:00:00 2001 From: Allen Goodman Date: Tue, 2 Jul 2024 17:56:10 -0400 Subject: [PATCH] tests --- src/beignet/polynomial/__div.py | 132 ----------------------------- src/beignet/polynomial/__init__.py | 2 - 2 files changed, 134 deletions(-) delete mode 100644 src/beignet/polynomial/__div.py diff --git a/src/beignet/polynomial/__div.py b/src/beignet/polynomial/__div.py deleted file mode 100644 index 5d09158328..0000000000 --- a/src/beignet/polynomial/__div.py +++ /dev/null @@ -1,132 +0,0 @@ -from typing import Callable, Tuple - -import torch -from torch import Tensor - - -def _div( - func: Callable, - input: Tensor, - other: Tensor, -) -> Tuple[Tensor, Tensor]: - input = torch.atleast_1d(input) - other = torch.atleast_1d(other) - - dtype = torch.promote_types(input.dtype, other.dtype) - - input = input.to(dtype) - other = other.to(dtype) - - m = input.shape[0] - n = other.shape[0] - - if m < n: - return torch.zeros_like(input[:1]), input - - if n == 1: - return input / other[-1], torch.zeros_like(input[:1]) - - def f(x: Tensor) -> Tensor: - indicies = torch.flip(x, [0]) - - indicies = torch.nonzero(indicies, as_tuple=False) - - if indicies.shape[0] > 1: - indicies = indicies[:1] - - if indicies.shape[0] < 1: - indicies = torch.concatenate( - [ - indicies, - torch.full( - [ - 1 - indicies.shape[0], - indicies.shape[1], - ], - 0, - ), - ], - 0, - ) - - return x.shape[0] - 1 - indicies[0][0] - - quotient = torch.zeros(m - n + 1, dtype=input.dtype) - - ridx = input.shape[0] - 1 - - size = m - f(other) - 1 - - y = torch.zeros(m + n + 1, dtype=input.dtype) - - y[size] = 1.0 - - x = quotient, input, y, ridx - - for index in range(0, size): - quotient, remainder, y2, ridx1 = x - - j = size - index - - p = func(y2, other) - - pidx = f(p) - - t = remainder[ridx1] / p[pidx] - - remainder_modified = remainder.clone() - remainder_modified[ridx1] = 0.0 - - a = remainder_modified - - p_modified = p.clone() - p_modified[pidx] = 0.0 - - b = t * p_modified - - a = torch.atleast_1d(a) - b = torch.atleast_1d(b) - - dtype = torch.promote_types(a.dtype, b.dtype) - - a = a.to(dtype) - b = b.to(dtype) - - if a.shape[0] > b.shape[0]: - output = -b - - output = torch.concatenate( - [ - output, - torch.zeros( - a.shape[0] - b.shape[0], - dtype=b.dtype, - ), - ], - ) - output = a + output - else: - output = -b - - output = torch.concatenate( - [ - output[: a.shape[0]] + a, - output[a.shape[0] :], - ], - ) - - remainder = output - - remainder = remainder[: remainder.shape[0]] - - quotient[j] = t - - ridx1 = ridx1 - 1 - - y2 = torch.roll(y2, -1) - - x = quotient, remainder, y2, ridx1 - - quotient, remainder, _, _ = x - - return quotient, remainder diff --git a/src/beignet/polynomial/__init__.py b/src/beignet/polynomial/__init__.py index 3f043ea610..58325d04d5 100644 --- a/src/beignet/polynomial/__init__.py +++ b/src/beignet/polynomial/__init__.py @@ -7,7 +7,6 @@ import torch.linalg -from .__div import _div from .__fit import _fit from .__from_roots import _from_roots from .__normed_hermite_e_n import _normed_hermite_e_n @@ -277,7 +276,6 @@ torch.set_default_dtype(torch.float64) __all__ = [ - "_div", "_fit", "_from_roots", "_normed_hermite_e_n",