I believe that optimization is happening behind the scenes.  See the following 
tests actually timing indexed assignment, first without replacing the original 
array and then replacing the original array:

    ts=: 6!:2 , 7!:2@]
    a=:i.1e6
    ts'_777 (2 9 43556)}a'
0.0238083 8.39078e6
    ts'a=:_777 (2 9 43556)}a'
1.00571e_5 2432

On 1/6/2012 9:54, Blake McBride wrote:
> Greetings,
>
> Going through J I found that:
>
>     x=:1+i.5
>     x
> 1 2 3 4 5
>     44 (2}) x
> 1 2 44 4 5
>     x
> 1 2 3 4 5
>
> It seems that J doesn't actually make an indexed assignment.  It seems
> more like it creates a copy of the array with the specified
> modifications.  This is actually quite shocking.  Index assignment to
> a very large array in most languages is a very fast and simple
> operation.  It is also very memory efficient.  Creating a modified
> copy of a very large array has a much, much greater time and space
> cost.  Further, multiplying this (unnecessary) cost over a great
> number of operations can drastically (and unnecessarily) affect
> performance negatively.
>
> Am I missing something here?
>
> Thanks.
>
> Blake McBride
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to