Julia 1.0 Programming - Ivo Balbaert - E-Book

Julia 1.0 Programming E-Book

Ivo Balbaert

0,0
36,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Enter the exciting world of Julia, a high-performance language for technical computing




Key Features



  • Leverage Julia's high speed and efficiency for your applications


  • Work with Julia in a multi-core, distributed, and networked environment


  • Apply Julia to tackle problems concurrently and in a distributed environment





Book Description



The release of Julia 1.0 is now ready to change the technical world by combining the high productivity and ease of use of Python and R with the lightning-fast speed of C++. Julia 1.0 programming gives you a head start in tackling your numerical and data problems. You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. With the help of practical examples, this book walks you through two important collection types: arrays and matrices. In addition to this, you will be taken through how type conversions and promotions work.






In the course of the book, you will be introduced to the homo-iconicity and metaprogramming concepts in Julia. You will understand how Julia provides different ways to interact with an operating system, as well as other languages, and then you'll discover what macros are. Once you have grasped the basics, you'll study what makes Julia suitable for numerical and scientific computing, and learn about the features provided by Julia. By the end of this book, you will also have learned how to run external programs.






This book covers all you need to know about Julia in order to leverage its high speed and efficiency for your applications.





What you will learn



  • Set up your Julia environment to achieve high productivity


  • Create your own types to extend the built-in type system


  • Visualize your data in Julia with plotting packages


  • Explore the use of built-in macros for testing and debugging, among other uses


  • Apply Julia to tackle problems concurrently


  • Integrate Julia with other languages such as C, Python, and MATLAB





Who this book is for



Julia 1.0 Programming is for you if you are a statistician or data scientist who wants a crash course in the Julia programming language while building big data applications. A basic knowledge of mathematics is needed to understand the various methods that are used or created during the course of the book to exploit the capabilities that Julia is designed with.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 223

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Julia 1.0 ProgrammingSecond Edition

 

 

 

 

 

 

 

 

 

 

 

Dynamic and high-performance programming to build fast scientific applications

 

 

 

 

 

 

 

