Wow, would not have expected that , Devon :)

After testing a substantially reduced challenge on my laptop (Devon, you have 
some serious metal behind your J installation!)
   idMate1=: 3 : '(2$y)$(>:y){.1'   NB. Explicit and fast
   (10) 6!:2 'idMate1 &.> 9000 '
0.120056
     idMatt1=: (2$])$1{.~>:           NB. Tacit and fast
   (10) 6!:2 'idMatt1 &.> 9000 '
0.11531
     idMatt2=: ,~ $ >: {. 1:             NB. Tacit and slow
   (10) 6!:2 'idMatt2 &.> 9000 '
0.510053

I am guessing that the 1: is the culprit and that these verbs may be used 
rarely enough that they don't get the benefit of special code

idMatt3=: ,~ $ 1{.~ >:                NB. Same as idMatt2 without use of 1:
   (10) 6!:2 'idMatt3 9000 '
0.114926

Thanks for the insight Devon, as I await Roger's clarification if I have 
guessed wrong. :)

Cheers, bob

On 2012-11-20, at 5:12 PM, Devon McCormick wrote:

> Here's what I get for timings for some of these methods:
> 
> NB. Various ways to create ] x ] identity mat.
>   idMat0=: =@:i.
>   idMat1=: 3 : '(2$y)$(>:y){.1'  NB.* faster, scales better
>   idMat2=: ,~ $ >: {. 1:
> 
>   (10) 6!:2 'idMat0 &.> 36000 38000 40000 42000 44000 46000 48000 50000'
> 21.7756
>   (10) 6!:2 'idMat1 &.> 36000 38000 40000 42000 44000 46000 48000 50000'
> 9.55495
>   (10) 6!:2 'idMat2 &.> 36000 38000 40000 42000 44000 46000 48000 50000'
> 23.0792
> 
> If you need a *:5e4 identity matrix, you're in trouble.
> 
> 
> On Tue, Nov 20, 2012 at 6:04 PM, bob therriault <[email protected]>wrote:
> 
>> Devon,
>> 
>> I like that, or another tacit option
>> 
>> idMat1=: ,~ $ >: {. 1:
>>   idMat1 6
>> 1 0 0 0 0 0
>> 0 1 0 0 0 0
>> 0 0 1 0 0 0
>> 0 0 0 1 0 0
>> 0 0 0 0 1 0
>> 0 0 0 0 0 1
>> 
>> Cheers, bob
>> 
>> On 2012-11-20, at 1:33 PM, Devon McCormick wrote:
>> 
>>> I used to have a named verb "idMat" in my own utilities library that was
>>> defined this way:
>>> idMat=: =@:i.
>>> 
>>> but testing this on large arguments led me to formulate this
>>> idMat=: 3 : '(2$y)$(>:y){.1'  NB.* faster and scales better
>>> 
>>> or, the same thing tacitly:
>>> idMat=: (2 $ ]) $ 1 {.~ >:
>>> 
>>> 
>>> On Tue, Nov 20, 2012 at 2:29 PM, Don & Cathy Kelly <[email protected]> wrote:
>>> 
>>>> A key point that dawned on me, after reading all the helpful comments
>> and
>>>> suggestions that have come in, is that I don't need a verb- just a noun
>> - so
>>>>  y=: 2 3 4 2 2 3  (it also works for an n,n array)
>>>> 
>>>> ] u=:=i.# y
>>>> 
>>>> 1 0 0 0 0 0
>>>> 0 1 0 0 0 0
>>>> 0 0 1 0 0 0
>>>> 0 0 0 1 0 0
>>>> 0 0 0 0 1 0
>>>> 0 0 0 0 0 1
>>>> 
>>>> and I can use   u*y    for different 'y''s ( as long as the # is the
>> same)
>>>> to get the desired diagonal  elements with off diagonal elements  0
>>>> I want this because I want to add to the diagonal elements  of a matrix.
>>>> This is for a Newton Raphson based power system load flow.
>>>> 
>>>> Thanks to all,
>>>> Don
>>>> 
>>>> 
>>>> 
>>>> On 20/11/2012 8:24 AM, Roger Hui wrote:
>>>> 
>>>>> http://www.jsoftware.com/**jwiki/Essays/Identity%20Matrix<
>> http://www.jsoftware.com/jwiki/Essays/Identity%20Matrix>: 34 different
>> ways
>>>>> to generate the identity matrix of order n; the first is =@i. and the
>> last
>>>>> is _&q:@p:@i.
>>>>> ------------------------------**------------------------------**
>>>>> ----------
>>>>> For information about J forums see
>> http://www.jsoftware.com/**forums.htm<http://www.jsoftware.com/forums.htm>
>>>>> 
>>>>> 
>>>> 
>> ------------------------------**------------------------------**----------
>>>> For information about J forums see
>> http://www.jsoftware.com/**forums.htm<http://www.jsoftware.com/forums.htm>
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> Devon McCormick, CFA
>>> ^me^ at acm.
>>> org is my
>>> preferred e-mail
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>> 
> 
> 
> 
> -- 
> Devon McCormick, CFA
> ^me^ at acm.
> org is my
> preferred e-mail
> ----------------------------------------------------------------------
> 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