12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!usr/bin/env python
- # -*- coding: utf8 -*-
- # -----------------------------------------------------------------------------
- # File: utils.py (as part of project URUMETRICS)
- # Created: 01/06/2022 16:36
- # Last Modified: 01/06/2022 16:36
- # -----------------------------------------------------------------------------
- # Author: William N. Havard
- # Postdoctoral Researcher
- #
- # Mail : william.havard@ens.fr / william.havard@gmail.com
- #
- # Institution: ENS / Laboratoire de Sciences Cognitives et Psycholinguistique
- #
- # ------------------------------------------------------------------------------
- # Description:
- # •
- # -----------------------------------------------------------------------------
- import os
- import numpy as np
- from functools import wraps
- def staticvariable(**assignments):
- def decorate(func):
- for var, val in assignments.items():
- setattr(func, var, val)
- @wraps(func)
- def wrapper(*args, **kwargs):
- return func(*args, **kwargs)
- return wrapper
- return decorate
- def vectorise(func):
- """
- To be used as decorator to vectorise a function using Numpy. Contrary to Numpy's vectorize function, this function
- preserves the name of the original function
- :param func: function
- :type func: callable
- :return: decorated function
- :rtype: callable
- """
- @wraps(func)
- def wrapper(args, **kwargs):
- return np.vectorize(func)(args, **kwargs)
- return wrapper
|