Skip to content

Commit 1daaf03

Browse files
amogorkondependabot[bot]
andcommitted
refactor: Update MAX combinator to handle empty input
The MAX combinator in `combinators.py` has been updated to handle empty input by providing a default value of 1. This change ensures that the MAX combinator returns a valid result even when no functions are provided. Co-authored-by: dependabot[bot] <support@github.com>
1 parent 4ac5001 commit 1daaf03

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/fuzzylogic/combinators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def MAX(*guncs):
6565
funcs = list(guncs)
6666

6767
def F(z):
68-
return max(f(z) for f in funcs)
68+
return max((f(z) for f in funcs), default=1)
6969

7070
return F
7171

@@ -263,12 +263,13 @@ def simple_disjoint_sum(*funcs): # sourcery skip: unwrap-iterable-construction
263263
(A AND ~B AND ~C) OR (B AND ~A AND ~C) OR (C AND ~B AND ~A)
264264
max(min(0,0.5,0), min(0.5,1,0), min(1,0.5,1)) == 0.5
265265
"""
266+
266267
def F(z):
267268
# Reminder how it works for 2 args
268269
# x, y = a(z), b(z)
269270
# return max(min(x, 1-y), min(1-x, y))
270271

271-
M:set[float] = {
272+
M: set[float] = {
272273
f(z) for f in funcs
273274
} # a set of all membership values over all given functions to be iterated over
274275
# we need to go over each value in the set, calc min(x, inverse(rest)), from that calc max

0 commit comments

Comments
 (0)