And another, but it's kind of slow.

copy5=: 4 : ',./>x{.!.(<y) '''''


Oleg Kobchenko wrote:

Here is another

  copy4=: (* {:@$) $"1 ]

+--+------------------+---------------------+
|  |A                 |B                    |
+--+------------------+---------------------+
|0 | 0.00101577 526144| 0.00291462 1.05043e6|
|1 | 0.00053694 525632| 0.00103952    787776|
|2 |0.000362057 523520| 0.00171139 1.04192e6|
|2a| 0.00118339 528384| 0.00272772 1.05267e6|
|3 | 0.00150857 526720| 0.00523586 1.05101e6|
|3a|0.000719645 526144| 0.00256317 1.05043e6|
|4 | 6.95619e_5 263552|0.000824127    525696|
+--+------------------+---------------------+

copy0=: 13 : ',./ > x $< y'
copy1=: ([ (* $ [EMAIL PROTECTED]) {:@[EMAIL PROTECTED]) {"1 ]
copy2=: 4 : '> ,.&.>/ ,.~&.>^:(I.|.#:x) <y'
copy2a=: 4 : '(x*{:$y) {."1 ,.~^:(>.2^.1>.x) y'
copy3=: ,/@(#,:)&.|:
copy3a=: [:,./ (#,:)
copy4=: (* {:@$) $"1 ]

seriesA=: 10 10 $'abcd'
seriesB=: 20 10 $'abcd'

  2000 (copy0 -: copy4) seriesA
1

--- "R.E. Boss" <[EMAIL PROTECTED]> wrote:

Some alternatives:

  copy3=: ,/@(#,:)&.|:
  copy3a=: [:,./ (#,:)

  20000 (copy2a-:copy3a) b
1
  20000 (copy2a-:copy3) b
1

  ts '20000 copy2a b'
0.00030425237 396992
  ts '20000 copy3 b'
0.00071625735 264064    NB. slower by a factor 2
  ts'20000 copy3a b'
0.00035746269 263680
R.E. BOSS


-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Roger Hui
Verzonden: zaterdag 18 maart 2006 18:33
Aan: Programming forum
Onderwerp: Re: [Jprogramming] Different(and maybe more elegant) ways of
copying?

Variation on the copy2 theme:  overshoot and then crop.

  copy2a=: 4 : '(x*{:$y) {."1 ,.~^:(>.2^.1>.x) y'
  2000 (copy -: copy2a) b
1
  ts '2000 copy2a b'
0.000196394 28352



----- Original Message ----- From: "Roger Hui" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Saturday, March 18, 2006 8:59 AM
Subject: Re: [Jprogramming] Different(and maybe more elegant) ways of
copying?

Yet another alternative is powers of the monad ,.~ .
If x is a power of 2 then the method is really short and fast.
If x is not a power of 2 then more code is required.

  (1024 copy b)-: ,.~^:10 b
1

  ts=: 6!:2 , 7!:[EMAIL PROTECTED]
  ts '1024 copy b'
0.000481905 17920
  ts ',.~^:10 b'
8.63238e_5 13248

  copy2=: 4 : '> ,.&.>/ ,.~&.>^:(I.|.#:x) <y'
2000 (copy -: copy1) b
1
  2000 (copy -: copy2) b
1

  ts '2000 copy b'
0.000918273 25664
  ts '2000 copy1 b'
0.000234387 41984
  ts '2000 copy2 b'
0.000215949 29056



----- Original Message ----- From: "Roger Hui" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Saturday, March 18, 2006 8:47 AM
Subject: Re: [Jprogramming] Different(and maybe more elegant) ways of
copying?

An alternative is to use indexing:

  copy1=: ([ (* $ [EMAIL PROTECTED]) {:@[EMAIL PROTECTED]) {"1 ]
  1000 (copy -: copy1) b
1



----- Original Message ----- From: "June Kim" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Saturday, March 18, 2006 8:32 AM
Subject: [Jprogramming] Different(and maybe more elegant) ways of copying?

  b=. 2 2 $'abcd'
  copy=.13 : ',./ > x $< y '   NB. copies the box side by side
  3 copy b
ababab
cdcdcd
  4 copy b
abababab
cdcdcdcd

Maybe, I could use under(as in  13 : ',./ (x&$)&.< y') but the final
form isn't tacit, which is not a big problem; however I'm interested
in knowing other possibilities.

Any suggestions?


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

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



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.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

Reply via email to