Post Reply 
RPL mini-challenge: Create an anti-Identity Matrix
05-13-2018, 08:48 PM
Post: #27
RE: RPL mini-challenge: Create an anti-Identity Matrix
(05-12-2018 09:07 PM)Gerald H Wrote:  Very good, 3298.

Your programme is faster for reals, but if you change the programme to

\<<
0 1 PICK3 NDUPN 1. + \->ARRY
OVER 1. - NDUPN ROW\->
SWAP DUP 2. \->LIST RDM
\>>

slower for integer matrix than my programme.
That can be fixed by using \->LIST in place of \->ARRY and the pair of commands \->LIST AXL in place of ROW\->. That speeds it up from around 1.38_s to around 1.20_s. The same change to the real number version would slow it down, though - by about 0.12_s.

---

I also put some finishing touches like a size parameter into pier4r's program, including slight optimizations (loop counter value range, shuffling the size parameter through the stack intelligently). I avoided UserRPL loops in my own solution because I expected them to be too slow to be of any use (perhaps I'm too used to the speed of SysRPL, and even there I squeeze every last bit of performance out of the loop structure with e.g. runstream shenanigans) - but it seems that handling larger elements (like my matrix rows and eventually the wrongly dimensioned matrix) isn't actually better, whereas in this program the large object doesn't even exist up to the last command. The internal structure of real/complex number matrices (which enforces same-size elements) allows for a very efficient implementation of \->ARRY for that argument type too.
Code:
\<<
  2. OVER START
    0. 1. ROT NDUPN
  NEXT
  0. SWAP
  DUP 2. \->LIST \->ARRY
\>>
Timing: 0.18306_s for the real number version, 0.645375_s for the integer version (drop the period of the 0. and 1. occurences for that). Averages over 20 runs on input 30., as with my previous measurements.

(05-13-2018 07:32 PM)pier4r Wrote:  Say I have 5 objects on the stack and I want to duplicate them, without using an explicit loop (surely the command internally will have a loop, like NDUPN). Is it possible?
Sounds like NDUP, but I don't think it's worth the effort here. You could make 2 matrix rows from 1, but you cannot make N rows from 1 row without putting it into your own loop (like the one that currently houses NDUPN). You'd also have to retain the code for generating a single row so NDUP has something to duplicate.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: RPL mini-challenge: Create an anti-Identity Matrix - 3298 - 05-13-2018 08:48 PM



User(s) browsing this thread: 10 Guest(s)