Python High Performance Programming 1st Edition Gabriele Lanaro instant download
Python High Performance Programming 1st Edition Gabriele Lanaro instant download
https://ebookbell.com/product/python-high-performance-
programming-1st-edition-gabriele-lanaro-43140680
https://ebookbell.com/product/parallel-and-high-performance-
programming-with-python-unlock-parallel-and-concurrent-programming-in-
python-fabio-nelli-48654648
https://ebookbell.com/product/parallel-and-high-performance-
programming-with-python-1st-edition-fabio-nelli-230355662
https://ebookbell.com/product/advanced-python-programming-build-high-
performance-concurrent-and-multithreaded-apps-with-python-using-
proven-design-patterns-dr-gabriele-lanaro-22045786
https://ebookbell.com/product/high-performance-python-practical-
performant-programming-for-humans-2nd-edition-micha-gorelick-24064792
High Performance Python Practical Performant Programming For Humans
Micha Gorelick
https://ebookbell.com/product/high-performance-python-practical-
performant-programming-for-humans-micha-gorelick-4766942
https://ebookbell.com/product/handson-gpu-programming-with-python-and-
cuda-explore-highperformance-parallel-computing-with-cuda-dr-brian-
tuomanen-10004658
https://ebookbell.com/product/python-high-performance-2nd-edition-
gabriele-lanaro-49052724
https://ebookbell.com/product/python-high-performance-2nd-edition-
gabriele-lanaro-10817444
https://ebookbell.com/product/python-high-performance-second-
edition-2nd-edition-gabriele-lanaro-231197896
Table of Contents
Python High Performance Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Benchmarking and Profiling
Designing your application
Writing tests and benchmarks
Timing your benchmark
Finding bottlenecks with cProfile
Profile line by line with line_profiler
Optimizing our code
The dis module
Profiling memory usage with memory_profiler
Performance tuning tips for pure Python code
Summary
2. Fast Array Operations with NumPy
Getting started with NumPy
Creating arrays
Accessing arrays
Broadcasting
Mathematical operations
Calculating the Norm
Rewriting the particle simulator in NumPy
Reaching optimal performance with numexpr
Summary
3. C Performance with Cython
Compiling Cython extensions
Adding static types
Variables
Functions
Classes
Sharing declarations
Working with arrays
C arrays and pointers
NumPy arrays
Typed memoryviews
Particle simulator in Cython
Profiling Cython
Summary
4. Parallel Processing
Introduction to parallel programming
The multiprocessing module
The Process and Pool classes
Monte Carlo approximation of pi
Synchronization and locks
IPython parallel
Direct interface
Task-based interface
Parallel Cython with OpenMP
Summary
Index
Python High Performance
Programming
Python High Performance
Programming
Copyright © 2013 Packt Publishing
Every effort has been made in the preparation of this book to ensure
the accuracy of the information presented. However, the information
contained in this book is sold without warranty, either express or
implied. Neither the author, nor Packt Publishing, and its dealers and
distributors will be held liable for any damages caused or alleged to
be caused directly or indirectly by this book.
Livery Place
35 Livery Street
ISBN 978-1-78328-845-8
www.packtpub.com
Gabriele Lanaro
Reviewers
Daniel Arbuckle
Mike Driscoll
Albert Lukaszewski
Acquisition Editors
Owen Roberts
Harsha Bharwani
Commissioning Editor
Shaon Basu
Technical Editors
Akashdeep Kundu
Faisal Siddiqui
Project Coordinator
Sherin Padayatty
Proofreader
Linda Morris
Indexer
Rekha Nair
Production Coordinators
Pooja Chiplunkar
Manu Joseph
Cover Work
Pooja Chiplunkar
About the Author
Gabriele Lanaro is a PhD student in Chemistry at the University of
British Columbia, in the field of Molecular Simulation. He writes high
performance Python code to analyze chemical systems in large-
scale simulations. He is the creator of Chemlab—a high performance
visualization software in Python—and emacs-for-python—a
collection of emacs extensions that facilitate working with Python
code in the emacs text editor. This book builds on his experience in
writing scientific Python code for his research and personal projects.
Did you know that Packt offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to
the eBook version at www.PacktPub.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get in
touch with us at <service@packtpub.com> for more details.
http://PacktLib.PacktPub.com
Why Subscribe?
Fully searchable across every book published by Packt
Copy and paste, print and bookmark content
On demand and accessible via web browser
In this book, you will learn, in a step-by-step method how to find and
speedup the slow parts of your programs using basic and advanced
techniques.
This book starts from the basics and builds on them, therefore, I
suggest you to move through the chapters in order.
The book was written and tested on Ubuntu 13.10. The examples
will likely run on Mac OS X with little or no changes.
And almost before Bertrand knew what she was doing, Ruby
was rushing through the little garden at the back of the
cottage on her way to descend the rough path to the shore.
“Look up;” and in spite of himself the boy could not help
looking up.
“A world...
Where the month is always June.”
Three Worlds.
“Mavis, Mavis,” she called out every now and then, “are you
there darling? can’t you answer?” as if, even had the wind
been less wildly raging, Mavis could possibly have heard her
so far-off.
“Mavis loves them so,” she thought, and her memory went
back to the happy peaceful afternoon they had spent with
old Adam and his grandson. How kind they were, and how
nice the cakes were that Winfried had made for them
himself!
And besides this, for Bertrand there might have been some
excuse; he had been neglected and yet spoilt; he had never
known what it was truly to love any one, whereas Ruby had
lived in love all her life; and this was her return for it.
“I have killed my little Mavis,” she sobbed. “Yes, it has been
all me. We needn’t have minded Bertrand; he couldn’t have
made me naughty if I hadn’t let him. Oh, Mavis, Mavis,
whatever shall I do?” Her glance fell again on the flowers in
her hand. They were not the least withered or spoilt, but as
fresh as if just newly gathered. They seemed to smile up at
her, and she felt somehow comforted.
“Dear little flowers,” she said. Seldom in her life had Ruby
spoken so tenderly. She started, as close beside her she
heard a faint sigh.
“But you cannot see me? and yet I am here, close to you,
as I have often been before. Try Ruby, try to see me.”
“If you could see me you would know how foolish you are,”
said the voice. “But I must have patience—it will come—
your eyes are not strong, Ruby; they are not even as strong
as Bertrand’s.”
“Yes, they are,” said Ruby indignantly. “I’ve never had sore
eyes in my life, and Bertrand’s have hurt him several times
lately.”
“I know; so much the better for him,” was the reply. “Well,
good-bye for the present, Ruby. Go on to look for Mavis;
you must face it all—there, the rain is coming now. Ah!”
And with this, which sounded like a long sigh, the voice
seemed to waft itself away, and down came the rain. The
same swirl which had been too much for sturdy Bertrand
was upon Ruby now, standing, too, in a far more exposed
place, with no shelter near, and the rough rocky path before
her. She did not stand long; she turned again and began to
descend, stumbling, slipping, blinded by the rain, dashed
and knocked about by the wind.
“She might have helped me, whoever she was that spoke to
me,” sobbed Ruby. “It isn’t my fault if I can’t see creatures
like that. I’m not good enough, I suppose.”
And yet as she struggled on again she did not feel quite so
miserable.
Yet it was terribly hard work, and every moment her anxiety
about Mavis increased; Ruby had never felt so much in all
her life.
She had at last reached the shore by this time. The rain still
fell in pitiless torrents, but the wind had fallen a little, and
down here she seemed rather less exposed than on the face
of the cliffs. Still Ruby was completely drenched through;
never before had she had any conception of the misery to
which some of our poor fellow-creatures are exposed to
almost every day of their lives. And yet, her fears for Mavis
overmastered all her other sufferings; for the first time
Ruby thought of another more than of herself.
“Mavis, dear little Mavis, Mavis darling, where are you?” she
sobbed wildly, her teeth chattering, while terrible shivers
shook her from head to foot. “Oh, it can’t be that she is
under those dreadful, fierce, leaping waves. They look as if
they were dancing in cruel joy over something they had
got;” and a shudder worse than those caused by the cold
went through the poor child.
“Mavis,” she called out at last, after she had peered round
about every large stone, every corner where her sister
could possibly have tried to find shelter, without coming
upon the slightest trace of either the child or the boat, “you
must be in the sea. I’ll go after you; it doesn’t matter if I
am drowned if you are. Perhaps—perhaps the mermaids are
keeping you safe; there are kind ones among them it says
in the fairy stories.”
“Mavis,” was the first word she whispered; “Mavis, are you
alive? Are you not drowned, darling? But it was such a very
long time ago. Perhaps the world is finished. But Mavis—I
thought Mavis was dead; and, oh! who are you?” she ended
with a thrill which seemed to make her quite alive and
awake.
“Are you the fairy in the turret? And what are you doing to
my eyes?”
Ruby obeyed; she had not even looked round to see where
she was; she only felt that she was lying on something soft
and warm and dry; oh, how nice it was to feel dry again.
For now the distant, long-ago sensation began to fade, and
she remembered everything clearly as if it had happened,
say, yesterday or the day before at farthest. The naughty
mischief she and Bertrand had been planning, the strange
little boat, the deserted cottage, the hurricane, and the
misery about Mavis, the plunge in search of her into the
sea, even to the loss of the forget-me-nots, which had been
her only comfort, all came back; and with it a wonderful
delightful feeling of hope and peace and trust, such as she
had never known before. She gave herself up to the kind
strong arms that clasped her round! “She will take me to
Mavis,” she thought; “and oh, I will try never, never to be
selfish and unkind and naughty again.”
Then, still wrapped in the soft warm mantle or rug she had
felt herself lying upon, she was lifted upwards, upwards
still, she knew not and cared not whither, for Ruby’s eyes
were closed and she was fast asleep, and this time her
sleep was dreamless.
“Ruby, my own little Ruby,” were the first words she heard.
They awoke her as nothing else would have done.
Yes, it was Mavis. She was leaning over the couch on which
Ruby lay. Never had Ruby seen her so bright and sweet and
happy-looking.
“Do you see, Ruby,” she said, “that all the flowers in this
garden are our wild flowers, though they are such
beauties?” She stooped to gather one or two blossoms
growing close beside her as she spoke.
“See, here are the same kind of forget-me-nots that were
at the old cottage, and that we found so strangely on the
castle terrace. And here are violets and primroses and
snowdrops, all the spring flowers; and the summer ones
too, honeysuckle and dog-roses; and even the tiny common
ones, buttercups and daisies, and celandine and pimpernel,
and eye-bright and shepherd’s-purse, and—and—”
“Up!” said Ruby, “are we down below the world? Are we out
of the world?”
Mavis smiled.
“I don’t know that either; perhaps it’s not days at all here.
I’ve never thought about it. But cousin Hortensia won’t be
frightened. The princess told me that. Winfried will take us
home. He can’t stay here either; he’s got work to do
somewhere, and he can only come back sometimes. There,
Ruby—look—there he comes; do you see him coming up
that little hill? He’ll be here in a few minutes.”
Chapter Eleven.
Down the Well.
“Is this my own frock?” she said. “No, it can’t be. See,
Mavis, it’s all beautifully embroidered with forget-me-nots!
And what lovely blue ribbon my hair is tied with; and my
hands are so white and clean Mavis, did the princess dress
me while I was asleep?”
“Oh Mavis!” she said, “he was so cruel and so heartless, and
I was so miserable. I do hope the princess will make him go
quite away.”
“No, no. I don’t want him. I only want you, my darling little
Mavis, and we shall be so happy—much, much happier than
we have ever been. Kiss me, Mavis, and tell me you quite
forgive me, and if ever I am naughty or horrid again, I hope
the princess will punish me.”
“She won’t let you forget her any way,” said Mavis. “I think
that is how she punishes.”
Ruby looked rather puzzled; but before she could ask more
they heard Winfried’s whistle, and in a moment he
appeared. His face was all one smile—all Ruby’s fears and
misgivings faded away before it.
“How lovely it must all be,” said Ruby, with a little sigh.
“Aren’t you sorry, Winfried, that you can’t stay here
altogether? Mavis says you have to go away to work.”
“Of course,” said Winfried cheerily. “It would never do,
young as I am, not to work. And we shouldn’t enjoy this
half as much if we had it always—it’s the rest and
refreshment after common life that makes half the
happiness. It’s different for gran—he’s done his part, none
better, and now his work should be light I’m thankful to
know he’s safe here. Now we had better go—down that little
hill is the way to his cottage.”
They listened with all their ears, you may be sure. Yes, as
they grew accustomed to the exceeding stillness, to the
clear thin fineness of the air, they heard the softest,
sweetest tinkle you can imagine; a perfect fairy bell-ringing,
and the longer they listened the clearer it grew.
“But don’t you miss the sea things?” Ruby went on. “You
love them so, Winfried, and somehow you seem to belong
to the sea.”
“So I do,” the boy replied. “The sea is my life. Coming here
is only a rest and a holiday.”
“You have seen farther into them than we have,” said Mavis
thoughtfully. “But still I think I can understand what you
mean.”
But just then, a little way off, they caught sight of old Adam
coming to meet them. His cottage was close by; they came
upon it suddenly, for it stood half-hidden under the shelter
of the hill they had been descending. Such a lovely cottage
it was—so simple, yet so pretty; quite clean, with a
cleanness you never see out of fairyland or places of that
kind, with flowers of all kinds, forget-me-nots above all,
clustering about it and peeping in at the windows.
There was some reason for Ruby’s question, for so far they
had seen no water at all in Forget-me-not Land. Everything
seemed fresh and fragrant, as if there was no dearth of
moisture, but there was neither lake, nor pond, nor running
brook. Winfried mounted the hill a little way, then turning
sharply, they found themselves in a sort of small wooded
ravine or glen. Steps led down the steep sides to the
bottom, which was a perfect thicket of ferns, mostly of the
deep green delicate kind, which loves darkness and water.
“Were you, dear?” said a voice whose sweet tones were not
strange to her. “No fear of that when I have to do with
things. Jump, that’s right; here you are, and you too,
Mavis.”
“The brook takes us to the river, and the river to the sea;
that is your way home,” she said. “Winfried will row, and
you two shall nestle up to me.”
She put an arm round each, and in silence, save for the
gentle drip of the oars, the little boat made its way. It was a
still evening, not yet dark, though growing dusk, and
though they were back in the winter world by now the
children felt no cold—who could have felt cold with the
princess’s mantle round them? They grew sleepy, too sleepy
to notice how, as she had said, the brook turned into the
river, and the river led on to the sea, the familiar sea, not
more than a mile or two from the cove below the castle.
And it was only when the boat grated a little on the pebbly
shore that both Ruby and Mavis started up to find
themselves alone with Winfried. The princess had left them.
“My dear, are you very tired? You seem half asleep.”
“We have not seen him for ever so long,” they replied.
“Oh,” she cried, “I am glad the young ladies are safe back.
Martin has seen the blue light in the west turret; he was
coming from the village a few minutes ago, and something
made him look up. It is many and many a year since it has
been seen, not since the young ladies were babies, and it
always—”
“Oh cousin, let us go too,” they said. “We are not a bit
frightened.”
So when old Joseph and Bertha had joined them, the whole
party set off for the turret.
As they got near to the top of the stair, a slight sound made
them all start.
“Hush!” said Miss Hortensia. They stood in perfect silence. It
came again—a murmur of faint sobs and weeping. Ulrica
grew whiter and whiter.
“I told you so,” she began, but no one listened. They all
pressed on, Miss Hortensia the first.
When she opened the door it was, except for the lamp she
held in her hand, upon total darkness. But in one corner
was heard a sort of convulsive breathing, and then a voice.
“Try and find out what it is; surely it is not another naughty
trick that he is playing,” said Miss Hortensia anxiously.
“No, no. I am sure it isn’t. Don’t be afraid, dear cousin,”
said the little girl.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com