Erich Schubert: Phoronix GNOME user survey
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.
In May this year, in a desperate bid to bail water out of a
sinking ship, HMV group sold off the Waterstones chain of
bookstores.
I'm fond of reading so naturally I visit Waterstones from time to time. (but
not exclusively.) For many years, their promotions were unanimously structured
as "3 for 2" offers: find three books in the promotion, in-store, and get the
cheapest of the three for free. I hated these promotions. I always found it
very challenging to find three books in the promotion that I wanted. If I was
visiting to buy a specific book and found it in the promotion, on more than one
occasion I left the shop empty handed: I wasn't prepared to pay full price for
a book in a promotion and not get the benefit of the promotion.
Since being sold, Waterstones seem to have made a lot of changes. Many new
hardbacks from popular authors have debuted at a discount for a short period
(Rowling, Pratchett). I've found many more discounted books not tied to others
in 3-for-2-style offers, sometimes window-display stock at half price, a month
or so after release. They started a loyalty-card scheme, with a 10 gift card
the prize you reach once you've spent 100. (I wonder if such schemes are
examples of a token economy?)
Finally, they've tentatively started to explore putting cafes in their branches.
The one in Newcastle is best described as 'fledgling', but it's nice to have one
more place to escape for a cup of tea at lunchtimes. The cafe, as well as a very
well stocked collection of magazines, were the two killer features of the sadly-
defunct Borders bookseller chain. For years before we got our own Borders in the
North East, I used to enjoy the York branch if I was passing.
I actually managed to fill a loyalty card this year, so clearly their change in
attitude has worked on me! I'm generally not a fan of gift cards, especially in
today's climate, so I quickly spent it. I hold an American Express credit card,
which earns me cashbask on purchases which I make with it. I think the rate is
about 1%. However, I can opt to receive the cashback in the form of gift
vouchers. If I do so, I get them to the value of 110% my cashback balance. One
of the retailers in on the scheme are Waterstones. I'm tempted
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!
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.
it's seems we're starting to run out of RC bugs with the implicit usertag
easy-enough-for-gregoa
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!
# apt-get install hfsprogs icnsutils
gdisk, it looks like this:Number Start (sector) End (sector) Size Code Name 5 235284480 235302943 9.0 MiB AF00 Apple HFS/HFS+ Partition GUID code: 48465300-0000-11AA-AA11-00306543ECAC (Apple HFS/HFS+) Partition unique GUID: AD1F5465-B777-4178-AC4D-1DE8B2EB1B4B First sector: 235284480 (at 112.2 GiB) Last sector: 235302943 (at 112.2 GiB) Partition size: 18464 sectors (9.0 MiB) Attribute flags: 0000000000000000 Partition name: 'Apple HFS/HFS+'
# mkfs.hfsplus /dev/sda5 -v Debian
(replace /dev/sda5 with whatever your partition is)
fstab entry for that filesystem:# echo $(blkid -o export -s UUID /dev/sda5) /boot/efi auto defaults 0 0 >> /etc/fstab
# mkdir /boot/efi # mount /boot/efi
/usr/sbin/grub-install, look for xfat , and remove the block of code that looks like:if test "x$efi_fs" = xfat; then :; else
echo "$ efidir doesn't look like an EFI partition." 1>&2
efidir=
fi
grub-install. At this point, there should be a /boot/efi/EFI/debian/grubx64.efi file (if using grub-efi-amd64)./boot/efi/System/Library/CoreServices directory:# mkdir -p /boot/efi/System/Library/CoreServices
# ln /boot/efi/EFI/debian/grubx64.efi /boot/efi/System/Library/CoreServices/boot.efi
mach_kernel file:# echo "This file is required for booting" > /boot/efi/mach_kernel
mactel-boot source code, unpack and build it:# wget http://www.codon.org.uk/~mjg59/mactel-boot/mactel-boot-0.9.tar.bz2 # tar -jxf mactel-boot-0.9.tar.bz2 # cd mactel-boot-0.9 # make PRODUCTVERSION=Debian
SystemVersion.plist file:# cp SystemVersion.plist /boot/efi/System/Library/CoreServices/
# ./hfs-bless /boot/efi/System/Library/CoreServices/boot.efi
# rsvg-convert -w 128 -h 128 -o /tmp/debian.png /usr/share/reportbug/debian-swirl.svg # png2icns /boot/efi/.VolumeIcon.icns /tmp/debian.png # rm /tmp/debian.png
And the Startup disk preferences dialog under OSX, like 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
Next.