[Jprogramming] reshaping a list to a table
'Michael Day' via Programming
programming at jsoftware.com
Sat May 16 23:07:55 UTC 2020
So have we all (mostly) been wrong over all the years in reporting, and
comparing,
ts, and the like, to assess which is the "best" version of some verb?
We had all,
mostly?, learnt to assign the input outside the ts argument, but that's
only the
foothills, apparently.
I don't think it's just me this evening. Seems worth a chapter or two
of J wiki or
NuBenchMark or the like...
Thanks for the instructive ticking-off,
Cheers,
Mike
On 16/05/2020 23:43, bill lam wrote:
> Shouldn't assignment like
> b=. , a
> c=. 1{a
> just increase reference count of the mother instead of deep copy?
>
>
> On Sun, May 17, 2020, 6:27 AM Henry Rich <henryhrich at gmail.com> wrote:
>
>> I wouldn't say so. Reshape takes virtually no time/space, but boxing or
>> assigning the reshaped result does. If you do something like
>>
>> +/ @: (,/) y
>>
>> the result of ,/ is never realized and it would be wrong to charge it
>> with time/space not used.
>>
>> Similarly
>>
>> (}. - }:) y
>>
>> the }. and }: create virtual results that are never realized.
>>
>> You need to expand your mental model beyond time/space for a verb, to
>> include time/space for realization when that becomes necessary.
>>
>> Henry Rich
>>
>>
>> On 5/16/2020 1:22 PM, 'Mike Day' via Programming wrote:
>>> Oh... so one needs to, say, assign the result to see the real t/s?
>>>
>>> Thanks,
>>>
>>> Mike
>>>
>>> Sent from my iPad
>>>
>>>> On 16 May 2020, at 17:05, Henry Rich <henryhrich at gmail.com> wrote:
>>>>
>>>> The time/space numbers are telling you that (x $ y) produces a virtual
>> result when it can, while (_2 ]\ y) doesn't (yet). If you use the result
>> immediately, the space saving is real. If you box the result or save it in
>> a name, the value will be realized and the space saving will vanish.
>>>> Henry Rich
>>>>
>>>>> On 5/16/2020 11:14 AM, 'Michael Day' via Programming wrote:
>>>>> Much neater than what I was about to offer, unless Raoul needs to
>> specify the fill,
>>>>> in which case, this alternative rather minimal amendment is worth
>> consideration:
>>>>> ($!._ ~2,~>. at -:@#) i.7
>>>>> 0 1
>>>>> 2 3
>>>>> 4 5
>>>>> 6 _
>>>>>
>>>>> cf
>>>>>
>>>>> _2]\ i.7
>>>>> 0 1
>>>>> 2 3
>>>>> 4 5
>>>>> 6 0
>>>>>
>>>>> Also, the time and space performance _might_ be important for large
>> inputs:
>>>>> ts' $ _2]\ list ' [list =: i.100000
>>>>> 0.000618 1.04986e6
>>>>> ts'($!._ ~2,~>. at -:@#) list'
>>>>> 2.7e_6 2304
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Mike
>>>>>
>>>>>> On 16/05/2020 15:57, 'Rob Hodgkinson' via Programming wrote:
>>>>>> You could try Infix … here with NuVoc link…
>>>>>> https://code.jsoftware.com/wiki/Vocabulary/bslash#dyadic
>>>>>>
>>>>>> x u\ y where x is eg _2 means apply very b to successive pairs
>> (_ for non-overlapping).
>>>>>> _2 ]\ 1 2 3 4 5 6
>>>>>> 1 2
>>>>>> 3 4
>>>>>> 5 6
>>>>>> _2 ]\ 1 2 3 4 5 6 7
>>>>>> 1 2
>>>>>> 3 4
>>>>>> 5 6
>>>>>> 7 0
>>>>>>
>>>>>> _2 <\ 1 2 3 4 5 6
>>>>>> ┌───┬───┬───┐
>>>>>> │1 2│3 4│5 6│
>>>>>> └───┴───┴───┘
>>>>>>
>>>>>> HTH…/Rob
>>>>>>
>>>>>>> On 17 May 2020, at 12:42 am, Raoul Schorer <raoul.schorer at gmail.com>
>> wrote:
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am convinced that this must be trivial, but I wasn't able to find
>> in the documentation how to reshape a list to a table without manually
>> extracting the length.
>>>>>>> in summary, is there a more direct way of doing:
>>>>>>>
>>>>>>> lst =. i. 6
>>>>>>>
>>>>>>> ((2,~2%~#) $ ]) lst
>>>>>>>
>>>>>>> for a list of arbitrary length?
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> Raoul
>>>>>>>
>>>>>>>
>> ----------------------------------------------------------------------
>>>>>>> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>>>>>> ----------------------------------------------------------------------
>>>>>> 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
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the Programming
mailing list