Skip to content

Instantly share code, notes, and snippets.

@piroyoung
Last active September 16, 2018 05:36
Show Gist options
  • Save piroyoung/6dedaaec66f8a3db1a35d2532e5267d5 to your computer and use it in GitHub Desktop.
Save piroyoung/6dedaaec66f8a3db1a35d2532e5267d5 to your computer and use it in GitHub Desktop.
dimcheck.py
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