Ivo Balbaert

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Julia 1.0 Programming Second Edition

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

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(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Commissioning Editor: Richa TripathiAcquisition Editor: Denim PintoContent Development Editor: Pooja ParvatkarTechnical Editor: Romy DiasCopy Editor: Safis EditingProject Coordinator: Ulhas KambaliProofreader: Safis EditingIndexer: Tejal Daruwale SoniGraphics: Tom ScariaProduction Coordinator: Shraddha Falebhai

First published: February 2015 Second edition: September 2018

Production reference: 1200918

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78899-909-0

www.packtpub.com

 
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

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.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the author

Ivo Balbaert has been a lecturer in web programming and databases at CVO Antwerpen (www.cvoantwerpen.be), a community college in Belgium. He received a Ph.D. in Applied Physics from the University of Antwerp in 1986. He worked for 20 years in the software industry as a developer and consultant in several companies, and for 10 years as project manager at the University Hospital of Antwerp. From 2000 onwards, he switched to partly teaching and partly developing software (at KHM Mechelen, CVO Antwerpen). He also wrote an introductory book in Dutch about developing in Ruby and Rails, Programmeren met Ruby en Rails, by Van Duuren Media. In 2012, he authored a book on the Go programming language, The Way To Go, by IUniverse. He wrote a number of introductory books for new programming languages, notably Dart, Julia, Rust, and Red, all published by Packt.

I would like to thank the technical reviewer, Malcolm Sherrington, for the many useful remarks that improved the text.

About the reviewer

Malcolm Sherrington has been working in computing for over 35 years. He holds degrees in mathematics, chemistry, and engineering. He is running his own company, focusing on the aerospace, healthcare, and finance sectors, with specific interests in High-Performance Computing and applications of GPUs and parallelism. Always hands-on, Malcolm started programming scientific problems in Fortran and C, progressing through Ada and Common Lisp, and recently became involved with data processing and analytics in Perl, Python, and R. Malcolm is the organizer of the London Julia User Group

 

 

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Julia 1.0 Programming Second Edition

Packt Upsell

Why subscribe?

Packt.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Conventions used

Get in touch

Reviews

Installing the Julia Platform

Installing Julia

Windows OS

OS X

Linux OS

Building from source

JuliaPro

Working with Julia's REPL

Startup options and Julia scripts

Packages

Adding a new package

Installing and working with IJulia

Installing Juno

Installing julia-vscode

Installing Sublime-IJulia

Other editors and IDEs

How Julia works

Summary

Variables, Types, and Operations

Variables, naming conventions, and comments

Types

Integers

Floating point numbers

Elementary mathematical functions and operations

Rational and complex numbers

Characters

Strings

Formatting numbers and strings

Regular expressions

Ranges and arrays

Other ways to create arrays

Some common functions for arrays

Dates and times

Scope and constants

Summary

Functions

Defining functions

Optional and keyword arguments

Anonymous functions

First-class functions and closures

functions

Broadcasting

Map, filter, and list comprehensions

Generic functions and multiple dispatch

Summary

Control Flow

Conditional evaluation

Repeated evaluation

for loops

while loops

The break statement

The continue statement

Exception handling

Scope revisited

Tasks

Summary

Collection Types

Matrices

Tuples

Dictionaries

Keys and values – looping

Sets

An example project – word frequency

Summary

More on Types, Methods, and Modules

Type annotations

Type conversions and promotions

The type hierarchy – subtypes and supertypes

Concrete and abstract types

User-defined and composite types

When are two values or objects equal or identical?

A multiple-dispatch example

Types and collections – inner constructors

Type unions

Parametric types and methods

Standard modules and paths

Summary

Metaprogramming in Julia

Expressions and symbols

Evaluation and interpolation

Defining macros

Built-in macros

Testing

Debugging

Benchmarking

Starting a task

Reflection capabilities

Summary

I/O, Networking, and Parallel Computing

Basic input and output

Working with files

Reading and writing CSV files

Using DataFrames

Other file formats

Working with TCP sockets and servers

Interacting with databases

Parallel operations and computing

Creating processes

Using low-level communications

Parallel loops and maps

Summary

Running External Programs

Running shell commands

Interpolation

Pipelining

Calling C and Fortran

Calling Python

Performance tips

Tools to use

Summary

The Standard Library and Packages

Digging deeper into the standard library

Julia's package manager

Installing and updating packages

Graphics in Julia

Using Plots on data

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Julia is a now a well-established programming language. It was developed at MIT in the Applied Computing Group under the supervision of Prof. Alan Edelman. Its development started in 2009, and it was first presented publicly in February 2012. It has now reached its first production version: Julia v1.0 (published Aug 8, 2018), which means that stability is guaranteed for the complete duration of version 1. It is based on clear and solid principles, and its popularity is steadily increasing in the technical, data scientist, and high-performance computing arena.

Who this book is for

This book is intended for data scientists and all those who work on technical and scientific computation projects. It will get you up and running quickly with Julia to start simplifying your projects' applications. The book assumes you already have some basic working knowledge of a high-level dynamic language such as MATLAB, R, Python, or Ruby.

What this book covers

Chapter 1, Installing the Julia Platform, explains how to install all the necessary components for a Julia environment. It teaches you how to work with Julia's console (the REPL) and discusses some of the more elaborate development editors you can use.

Chapter 2, Variables, Types, and Operations, discusses the elementary built-in types in Julia and the operations that can be performed on them so that you are prepared to start writing code with them.

Chapter 3, Functions, teaches you why functions are the basic building blocks of Julia, and how to effectively use them.

Chapter 4, Control Flow, shows Julia's elegant control constructs, how to perform error handling, and how to use coroutines (called Tasks in Julia) to structure the execution of your code.

Chapter 5, Collection Types, explores the different types that group individual values, such as arrays and matrices, tuples, dictionaries, and sets.

Chapter 6, More on Types, Methods, and Modules, digs deeper into the type concept and how it is used in multiple dispatch to get C-like performance. Modules, a higher code organizing concept, are discussed as well.

Chapter 7, Metaprogramming in Julia, touches on deeper layers of Julia, such as expressions and reflection capabilities, and demonstrates the power of macros.

Chapter 8, I/O, Networking, and Parallel Computing, shows how to work with data in files and databases by using DataFrames. It also looks at networking capabilities, and how to set up a parallel computing environment with Julia.

Chapter 9, Running External Programs, looks at how Julia interacts with the command-line and with other languages, and also discusses performance tips.

Chapter 10, The Standard Library and Packages, digs deeper into the standard library, and demonstrates important packages for the visualization of data.

To get the most out of this book

To run the code examples in the book, you will need the Julia platform for your computer, which can be downloaded from http://julialang.org/downloads/. To work more comfortably with Julia scripts, a development environment such as IJulia, Sublime Text, or Visual Studio Code is advisable. The first chapter contains detailed instructions on how to set up your Julia environment.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Julia-1.0-Programming-Second-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Add /Applications/Julia-n.m.app/Contents/Resources/julia/bin/Julia to make Julia available everywhere on your computer."

A block of code is set as follows:

for arg in ARGS println(arg) end

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

mutable struct Point

x::Float64 y::Float64 z::Float64 end

Any command-line input or output is written as follows:

julia> include("hello.jl")

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Start it up, go to Settings, and then Install Panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Installing the Julia Platform

This chapter guides you through the download and installation process of all the necessary components of Julia. The topics covered in this chapter are as follows:

Installing Julia

Working with Julia's REPL

Startup options and Julia scripts

Packages

Installing and working with IJulia

Installing Juno

Installing julia-vscode

Installing Sublime-IJulia

Other editors and IDEs

How Julia works

By the end of this chapter, you will have a running Julia platform. Moreover, you will be able to work with Julia's shell as well as with editors or integrated development environments with a lot of built-in features to make development more comfortable.

Installing Julia

The Julia platform, in binary (that is, executable) form, can be downloaded from http://julialang.org/downloads/. It exists for three major platforms (Windows, Linux, and OS X) in 32- and 64-bit format, and it is delivered as a package or in an archive version. FreeBSD 64-bit is also supported.

You should use the current official stable release when doing serious professional work with Julia. At the time of writing, Julia has reached its version 1.0 production release. The previous link contains detailed and platform-specific instructions for the installation. We will not repeat these instructions here completely, but we will summarize some important points.

Windows OS

Keep in mind that your Windows OS must be version 7 or higher. Now, follow the steps shown here:

Download the

julia-n.m.p-win64.exe

file into a temporary folder (

n.m.p

is the version number, such as

0.7.0

or

0.

1.0

;

win32

/

win64

are the 32- and 64-bit versions, 

respectively

; a release candidate file looks like

julia-1.0.0-rc1-nnnnnnn-win64

(where 

nnnnnnn

is a checksum number such as

0480f1b

)).

Double-click on the file (or right-click and select

Run as Administrator

if you want Julia installed for all users on the machine). Click

OK

on the security dialog message. Then, choose the installation directory (for example, for

C:\julia

,

the default installation folder is:

C:\Users\UserName\AppData\Local\Julia-n.m.p

(where

n.m.p

is the version number)) and the setup program will extract the archive into the chosen folder, producing the following directory structure, and taking some 800 MB of disk space:

The Julia folder structure in Windows

A me

nu shortcut will be created which, when clicked, starts the Julia command-line version or

Read Evaluate Print Loop

(

REPL

), as shown in the following screenshot:

The Julia REPL

On Windows, if you have chosen

C:\Julia

as your installation directory, this is the

C:\Julia\bin\julia.exe

file. Add

C:\Julia\bin

to your

PATH

variable if you want the REPL to be available on any command window.

More information on Julia's installation for the Windows OS can be found at

https://github.com/JuliaLang/julia/blob/master/README.windows.md

.

OS X

Installation for OS X is straightforward, and can be done using the standard software installation tools for the platform. Add /Applications/Julia-n.m.app/Contents/Resources/julia/bin/Julia to make Julia available everywhere on your computer.

Linux OS

Generic Linux binaries for x86 can be downloaded. This will get you a compressed tar.gz archive that will have a name similar to julia-1.0-linux-x86_64.tar.gz, for example, in your ~/Downloads directory in Ubuntu. Open up a Terminal window and navigate to the Downloads directory using cd Downloads. Move the tar.gz file to a directory of your choice, and then extract the tar.gz file using the tar -zxvf julia-1.0-linux-x86_64.tar.gzcommand. A directory with the extracted contents will be generated in the same parent directory as the compressed archive with a name similar to julia-n.m.p, where n.m.p is Julia's version number.

This is the directory from which Julia will be run; no further installation is needed. To run it, simply navigate to the julia-n.m.p\bin directory in your Terminal and type: ./julia.

If you want to be at the bleeding edge of development, you can download the nightly builds instead of the stable releases from https://julialang.org/downloads/nightlies.html. The nightly builds are generally less stable, but will contain the most recent features. They are available for Windows, Linux, and OS X.

The path to the Julia executable is contained in the environment variable, JULIA_BINDIR (for example, in our installation procedure, this was C:\Julia\bin on Windows).

If you want code to be run whenever you start a Julia session, put it in /home/.juliarc.jl on Ubuntu, ~/.juliarc.jl on OS X, or C:\Users\username\.juliarc.jl on Windows.

Building from source

Download the source code, rather than the binaries, if you intend to contribute to the development of Julia itself, or if no Julia binaries are provided for your operating system or particular computer architecture. The Julia source code can be found on GitHub at https://github.com/JuliaLang/julia.git. Compiling the source code will get you the latest Julia version, not the stable version (if you want the latter, download the binaries, and refer to the previous section).

Because of the diversity of platforms and the possible issues involved, we refer you to https://github.com/JuliaLang/julia, and in that, the Source Download and Compilation section.

JuliaPro

Another alternative is JuliaPro, which is available from https://juliacomputing.com/products/juliapro.html. This is an Anaconda-style Julia repository, which, at present, is only up to version 0.6.4. It does come with about 200+ verified ready-to-go packages, and is a very good way for beginners to start. JuliaPro version 1.0 will probably become available after some time.

There are two ways of using Julia. As described in the previous section, we can use the Julia shell for interactive work. Alternatively, we can write programs in a text file, save them with a .jl extension, and let Julia execute the program by starting it by running julia program.jl.