test1=: 0:`1:`2: @. (3&|)

For J9.01 and earlier,

test1 i. 6 is a rank error because execution of (3&|)  doesn't produce an atom.

So you guys must be using J9.02.  Thanks for helping out!

Starting in 9.02, this doesn't automatically produce a rank error.  Instead, the result of (3&| i. 6/7) is inspected.  It is seen to produce a result with the same shape as (i. 6): that is, there is one result-atom for each atom of (y).  This means that the implied rank of the verbs in (0:`1:`2:) is 0: each verb is assumed to produce a result for each 0-cell (i. e. atom) of input.

[Note that this is a requirement on the gerund-verb.  The gerund is not executed with rank 0: that would be inefficient.  Rather, the gerund must behave properly when given an argument of rank > 0.]

[if the selector-verb were (3 | +/"1) and the argument were (i. 3 6), the selector would produce a result with shape (,3) and the JE would conclude that the implied rank of the gerund-verbs is 1.]

The gerunds are then executed as called for by the result of (3&|).  How many times are they executed?  That's none of your business - the JE might execute them one at a time, or it might group them together.  When you execute (test1 i. 6), the JE executes each gerund on an atom, and you get no error.

But when you execute (test1 i. 7), the JE decides differently.  It collects the inputs to the first gerund (0 3 6) and passes them in a single call to the verb (0:).  Remember, the verb is charged with giving a result on each atom.  But this verb doesn't.  It gives a single atomic result, which is a rank error because it is not the 3 results expected.

How to fix it?  Make each gerund follow the rules, and give a result on each atom.  A simple way, inefficient in general, is to make sure the rank of each gerund is the implied rank of the verb:

   test1a=: 0"0`(1"0)`(2"0) @. (3&|)
   test1a i. 7
0 1 2 0 1 2 0

The gerund-verb can have a higher rank if it is well-behaved:

   test1b=: 0"0`(3&|)`(3&|) @. (3&|)
   test1b i. 7
0 1 2 0 1 2 0



This is what I was trying to say in the NuVoc writeup.  If you would reread it and tell me what's unclear, or just fix the Wiki yourself, I'd be obliged.

Henry Rich


On 6/7/2020 1:18 PM, Devon McCormick wrote:
I see the same anomaly for the "i.7" argument on J 9.02.03 under Windows 10:
    test1=: 0:`1:`2: @. (3&|)
    test1 &.> i.&.> >:i.6
+-+---+-----+-------+---------+-----------+
|0|0 1|0 1 2|0 1 2 0|0 1 2 0 1|0 1 2 0 1 2|
+-+---+-----+-------+---------+-----------+
    test1 i.7
|rank error: test1
|test1[0]
       dbr 1 [ dbr 0
    test1 i.100
|rank error: test1
|test1[0]

But defining "test1" with scalar rank does not exhibit this behavior:
    test1=: 0:`1:`2: @. (3&|)"0
    test1&.>i.&.>7+i.3
+-------------+---------------+-----------------+
|0 1 2 0 1 2 0|0 1 2 0 1 2 0 1|0 1 2 0 1 2 0 1 2|
+-------------+---------------+-----------------+


On Sun, Jun 7, 2020 at 10:39 AM Hauke Rehr <[email protected]> wrote:

test1 i.6
doesn’t work for me either

but both
test1"0 i.6
and
test1"0 i.7
do work as expected

Am 07.06.20 um 16:35 schrieb çağlar girit:
Hi,

Although I have read NuVoc entries for Agenda and Constant Function, I
still don't understand why for "test1 =. 0: ` 1: ` 2: @. (3&|)", "test1
i.
6" works whereas "test2 i.7" gives a rank error.  Am I missing some
subtlety of implied rank with Agenda?

    test1 =. 0: ` 1: ` 2: @. (3&|)
    test1 i.6
0 1 2 0 1 2
     test1 i.7
|rank error: test1
|       test1 i.7

Thanks!


--
----------------------
mail written using NEO
neo-layout.org

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




--
This email has been checked for viruses by AVG.
https://www.avg.com

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to