We introduced Rcpp 0.10.0 with a number of very nice new features a
few days ago, and the activity on the rcpp-devel mailing list has been pretty
responsive which is awesome.
But because few things beat a nice example, this post tries to build some more excitement. We will illustrate how Rcpp attributes
makes it really easy to add C++ code to R session, and that that code is as easy to grasp as R code.
Our motivating example is everybody's favourite introduction to Monte Carlo simulation: estimating . A common method uses the fact
the unit circle has a surface area equal to . We draw two uniform random numbers x and y, each between zero
and one. We then check for the distance of the corresponding point (x,y) relative to the origin. If less than one (or equal),
it is in the circle (or on it); if more than one it is outside. As the first quadrant is a quarter of a square of area one, the area of
the whole circle is -- so our first quadrant approximates over four. The following figure, kindly borrowed from Wikipedia
with full attribution and credit, illustrates this:
Now, a vectorized version (drawing N such pairs at once) of this approach is provided by the following R function.
And in C++ we can write almost exactly the same function thanks the Rcpp sugar vectorisation available via Rcpp:piR <- function(N) x <- runif(N) y <- runif(N) d <- sqrt(x^2 + y^2) return(4 * sum(d < 1.0) / N)
Sure, there are small differences: C++ is statically typed, R is not. We need one include file for declaration, and we need one instantiation of the#include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] double piSugar(const int N) RNGScope scope; // ensure RNG gets set/reset NumericVector x = runif(N); NumericVector y = runif(N); NumericVector d = sqrt(x*x + y*y); return 4.0 * sum(d < 1.0) / N;
RNGScope object to ensure random number draws remain coordinated between the calling R process and the C++ function
calling into its (compiled C-code based) random number generators. That way we even get the exact same draws for the same seed.
But the basic approach is identical: draw a vector x and vector y, compute the distance to the origin and then
obtain the proportion within the unit circle -- which we scale by four. Same idea, same vectorised implementation in C++.
But the real key here is the one short line with the [[Rcpp::export]] attribute. This is all it takes (along with
sourceCpp() from Rcpp 0.10.0) to get the C++ code into R.
The full example (which assumes the C++ file is saved as piSugar.cpp in the same directory) is now:
and it does a few things: set up the R function, source the C++ function (and presto: we have a callable C++ function just like that), compute two simulations given the same seed and ensure they are in fact identical -- and proceed to compare the timing in a benchmarking exercise. That last aspect is not even that important -- we end up being almost-but-not-quite twice as fast on my machine for different values of#!/usr/bin/r library(Rcpp) library(rbenchmark) piR <- function(N) x <- runif(N) y <- runif(N) d <- sqrt(x^2 + y^2) return(4 * sum(d < 1.0) / N) sourceCpp("piSugar.cpp") N <- 1e6 set.seed(42) resR <- piR(N) set.seed(42) resCpp <- piSugar(N) ## important: check results are identical with RNG seeded stopifnot(identical(resR, resCpp)) res <- benchmark(piR(N), piSugar(N), order="relative") print(res[,1:4])
N.
The real takeaway here is the ease with which we can get a C++ function into R --- and the new process completely takes care of passing
parameters in, results out, and does the compilation, linking and loading.
More details about Rcpp attributes are in the new vignette. Now enjoy the .
Update:One somewhat bad typo fixed.
Update:Corrected one background tag.
I recently wrote about tools to handle archives conveniently. If you just have to handle
compressed text files, there are some widely known shortcut commands
to mimic common commands on files compressed with a specific
compression format.
| gzip | bzip2 | lzma | xz | |
|---|---|---|---|---|
| cat | zcat | bzcat | lzcat | xzcat |
| cmp | zcmp | bzcmp | lzcmp | xzcmp |
| diff | zdiff | bzdiff | lzdiff | xzdiff |
| grep | zgrep | bzgrep | lzgrep | xzgrep |
| egrep | zegrep | bzegrep | lzegrep | xzegrep |
| fgrep | zfgrep | bzfgrep | lzfgrep | xzfgrep |
| more | zmore | bzmore | lzmore | xzmore |
| less | zless | bzless | lzless | xzless |
zcat
command is part of the gzip package and the
xzfgrep command is part of the xz-utils package.
But despite this matrix is quite easy to remember, the situation has a
few drawbacks:
lzma-compressed files as lzma is
xz s predecessor)zcat and the other cat variants can t even recognize
non-compressed files and throw an error instead of just showing their
contents.lzcat and friends are for
lzip-based compression as xzcat can handle
lzma-compressed files anyway.zcat, zcmp, zdiff,
zgrep, zegrep, or zfgrep and it
works independently of what compression method has been used
if any or if there are different compression types
mixed in the parameters to the same command:
$ zfgrep foobar bla.txt fnord.gz hurz.xz quux.lz bar.lzmaEspecially if you use logrotate and let
logrotate compress old logs, it s very comfortable that
one command suffices to concatenate all the available logfiles,
including the current uncompressed one:
$ zcat /var/log/syslog*Additionally, zutils versions of these tools also support
lzip-compressed files.
The zutils package is available in Debian starting with
Wheezy and in Ubuntu since Oneiric. When being installed, it replaces
the original z* utilities from the gzip package
by diverting them away.
The only drawback so far is that there neither a
zless nor a zmore utility from the
zutils project, so zless bla.txt fnord.gz hurz.xz quux.lz
bar.lzma will not work as expected even after
installing zutils as it is still the one from the gzip package and hence it will show you just the first two files in
plain text, but not the remaining ones.
Github now provides native hook for Weblate. This means that all you need to do to link these two together is to enter URL of your Weblate installation and you are done.
This was actually my first code in Ruby and I don't think I will start to like it, Python still looks nicer to me :-). However it was not that hard as I expected and I've even contribute (simple) testcase for this service.
Filed under: English Weblate 3 comments Flattr this!
Yesterday I was discussing in an online board how to break a decision deadlock in life. There are real deadlocks, but I don t think they are very frequent most of the time, doing a pros and cons analysis is enough to decide what to do. Sometimes our judgement is impaired by lack of objectivity or by our inability to see things from a different point of view (it s hard to think straight when everything seems to be falling apart around you); talking to a friend or relative can help in these situations.
But there are times when nothing helps. When you are really stuck and nothing seems to break the deadlock. At these times I give it one or two days, sleep on the issue and if I cannot come up with a decision I assume the alternatives are equivalent to me and just flip a coin.
Of course, this will do if you can postpone the decision, giving yourself (and your inner self) time to decide on a course-of-action. But is there some way to speed up the process? During the discussion, someone came up with a rather smart quote by Rothstein character in Boardwalk Empire TV series:
Flip a coin. When it s in the air, you ll know what side you re hoping for.I found it an interesting way to give your inner self an ultimatum: decide or luck will decide instead. I ve never did it like that, for I would not flip a coin unless it s my last resort. Being such a clever psychological idea, I doubted it originated in the TV series itself, so I went on pursue of the original idea. I found a Danish poet and mathematician called Piet Hein, who wrote a poem about it circa 1969:
A PSYCHOLOGICAL TIP Whenever you re called on to make up your mind,And also, there are a Donald Duck comic called Flip Decision circa 1953 that introduces Flipism philosophy, which supports a rather radical anecdotal variant: make all decisions by flipping a coin. Piet Hein or Rothstein character idea is much better than Flipism, of course. Does anyone knows any older sources of the same idea?
and you re hampered by not having any,
the best way to solve the dilemma, you ll find,
is simply by spinning a penny.
No not so that chance shall decide the affair
while you re passively standing there moping;
but the moment the penny is up in the air,
you suddenly know what you re hoping.
This was a good year for plums in the garden, both for the yellow plums and
for the Italian prunes - enough so that it took some doing to figure out what
to do with them all. Since I'm not in a hurry to set up a still and make
slivovic, and you can only pawn so many plums off on friends and neighbors,
I had on the order of 15 pounds of Italian prunes to dispense with.
With our change of diet to eliminate extra carbs, Patty and I have both been
experimenting with reduced-carb desserts in the kitchen. And I've always
been fond of central European (e.g., German) desserts, which tend to be
sweetened much more lightly than American equivalents. Indeed, my earliest
impression of "coffee cake" comes from the home of an elderly couple who
were friends of the family, who served a delicious plum cake in their home.
She was from Bavaria, so I guess she probably wouldn't have called it
Zwetchgendatschi like the Austrians do (if they even really call it that; I
have my suspicions that this is a made-up name designed to poke fun at the
foreigners). Maybe she would have called it Pflaumenkuchen. The Internet
calls it "Polish plum
cake".
Whatever you call it, it's tasty, and I aimed to recreate it at home. The
plums are now nearly a month gone, but after multiple iterations the cake
turned out well enough that I feel compelled to share it with the Internet.
Since we have friends who are dairy-intolerant, this particular recipe is
tailored to be low-carb and dairy-free. It doesn't lose anything in the
taste for being made with a restricted set of ingredients. The original
recipe did call for a streusel, and a non-dairy streusel is pretty pointless
so this recipe simply omits it.
Metric cooks, avert your eyes. ;)
[edit: the Internet is bad at me for my badly spelled german. Spelling corrected. ;)]Lightly coat an 8"x8" pan with cooking spray. Heat oven to 350 degrees. In medium bowl, combine flour, baking powder, salt and Steviva. Add grapeseed oil, milk and egg. Beat at medium speed 4 minutes. Pour batter into prepared pan. Place plums on top, cut side up, pushing down slightly into batter. Sprinkle cloves over the plums. Bake about 50 minutes or until a toothpick tests clean. Let the cake cool in the pan so the plum juices will be reabsorbed to create a moist cake. Sprinkle with confectioners' sugar, if desired, and cut into 16 squares.
- 1 c almond flour
- 1 tsp baking powder
- tsp salt
- c Steviva blend
- 3 tbsp grapeseed oil
- c milk
- 1 large egg
- 12 fresh plums, pitted and halved
- tsp cloves
This was a good year for plums in the garden, both for the yellow plums and
for the Italian prunes - enough so that it took some doing to figure out what
to do with them all. Since I'm not in a hurry to set up a still and make
slivovic, and you can only pawn so many plums off on friends and neighbors,
I had on the order of 15 pounds of Italian prunes to dispense with.
With our change of diet to eliminate extra carbs, Patty and I have both been
experimenting with reduced-carb desserts in the kitchen. And I've always
been fond of central European (e.g., German) desserts, which tend to be
sweetened much more lightly than American equivalents. Indeed, my earliest
impression of "coffee cake" comes from the home of an elderly couple who
were friends of the family, who served a delicious plum cake in their home.
She was from Bavaria, so I guess she probably wouldn't have called it
Zwetchgendatschi like the Austrians do (if they even really call it that; I
have my suspicions that this is a made-up name designed to poke fun at the
foreigners). Maybe she would have called it Pflaumkuchen. The Internet
calls it "Polish plum
cake".
Whatever you call it, it's tasty, and I aimed to recreate it at home. The
plums are now nearly a month gone, but after multiple iterations the cake
turned out well enough that I feel compelled to share it with the Internet.
Since we have friends who are dairy-intolerant, this particular recipe is
tailored to be low-carb and dairy-free. It doesn't lose anything in the
taste for being made with a restricted set of ingredients. The original
recipe did call for a streusel, and a non-dairy streusel is pretty pointless
so this recipe simply omits it.
Metric cooks, avert your eyes. ;)
Lightly coat an 8"x8" pan with cooking spray. Heat oven to 350 degrees. In medium bowl, combine flour, baking powder, salt and Steviva. Add grapeseed oil, milk and egg. Beat at medium speed 4 minutes. Pour batter into prepared pan. Place plums on top, cut side up, pushing down slightly into batter. Sprinkle cloves over the plums. Bake about 50 minutes or until a toothpick tests clean. Let the cake cool in the pan so the plum juices will be reabsorbed to create a moist cake. Sprinkle with confectioners' sugar, if desired, and cut into 16 squares.
- 1 c almond flour
- 1 tsp baking powder
- tsp salt
- c Steviva blend
- 3 tbsp grapeseed oil
- c milk
- 1 large egg
- 12 fresh plums, pitted and halved
- tsp cloves
The last week was quite productive as I was on vacation and at home town but sadly I
couldn't complete this post so again merging the work with this week but this week ain't
much productive as I was tired from journey back and didn't get enough time to recover.
So here it goes.
Debian Related
| Publisher: | |
| Copyright: | 1998 |
| Printing: | May 2001 |
| ISBN: | 0-7434-1196-X |
| Format: | Mass market |
| Pages: | 376 |
As some may have noticed, Google launched something that is unusual for the company: A game. A mobile alternate reality game, to be precise. See allthingsd article for a bit more information. In my opinion this game is most interesting to people who are mildly interested in geo-caching. You spend most of the gaming time either looking for the right portals (geo-location that is an interesting place for one reason or another, many located at sculptures, murals or (more scarcely) interesting local businesses), or trying to solve the puzzles that appear in the game itself or on http://www.nianticproject.com/. I was one of the beta testers and really enjoy the game, especially in areas with more players.
As the game is most fun when people coordinate a bit, I started a google group for the munich area for one of the two teams (the enlightenment), but I will only let people enter that group who can be verified to be on that team.
On a side note: I still have a few invites to the game left, so if you are interested, please leave a comment and enter your gmail.com email address (you need a Google account to play anyway) while doing so. I will send out invites in the order I received the requests (which I admit might not always be the same in which they were submitted. First come first serve and no guarantee to get an invitation though. Your email address you enter when commenting isn t shown to anyone and I don t share them with anyone but the game (and thus Google).
EDIT: So short time went past, but I already ran out of invites (note that I didn t approve comments that really only were like please send me an invite , but still did sent one out). Feel free to still ask me for an invite, I will send some out as I get new ones, but this might take anything between a few days and some weeks.
PS: For the lucky ones who got invites: You don t strictly need to do the training offered when you start the game for the first time, but I strongly encourage you to do so.
After prompts from Wookey and Steve McIntyre, I decided to look at #285559 and #633884 for perl cross-build support and then port that support forward to the current perl in Wheezy and on to the version of perl currently in experimental. The first patch is for perl 5.8, the second for perl 5.12, neither of which is available currently in Debian. snapshot.debian.org provided the 5.12 source but then that no longer cross-builds with the patch.
DEB_BUILD_OPTIONS="nocheck" fakeroot debian/rules perl.static
/bin/bash debian/config.debian --full-version
armhf: #define Netdb_host_t const void * /**/
amd64: #define Netdb_host_t char * /**/
dpkg-architecture -aarmel -c fakeroot debian/rules clean
As Weblate 1.3 is out, it's time to think about features for next release. My current plan is to go more into two areas.
First is improving support for machine translations. I have some ideas how to integrate these in interesting ways, I just hope my (poor) Javascript knowledge will not prevent me doing it that way.
The second area is improving testsuite. Right now it really does not cover much and I'd like to cover at least basic functionality with different file formats. I'll see how much I will be able to cover, but at least I will try to cover as much as possible :-).
Filed under: English Weblate 0 comments Flattr this!
| Series: | Women Were Warriors #3 |
| Publisher: | Shield Maiden |
| Copyright: | 2008 |
| ISBN: | 0-9815636-3-5 |
| Format: | Kindle |
| Pages: | 301 |
This is an ebook, so metadata may be inaccurate or missing. See notes on ebooks for more information. A Hero's Tale is the third book in the When Women Were Warriors trilogy, which is best thought of as a single long novel. Reading it independently will miss most of the significance of the plot, since one wouldn't know many of the important characters. A Hero's Tale follows the pattern of the second book: even less quiet contemplation, and even more in the way of events and plot. Tamras completes her training, in a somewhat unexpected way (and in a rather interesting reworking of gender roles), but then both Maara's past and the problems of A Journey of the Heart catch up with them. There is, accordingly, quite a bit more action, or at least war councils and political maneuvering, than the previous books, and somewhat less time for thoughtful wisdom. That also means that A Hero's Tale shifts a bit more towards the traditional fantasy coming-of-age story, where the heroine is able to shift armies and win conflicts with an understated and self-deprecating skill that comes inevitably but indirectly out of all of her previous experiences. I think Wilson is still fairly original in how she presents those tropes, with an interesting focus on empathy and compassion that is all too rare in this sort of story, but this book does feel a lot more like a story that one has read before. If you're particularly allergic to that story shape, you may find this entry somewhat disappointing. One of the things I loved about it, though, was Wilson's avoidance of traditional villains. There is one, so it's not a complete avoidance, but nearly everyone in this story has their own viewpoint and perspective and is on the side of right in their own way. Wilson uses Tamras's empathy and willingness to listen and understand to let the reader see various different perspectives without moving away from the first-person perspective. It's very nicely done. I thought the handling of the emotional arc of the story was more mixed. Tamras is seriously tested in some moments that aimed for heartbreaking, but I thought they fell short of the emotional punch they were supposed to carry since the story shape had already made it obvious that everything would turn out okay in the end. The story is so gentle that Wilson hadn't established any willingness to end something badly, which robs a lot of the punch from emotional turmoil. I also had quite a bit of trouble with the principle of love above all else, particularly for someone in Tamras's position. Maybe that's because I'm still too entrenched in the attitude towards politics that this series argues against, but I had a hard time not seeing her as personally indulgent. Both of those factors blunted the emotional climax for me, leaving it moving but not as heartbreaking as I think Wilson was aiming for. (This is the point where a friend will tell me that I think too much about books while I'm reading them.) That said, Wilson continues to write one of the best mentoring relationships that I've seen in fiction. The dynamic between Tamras and Maara is just beautiful, and remains so through the end of the book. So many traditional issues with rivalry, growth, replacement of the mentor, and relative social position that are ignored or dealt with ham-handedly in other stories are handled adeptly and quietly. Maara is by far my favorite character of this series, largely because of how she handles that relationship. I could identify with her more easily than with Tamras at various points in the story, and I thought the understated ending was quietly beautiful. If you enjoyed the rest of the series, definitely read A Hero's Tale for the conclusion. If you've been hungry for more typical action, you'll get some of it here. I wish a few deep emotions other than love had been in play, but, despite that, When Women Were Warriors is still quietly and delightfully different than most things I've read, and worth the price. Rating: 8 out of 10
Since converting the phpMyAdmin documentation to new format and updating it's content, I was quite frightened how this will affect translated versions of it.
Fortunately giving it more attractive format and more advertisement lead to increased contributions. Since Friday, we already have one language which has reached 100% - Spanish. Mat as Bellone simply did there awesome job and went through all fuzzy and new strings in just few days.
Now I'm looking forward to other contributors as well, I hope we will be able to deliver translated manual for phpMyAdmin 4.0 in many languages. I'll definitely try to translate to Czech, but any help with that is welcome.
Filed under: English Phpmyadmin 2 comments Flattr this!
Next.