Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: how to self define a operator

by vr (Curate)
on Oct 22, 2019 at 10:26 UTC ( [id://11107842]=note: print w/replies, xml ) Need Help??


in reply to how to self define a operator

It's not clear how hypothetical operator should behave in case of multi-D slices. Your "reshape" solution simply fills new container with existing data regardless of row/column/plane boundaries, just like pouring liquid from one vessel to another of different shape, under normal gravity, and it's only exact volume that matters. Should 2-D matrix be perhaps transposed? Anyway, existing facilities can solve these tasks without repeating a slice expression twice -- if that's what you want to avoid.

E.g., for "liquid data to fill new vessel", both RHS and LHS piddles can be flattened, and since the latter is virtual, changes will flow to original multi-D piddle:

pdl> p$p = sequence 2,5 [ [0 1] [2 3] [4 5] [6 7] [8 9] ] pdl> p$t3 = $t2 = ($t1 = zeroes 4,3) .= -1 [ [-1 -1 -1 -1] [-1 -1 -1 -1] [-1 -1 -1 -1] ] pdl> $t1(0:2,1:2)->(;_) .= $p(0:1,1:3)->(;_); p$t1 [ [-1 -1 -1 -1] [ 2 3 4 -1] [ 5 6 7 -1] ] pdl> $t2(0:2,1:2)->flat .= $p(0:1,1:3)->flat; p$t2 # the same [ [-1 -1 -1 -1] [ 2 3 4 -1] [ 5 6 7 -1] ] pdl> $t3(0:2,1:2) .= $p(0:1,1:3)->transpose; p$t3 [ [-1 -1 -1 -1] [ 2 4 6 -1] [ 3 5 7 -1] ] pdl>

Replies are listed 'Best First'.
Re^2: how to self define a operator
by toothedsword (Sexton) on Oct 22, 2019 at 15:02 UTC
    Thanks! Your answer is much better than what my want! I have seen some guys using so many clump and dummy(0,1) making the code very ugly and obscure. Your method is very good!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11107842]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-25 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found