Crash with map in function expression and sum with non-numerical arguments
The following program works:
mask = (b: true, false, true)
len = sum(map((x: if(x, 1, 0)), mask))
print(len)
but if I define a function:
mask = (b: true, false, true)
lenf(z) = sum(map((x: if(x, 1, 0)), z))
print(lenf(mask))
I get this error:
Traceback (most recent call last):
File "vre-language/src/virtmat/language/utilities/errors.py", line 87, in wrapper
return func(*args, **kwargs)
File "../scripts/run_model.py", line 56, in run_instant_deferred
return meta.model_from_file(clargs.model_file, deferred_mode=deferred,
File "jupyter-tensorflow-2023-01-02/lib64/python3.8/site-packages/textx/metamodel.py", line 658, in model_from_file
return self.internal_model_from_file(
File "jupyter-tensorflow-2023-01-02/lib64/python3.8/site-packages/textx/metamodel.py", line 712, in internal_model_from_file
p(model, self)
File "vre-language/src/virtmat/language/metamodel/function.py", line 38, in function_call_processor
call.__expr = deepcopy(call.function.expr)
File "/usr/lib64/python3.8/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib64/python3.8/copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python3.8/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python3.8/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib64/python3.8/copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python3.8/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python3.8/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib64/python3.8/copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python3.8/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python3.8/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib64/python3.8/copy.py", line 270, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python3.8/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python3.8/copy.py", line 230, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python3.8/copy.py", line 161, in deepcopy
rv = reductor(4)
TypeError: cannot pickle '_io.TextIOWrapper' object
It is striking that sum(mask)
works - it returns the number of true
elements which is the behavior in Python but should not be in the DSL. I thought that only numerical types are allowed in sum. For non-arithmetic types either reduce()
should be used or a map
converting the booleans to 0 or 1 integers.