Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
y33-j3T
GitHub Repository: y33-j3T/Coursera-Deep-Learning
Path: blob/master/Convolutional Neural Networks/week3/Car detection for Autonomous Driving/yad2k/utils/utils.py
14462 views
1
"""Miscellaneous utility functions."""
2
3
from functools import reduce
4
5
6
def compose(*funcs):
7
"""Compose arbitrarily many functions, evaluated left to right.
8
9
Reference: https://mathieularose.com/function-composition-in-python/
10
"""
11
# return lambda x: reduce(lambda v, f: f(v), funcs, x)
12
if funcs:
13
return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
14
else:
15
raise ValueError('Composition of empty sequence not supported.')
16
17