pytorch/torch/testing/_deprecated.py
Philip Meier 10ccc5a81c remove randn? from torch.testing namespace (#61840)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/61840

Redo of #60859.

Test Plan: Imported from OSS

Reviewed By: jbschlosser

Differential Revision: D29871017

Pulled By: mruberry

fbshipit-source-id: 47afed1dc6aa0bb1e826af616ef5d5aaabb8e5bb
2021-07-23 11:51:03 -07:00

32 lines
1014 B
Python

"""This module exists since the `torch.testing` exposed a lot of stuff that shouldn't have been public. Although this
was never documented anywhere, some other internal FB projects as well as downstream OSS projects might use this. Thus,
we don't internalize without warning, but still go through a deprecation cycle.
"""
import functools
import warnings
from typing import Any, Callable
import torch
__all__ = ["rand", "randn"]
def warn_deprecated(instructions: str) -> Callable:
def outer_wrapper(fn: Callable) -> Callable:
msg = f"torch.testing.{fn.__name__} is deprecated and will be removed in the future. {instructions.strip()}"
@functools.wraps(fn)
def inner_wrapper(*args: Any, **kwargs: Any) -> Any:
warnings.warn(msg, FutureWarning)
return fn(*args, **kwargs)
return inner_wrapper
return outer_wrapper
rand = warn_deprecated("Use torch.rand instead.")(torch.rand)
randn = warn_deprecated("Use torch.randn instead.")(torch.randn)