I guess this is worth mentioning here:
https://code.jsoftware.com/wiki/Vocabulary/SpecialCombinations#Assignments_In_Place_.28AIP.29

Assignments are done in place if you use a specific form recognised by the
interpreter.

If you do not assign the result, or use it in a longer sentence, it will
not be recognised, copying over the entire array, rather than updating a
single element.

Best regards,

Jan-Pieter


On Sun, Oct 25, 2020, 11:56 Hauke Rehr <[email protected]> wrote:

> I’d expect it’s allocation and copying.
> And as you execute it in the repl, there’s no compiler involved.
> Rather, the JE “knows” it’s dealing with a single element only.
>
> Am 25.10.20 um 11:52 schrieb pietdion:
> > Ok.  Thanks.
> > What explains the huge time difference?
> > Does the compiler somehow “know” it’s only dealing with one element in
> the in place assignment?
> >
> >> On 25 Oct 2020, at 7:25 pm, Lippu Esa <[email protected]> wrote:
> >>
> >> Hello
> >>
> >> It is not expensive if an in place assignment can be made:
> >>
> >> a=.i.1e7
> >>   ts '(_999+1000{a) 1000 }a'
> >> 0.07655064 134219392
> >>   ts 'a=.(_999+1000{a) 1000 }a'
> >> 0.00000177 1792
> >>
> >> Esa
> >>
> >> -----Original Message-----
> >> From: Programming <[email protected]> On Behalf
> Of pietdion
> >> Sent: Sunday, October 25, 2020 9:58 AM
> >> To: Programming forum <[email protected]>
> >> Subject: [Jprogramming] Adding constant to a specified element of a
> vector
> >>
> >> What is the best way to add, say,  scalar x to component i of vector y?
> >>
> >> One way is (x + i{y) i} y
> >> But this seems clumsy/expensive.
> >> Is there a cleaner/more efficient way?
> >> ----------------------------------------------------------------------
> >> For information about J forums see
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&amp;data=04%7C01%7C%7C846dab3174224b01be8508d878bbba64%7C5090e269dbea4e98a9aa3e70be5890f7%7C0%7C0%7C637392094979944278%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=q2LAzVmaMgPTY86v0%2FpBEascSJSwOoSYOMbgwC%2FxQUQ%3D&amp;reserved=0
> >>
> >> Tämän viestin sisältö liitteineen on luottamuksellinen ja tarkoitettu
> vain sen vastaanottajalle. Jos et ole viestin tarkoitettu vastaanottaja,
> pyydämme sinua poistamaan viestin liitteineen ja sen jälkeen ilmoittamaan
> asiasta välittömästi viestin lähettäjälle. Viestin sisällön paljastaminen,
> kopioiminen tai muu käyttö on kielletty.
> >>
> >> The contents of this message and any attachments are confidential and
> meant solely for the intended recipient. If you are not the intended
> recipient, we kindly ask that you delete the message and its attachments,
> and immediately notify the sender of the email. Disclosing, copying or
> using the contents of the message is strictly prohibited.
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
> --
> ----------------------
> mail written using NEO
> neo-layout.org
>
> ----------------------------------------------------------------------
> 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