From 68022399de61c9a9702b02b52ad8db1ac9d9e6fb Mon Sep 17 00:00:00 2001 From: jessegrabowski Date: Wed, 14 Feb 2024 07:57:13 +0800 Subject: [PATCH] fix typos, gradients --- pytensor/gradient.py | 17 +++++++++++------ pytensor/tensor/nlinalg.py | 6 ++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pytensor/gradient.py b/pytensor/gradient.py index 6f74df2da6..1be6cca1eb 100644 --- a/pytensor/gradient.py +++ b/pytensor/gradient.py @@ -1815,17 +1815,22 @@ def random_projection(shape, dtype): # This sum() is defined above, it's not the builtin sum. if sum_outputs: t_rs = [ - shared(random_projection(o.shape, o.dtype), borrow=True) for o in o_fn_out + shared( + value=random_projection(o.shape, o.dtype), + borrow=True, + name=f"random_projection_{i}", + ) + for i, o in enumerate(o_fn_out) ] - for i, x in enumerate(t_rs): - x.name = "ranom_projection_{i}" cost = pytensor.tensor.sum( [pytensor.tensor.sum(x * y) for x, y in zip(t_rs, o_output)] ) else: - t_r = shared(random_projection(o_fn_out.shape, o_fn_out.dtype), borrow=True) - t_r.name = "random_projection" - + t_r = shared( + value=random_projection(o_fn_out.shape, o_fn_out.dtype), + borrow=True, + name="random_projection", + ) cost = pytensor.tensor.sum(t_r * o_output) if no_debug_ref: diff --git a/pytensor/tensor/nlinalg.py b/pytensor/tensor/nlinalg.py index 818ce5b09a..b6dd4e11c2 100644 --- a/pytensor/tensor/nlinalg.py +++ b/pytensor/tensor/nlinalg.py @@ -6,6 +6,7 @@ import numpy as np from numpy.core.numeric import normalize_axis_tuple # type: ignore +import pytensor.printing from pytensor import scalar as ps from pytensor.gradient import DisconnectedType from pytensor.graph.basic import Apply @@ -552,7 +553,7 @@ def __init__(self, full_matrices: bool = True, compute_uv: bool = True): if self.full_matrices: self.gufunc_signature = "(m,n)->(m,m),(k),(n,n)" else: - self.gufunc_signature = "(m,n)->(m,k),(k),(k,n)" + self.gufunc_signature = "(m,n)->(o,k),(k),(k,p)" else: self.gufunc_signature = "(m,n)->(k)" @@ -653,9 +654,10 @@ def h(t): sign_t = ptb.where(ptm.eq(t, 0), 1, ptm.sign(t)) return ptm.maximum(ptm.abs(t), eps) * sign_t - numer = ptb.ones_like(A) - eye + numer = ptb.ones((k, k)) - eye denom = h(s[None] - s[:, None]) * h(s[None] + s[:, None]) E = numer / denom + E = pytensor.printing.Print("E")(E) utgu = U.T @ dU vtgv = VT @ dV