On 6/23/2010 11:57 PM, P Kishor wrote: > > Thanks Chris, thanks so much. After using Perl for a while, just when > I thought I started getting a hang of it, in comes PDL. Its like > learning a brand new language. Your and others' answers to all my > novice questions really help in learning this new language. > > I am writing a super-beginners manual, really documenting my own baby > steps. Hopefully, it will become something I can share with others, > and someone else may benefit from it as well.
Great! > A few specific responses below. > > On Wed, Jun 23, 2010 at 9:23 PM, Chris Marshall<[email protected]> wrote: >> On 6/23/2010 8:43 PM, P Kishor wrote: >>> >>> That seems the various methods don't seem to work analogously. For >>> example, $a->reshape() changes $a, but $b->dummy() doesn't change $b. >> >> I believe reshape works in place. I would prefer that it >> work otherwise unless inplace is requested. You are right >> about the inconsistency.... BTW, I think I see your problem from the '...errors abound' thread. dummy() has two required args as a sub (the piddle and the dimension) and one required arg as a method (the dimension). E.g.: dummy($pdl, 0) # good sub call $pdl->dummy(2) # good call as method $pdl->dummy # ...lots of errors!! > Yes, there are a few more. For example, in FastRaw, the writefraw command is > > writefraw($pdl,"fname"); > > while in FlexRaw, the analogous writeflex command is > > $hdr = writeflex($file, $pdl1, $pdl2,...) > >> From the docs, FlexRaw is made to be a smarter version of FastRaw, but > reverses the order of $pdl and filename. Be sure to keep a list. At the least, the docs ought to point out the differences since it can trip up beginners. > There are others as well. > >>> [ >>> [0 1 x] >>> [2 3 x] >>> [4 5 x] >>> [0 0 x] >>> ] >>> >>> Where 'x' is a custom value. For example, I want a 0 for every 'x', or >>> I want a random number between 20 and 30 for every 'x'. How do I do >>> that? I know there is the 'random' method. But that creates a new >>> piddle with random values between 0 and 1. So, I tried a different >>> tactic >> >> $x = $a((2),:) >> $x .= floor($x->random * 10 + 20) > > Ok. So the above is very interesting. $x is just a reference to the > 3rd column in $a (the column marked with 'x'). Then you modify $x, > which modifies $a. > > So, is this the normal idiom for wanting to modify a part of a piddle? > Create a reference to the part you want to modify. That reference is a > piddle. Then, modify that reference piddle which in turn will modify > the referent piddle. slicing (with or without NiceSlice syntax support) is the standard way to do vectorized assignments in PDL. The fact that there is data flow back to the original piddle is one of the most convenient and powerful PDL features. Using a slice as an alias into a piddle can clean up your code and simplify programming. > What if I wanted to apply a custom function to $x? How would I apply > my_func() to $x? $x is like a pointer to the slice of locations. You can just read the values there (using the $x 'alias'), do the computation and assign the result back to the original locations with the .= assignment ( $x .= sin($x) ). >> >> int() is a perl built-in function. See perldoc -f int for >> what it does. HINT: it doesn't know anything about piddles. >> >>> Wha!!! What happened there? Why does $a = $a * 100 multiply every >>> element in $a by 100, but int($a) converts $a to 0? We should use the word integer in the descriptions of floor and ceil so that pdldoc or help can find them. I might be possible to overload the int routine since it is the source of confusion... --Chris _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
