Re: Performance of matrix arithmetic in Raku
Hi, raku doesn't have matrix operations built into the language, so you're probably refering to modules out of the ecosystem? Math::Matrix seems to have everything implemented in pure raku, which you should not expect to outperform pure python without some optimization work. Math::libgsl::Matrix is a NativeCall wrapper around the gnu scientific library, which you would expect to be fast whenever big tasks can be implemented as a single call into the library, and a bit slower whenever data has to go back and forth between raku and the library, though without measuring first, I can't say anything about the actual performance numbers. It would be quite important to see whether the "python performance of matrix arithmetic" refers to NumPy, which i think has most of its code implemented in fortran, which i would naively expect to outperform code written in C. Other than that, there's of course the @ operator in python which just does matrix multiplication i think? You would have to look at CPython to see how that is implemented. On top of that, you'll of course also have to try the code in question with PyPy, which is very good at making python code go fast, and perhaps with Cython? Hope this doesn't add too many more questions, and actually answers a thing or two? - Timo On 09/02/2021 02:18, Parrot Raiser wrote: There's a post online comparing Python's performance of matrix arithmetic to C, indicating that Python's performance was 100x (yes, 2 orders of magnitude) slower than C's. If I understand it correctly, matrix modules in Raku call GNU code written in C to perform the actual work. Does that make Raku significantly faster for matrix work, which is a large part of many contemporary applications, such as AI and video manipulation? If it does, that could be a big selling point.
Re: "put" vs "say"
put is meant for machines, while say is meant for humans. this is implemented by having say call the .gist method and put calling the .Str method. Try using say and put on a list of a thousand elements or more and you'll see what I mean. HTH - Timo On 21/10/2018 18:29, Parrot Raiser wrote: > "put" and "say" seem to be redundant, but I'm sure there's a good > reason for having 2 output commands. > > Would anyone care to comment on how they differ and why, or point to > an explanation?
Re: "temp" vs "my"
you can refer to the outer $v as OUTER::('$v'), that ought to help :) On 03/10/2018 08:10, yary wrote: > Reading and playing with https://docs.perl6.org/routine/temp > > There's an example showing how temp is "dynamic" - that any jump > outside a block restores the value. All well and good. > > Then I thought, what if I want a lexical temporary value- then use > "my"- and this is all well and good: > > my $v = "original"; > { > my $v = "new one"; > start { > say "[PROMISE] Value before block is left: `$v`"; > sleep 1; > say "[PROMISE] Block was left while we slept; value is still > `$v`"; > } > sleep ½; > say "About to leave the block; value is `$v`"; > } > say "Left the block; value is now `$v`"; > sleep 2; > > Then I thought, well, what if I want to initialize the inner $v with > the outer $v. > > my $v = "original"; > { > my $v = $v; # "SORRY! Cannot use variable $v in declaration to > initialize itself" > say "inner value is $v"; > $v= "new one"; > ... > > Gentle reader, how would you succinctly solve this contrived example? > Anything you like better than this? > > my $v = "original"; > given $v -> $v is copy { > say "inner value is $v"; # "original", good > $v= "new one"; > > > -y
Re: Is negative lookbehind behaving here?
Yes, you've encountered a bug. It's got these two tickets: https://rt.perl.org/Public/Bug/Display.html?id=124898 https://rt.perl.org/Public/Bug/Display.html?id=131964 I've got a branch in nqp and rakudo that I'll merge very soon that fixes both of these bugs. Until then you can switch $ and ^, but when the version lands that fixes the bug, that'll "misbehave" again. I think having ^|$ in the before/after assertions, i.e. literally match either the beginning or the end, should work with pre-fix and post-fix versions, as you cannot have text after the end of the string for example. Hope that helps! - Timo On 04/05/18 07:38, yary wrote: > I want to match something anywhere but at the end of a string in one > example, or anywhere but at the start of a string in another example. > The "except at start" one has me stumped. Not sure if it's me or if > I've tickled a bug. > > perl6 --version > This is Rakudo Star version 2018.01 built on MoarVM version 2018.01 > implementing Perl 6.c. > > # Match all but at end- this works as I like > > 'abcd' ~~ m/.+/ > 「abc」 > > # Match all but at start- this puzzles me, 'a' is after the start of > string but still matches > > 'abcd' ~~ m/.+/ > 「abcd」 > > # This is a workaround > > 'abcd' ~~ m/.+/ > 「bcd」 > > Using a perl5 debugger session, roughly translated negative > lookbehind/lookahead work as I expect. > > DB<1> p 'abcd' =~ /(.+(?!$))/ > abc > DB<2> p 'abcd' =~ /((? bcd > > -y
Re: Naming debate- what's the location for it?
FWIW, Jupyter can also be used with Perl 6, though surely we ought to advertise it more broadly.
Re: Is this a bug?
On 19/09/16 16:02, Aaron Sherman wrote: > I'm guessing that what you meant was "say as a function was what I > meant to > use there." In which case: > > say for reverse lines > > or > > for reverse lines { say } > > These are both valid ways of asking for each element of the iterable > thing returned from lines to be printed with a newline. Watch out, this needs to read say $_ otherwise you would get an error message: Unsupported use of bare "say"; in Perl 6 please use .say if you meant $_, or use an explicit invocant or argument, or use to refer to the function as a noun
Re: This seems to be wrong
On 19/09/16 15:56, Aaron Sherman wrote:> You can also use map, but it's slightly clunkier: > > "for @inputs.map: .Int -> $i { ... }" This also needs to have "*.Int" or "{ .Int }" otherwise you'll pass $_.Int as the argument to map rather than telling map to call .Int on things.
Re: ADT and GADT (a partial implementation)
On 21.03.2013 17:45, Carl Mäsak wrote: [...] Using hashes and subclasses: https://gist.github.com/masak/5213423 Using classes and subclasses: https://gist.github.com/masak/5213563 [...] I came up with a prototype to create those classes like in the second gist automatically by supplying a haskell-like declaration of the data type. (skip to the end of the mail for the code) Here's what it can do: my %res = create_adt(Tree = Branch Tree left, Tree right | Leaf Str storage); my \Tree = %resTree; # create the tree with named parameters my $t = Tree.new-branch( :left(Tree.new-branch( :left(Tree.new-leaf(:storage(1))), :right(Tree.new-leaf(:storage(2), :right(Tree.new-leaf(:storage(3; # create the tree with positional arguments my $t2 = Tree.new-branch( Tree.new-branch( Tree.new-leaf(1), Tree.new-leaf(2)), Tree.new-leaf(3)); say $t2.gist; # outputs: (reformatted for email) # Tree.new-branch( #left = Tree.new-branch( # left = Tree.new-leaf(storage = 1), # right = Tree.new-leaf(storage = 2)), #right = Tree.new-leaf(storage = 3)) my \Branch = %resBranch; my \Leaf = %resLeaf; # haskell-style map for the tree sub treemap($t, *code) { given $t { when Branch { return Tree.new-branch( treemap($t.left, code), treemap($t.right, code)) } when Leaf { return Tree.new-leaf(code($t.storage)) } } } say treemap($t2, * * 10).gist; # outputs: # Tree.new-branch( #left = Tree.new-branch( # left = Tree.new-leaf(storage = 10), # right = Tree.new-leaf(storage = 20)), #right = Tree.new-leaf(storage = 30)) There are currently some limitations: 1) there is no compiler support for checking that all cases have been covered, but as masak mentioned, I'm confident this can be done with a macro, because those run at compile-time basically. 2) you cannot yet use Leaf and Branch for declaring multi subs, because the symbols are not there at compile-time, but see below. 3) I have not yet figured out how to properly do pattern matching/decomposing, so the names left, right and storage need to be supplied in the definition unlike in haskell. 4) I'm not sure how to do type parameters (think data Tree A = ...), because perl6 has only parametric roles, not parametric classes. One thing rakudo needs to get for this to be much smoother is support for the sub EXPORT to return a hash-like of symbols that will be installed in the caller's package. This would make Tree, Branch and Leaf available as compile-time symbols, so that multi methods/subs can use them for dispatch. I mean to turn this into a module for the perl6 modules list some time in the Future. Finally, here's the runnable code. Feel free to play around with it and tell me on this mailing list or the IRC channel what further problems (or even solutions!) you find. https://gist.github.com/timo/5226114 Have Fun! - Timo