phylanx icon indicating copy to clipboard operation
phylanx copied to clipboard

The problem with the `dtype` as an argument

Open taless474 opened this issue 5 years ago • 3 comments

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.

taless474 avatar Mar 12 '19 19:03 taless474

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.

hkaiser avatar Mar 12 '19 21:03 hkaiser

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

  • [x] eye (#884)
  • [x] constant (#919)
  • [x] random (#1087)
  • [x] arange (#884)
  • [x] variable (#903)
  • [x] generic math operations (#1087)

And future primitives:

  • [ ] map_fn
  • [ ] placeholder
  • [x] cast (astype added by #954)

taless474 avatar Mar 13 '19 18:03 taless474

@taless474 here are some more:

  • [x] cumprod (#884)
  • [x] cumsum (#884)
  • [x] dstack, vstack, hstack, stack (#884)
  • [ ] vsplit, hsplit
  • [ ] all numeric operations (__add, __sub, __mul, __div, __neg)
  • [x] identity (#1087)
  • [x] insert (#1087)
  • [ ] linearmatrix
  • [ ] linspace
  • [ ] power
  • [ ] some statistics operations (min, max, mean, prod, sum)

hkaiser avatar Mar 14 '19 01:03 hkaiser