Last active
September 16, 2018 05:36
-
-
Save piroyoung/6dedaaec66f8a3db1a35d2532e5267d5 to your computer and use it in GitHub Desktop.
dimcheck.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Callable | |
from numpy import array | |
from numpy import ndarray | |
def dimension(*expected: int): | |
def wrap_up(func: Callable) -> Callable: | |
def wrapped(*args, **kwargs) -> ndarray: | |
result: ndarray = func(*args, **kwargs) | |
assert tuple(result.shape) == tuple(expected), "Mismatch dimensions" | |
return result | |
return wrapped | |
return wrap_up | |
@dimension(2, 1) | |
def f(): | |
return array([[1], [1]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment