STEllAR-GROUP / phylanx

An Asynchronous Distributed C++ Array Processing Toolkit
Boost Software License 1.0
75 stars 76 forks source link

The problem with the `dtype` as an argument #866

Open taless474 opened 5 years ago

taless474 commented 5 years ago
import numpy as np
from phylanx import Phylanx

@Phylanx
def fx1(x):
    return np.eye(x, dtype='float')

print(fx1(5))  # OK

@Phylanx
def fx2(x, d):
    return np.eye(x, dtype=d)

print(fx2(5, 'float'))  # ValueError: dtype must a be string literal.

@Phylanx
def fx3(x, dtype):
    return np.eye(x, dtype=dtype)

print(fx3(5, 'float'))  # ValueError: dtype must a be string literal.

results in

[[1. 0. 0. 0. 0.]
 [0. 1. 0. 0. 0.]
 [0. 0. 1. 0. 0.]
 [0. 0. 0. 1. 0.]
 [0. 0. 0. 0. 1.]]
Traceback (most recent call last):
  File "test18.py", line 12, in <module>
    @Phylanx
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\transducer.py", line 104, in Phylanx
    return __PhylanxDecorator(__phylanx_arg)
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\transducer.py", line 48, in __init__
    self.backend = self.backends_map[self.backend](f, python_ast, kwargs)
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 350, in __init__
    self.ir = self.apply_rule(tree.body[0])
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 394, in apply_rule
    return eval('self._%s' % node_name)(node)
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 840, in _FunctionDef
    body = self.block(node.body)
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 400, in block
    block = tuple(map(self.apply_rule, node))
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 394, in apply_rule
    return eval('self._%s' % node_name)(node)
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 1011, in _Return
    return [symbol, (self.apply_rule(node.value),)]
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 394, in apply_rule
    return eval('self._%s' % node_name)(node)
  File "C:\Repos\phylanx\cmake-build-debug\python\build\lib.win-amd64-3.6\phylanx\ast\physl.py", line 638, in _Call
    raise ValueError("dtype must a be string literal.")
ValueError: dtype must a be string literal.
hkaiser commented 5 years ago

This exposes the more general problem that PhySL does not support named arguments at this point. Alternatively we will have to touch on all primitives that require dtype support and add it as a optional argument to them.

taless474 commented 5 years ago

Here is a list of existing primitives that need to support dtype:

And future primitives:

hkaiser commented 5 years ago

@taless474 here are some more: