Dyalog / Dyalog/pynapl

Cannot derive monadic operator from inner product with right operand.

Open
#10 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
86
Forks
14
PR merge metrics
No merged PRs in 30d

Description

```py
>>> import operator
>>> from pynapl import APL
>>> apl = APL.APL()
>>> dot_ = apl.op(".+")
>>> dot_(operator.mul)([1, 2, 3], [1, 2, 3])
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\rodri\Documents\Dyalog\pynapl\pynapl\APLPyConnect.py", line 307, in __fn
if len(args)==2: return self.eval("(⊃∆)(%s)2⊃∆"%aplfn, args[0], args[1], raw=raw)
File "C:\Users\rodri\Documents\Dyalog\pynapl\pynapl\APLPyConnect.py", line 381, in eval
raise APLError(json_obj=reply.data)
pynapl.APLPyConnect.APLError: SYNTAX ERROR
```

The expected behaviour would've been to compute `1 2 3 ×.+ 1 2 3`. Instead, we get a `SYNTAX ERROR`.
This does not seem to be a shortcoming of dyadic operators in general, as we seem to be able to derive monadic operators from other dyadic operators; `@` for example:

```py
>>> from pynapl import APL
>>> apl = APL.APL()
>>> # Array right operand
>>> at_first = apl.op("@1")
>>> at_first(lambda *_: 73)([1, 2, 3, 4])
[73, 2, 3, 4]
>>> at_first(lambda n: n + 3)([1, 2, 3, 4])
[4, 2, 3, 4]
>>> # Function right operand
>>> at_self = apl.op("@⊢")
>>> at_self(lambda *_: 73)([1, 0, 1, 0, 0, 1, 1])
[73, 0, 73, 0, 0, 73, 73]
```

Probably related to the special casing mentioned in #9.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in pynapl/APLPyConnect.py at __fn around line 307 and eval around line 381, then compare the operator handling mentioned in #9 with the working @ examples. Reproduce the .+ case and verify that apl.op(".+")(operator.mul) computes the expected inner product without a SYNTAX ERROR.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.