We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents abfae5e + 90608c1 commit c187ce8Copy full SHA for c187ce8
inst/@sym/piecewise.m
@@ -68,11 +68,14 @@
68
print_usage ();
69
end
70
71
- cmd = {'def chunks_of(ls, n):'
72
- ' return itertools.zip_longest(*[ls[k::n] for k in range(n)])'
73
- 'args = [(val, cond) if val is not None else (cond, True)'
74
- ' for cond, val in chunks_of(_ins, 2)]'
75
- 'return Piecewise(*args)'
+ cmd = {'def pack_args_without_else(args):'
+ ' return [(val, cond) for cond, val in unflatten(args, 2)]'
+ 'def pack_args(args):'
+ ' if len(args) % 2 == 0:'
+ ' return pack_args_without_else(args)'
76
+ ' else:'
77
+ ' return pack_args_without_else(args[:-1]) + [(args[-1], True)]'
78
+ 'return Piecewise(*pack_args(_ins))'
79
};
80
81
args = cellfun (@sym, varargin, 'UniformOutput', false);
0 commit comments