Julia: High Performance Programming

Book description

Leverage the power of Julia to design and develop high performing programs

About This Book

  • Get to know the best techniques to create blazingly fast programs with Julia
  • Stand out from the crowd by developing code that runs faster than your peers' code
  • Complete an extensive data science project through the entire cycle from ETL to analytics and data visualization

Who This Book Is For

This learning path is for data scientists and for all those who work in technical and scientific computation projects. It will be great for Julia developers who are interested in high-performance technical computing.

This learning path assumes that you already have some basic working knowledge of Julia's syntax and high-level dynamic languages such as MATLAB, R, Python, or Ruby.

What You Will Learn

  • Set up your Julia environment to achieve the highest productivity
  • Solve your tasks in a high-level dynamic language and use types for your data only when needed
  • Apply Julia to tackle problems concurrently and in a distributed environment
  • Get a sense of the possibilities and limitations of Julia's performance
  • Use Julia arrays to write high performance code
  • Build a data science project through the entire cycle of ETL, analytics, and data visualization
  • Display graphics and visualizations to carry out modeling and simulation in Julia
  • Develop your own packages and contribute to the Julia Community

In Detail

In this learning path, you will learn to use an interesting and dynamic programming language - Julia! You will get a chance to tackle your numerical and data problems with Julia. You'll begin the journey by setting up a running Julia platform before exploring its various built-in types. We'll then move on to the various functions and constructs in Julia. We'll walk through the two important collection types - arrays and matrices in Julia.

You will dive into how Julia uses type information to achieve its performance goals, and how to use multiple dispatch to help the compiler emit high performance machine code. You will see how Julia's design makes code fast, and you'll see its distributed computing capabilities.

By the end of this learning path, you will see how data works using simple statistics and analytics, and you'll discover its high and dynamic performance - its real strength, which makes it particularly useful in highly intensive computing tasks.

This learning path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products:

  • Getting Started with Julia by Ivo Balvaert
  • Julia High Performance by Avik Sengupta
  • Mastering Julia by Malcolm Sherrington

Style and approach

This hands-on manual will give you great explanations of the important concepts related to Julia programming.

Table of contents

  1. Julia: High Performance Programming
    1. Table of Contents
    2. Julia: High Performance Programming
    3. Julia: High Performance Programming
    4. Credits
    5. Preface
      1. What this learning path covers
      2. What you need for this learning path
      3. Who this learning path is for
      4. Reader feedback
      5. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    6. I. Module 1
      1. The Rationale for Julia
        1. The scope of Julia
        2. Julia's place among the other programming languages
        3. A comparison with other languages for the data scientist
          1. MATLAB
          2. R
          3. Python
        4. Useful links
        5. Summary
      2. 1. Installing the Julia Platform
        1. Installing Julia
          1. Windows version – usable from Windows XP SP2 onwards
          2. Ubuntu version
          3. OS X
          4. Building from source
        2. Working with Julia's shell
        3. Startup options and Julia scripts
        4. Packages
          1. Adding a new package
        5. Installing and working with Julia Studio
        6. Installing and working with IJulia
        7. Installing Sublime-IJulia
        8. Installing Juno
        9. Other editors and IDEs
        10. How Julia works
        11. Summary
      3. 2. Variables, Types, and Operations
        1. Variables, naming conventions, and comments
        2. Types
        3. Integers
        4. Floating point numbers
        5. Elementary mathematical functions and operations
        6. Rational and complex numbers
        7. Characters
        8. Strings
          1. Formatting numbers and strings
        9. Regular expressions
        10. Ranges and arrays
          1. Other ways to create arrays
          2. Some common functions for arrays
          3. How to convert an array of chars to a string
        11. Dates and times
        12. Scope and constants
        13. Summary
      4. 3. Functions
        1. Defining functions
        2. Optional and keyword arguments
        3. Anonymous functions
        4. First-class functions and closures
        5. Recursive functions
        6. Map, filter, and list comprehensions
        7. Generic functions and multiple dispatch
        8. Summary
      5. 4. Control Flow
        1. Conditional evaluation
        2. Repeated evaluation
          1. The for loop
          2. The while loop
          3. The break statement
          4. The continue statement
        3. Exception handling
        4. Scope revisited
        5. Tasks
        6. Summary
      6. 5. Collection Types
        1. Matrices
        2. Tuples
        3. Dictionaries
          1. Keys and values – looping
        4. Sets
          1. Making a set of tuples
        5. Example project – word frequency
        6. Summary
      7. 6. More on Types, Methods, and Modules
        1. Type annotations and conversions
          1. Type conversions and promotions
        2. The type hierarchy – subtypes and supertypes
          1. Concrete and abstract types
        3. User-defined and composite types
          1. When are two values or objects equal or identical?
          2. Multiple dispatch example
        4. Types and collections – inner constructors
        5. Type unions
        6. Parametric types and methods
        7. Standard modules and paths
        8. Summary
      8. 7. Metaprogramming in Julia
        1. Expressions and symbols
        2. Eval and interpolation
        3. Defining macros
        4. Built-in macros
          1. Testing
          2. Debugging
          3. Benchmarking
          4. Starting a task
        5. Reflection capabilities
        6. Summary
      9. 8. I/O, Networking, and Parallel Computing
        1. Basic input and output
        2. Working with files
          1. Reading and writing CSV files
        3. Using DataFrames
          1. Other file formats
        4. Working with TCP sockets and servers
        5. Interacting with databases
        6. Parallel operations and computing
          1. Creating processes
          2. Using low-level communications
          3. Parallel loops and maps
          4. Distributed arrays
        7. Summary
      10. 9. Running External Programs
        1. Running shell commands
          1. Interpolation
          2. Pipelining
        2. Calling C and FORTRAN
        3. Calling Python
        4. Performance tips
          1. Tools to use
        5. Summary
      11. 10. The Standard Library and Packages
        1. Digging deeper into the standard library
        2. Julia's package manager
          1. Installing and updating packages
        3. Publishing a package
        4. Graphics in Julia
        5. Using Gadfly on data
        6. Summary
      12. A. List of Macros and Packages
        1. Macros
        2. List of packages
    7. II. Module 2
      1. 1. Julia is Fast
        1. Julia – fast and dynamic
        2. Designed for speed
          1. JIT and LLVM
          2. Types
        3. How fast can Julia be?
        4. Summary
      2. 2. Analyzing Julia Performance
        1. Timing Julia code
          1. Tic and Toc
          2. The @time macro
          3. The @timev macro
        2. The Julia profiler
          1. Using the profiler
          2. ProfileView
        3. Analyzing memory allocation
          1. Using the memory allocation tracker
        4. Statistically accurate benchmarking
          1. Using Benchmarks.jl
        5. Summary
      3. 3. Types in Julia
        1. The Julia type system
          1. Using types
          2. Multiple dispatch
          3. Abstract types
          4. Julia's type hierarchy
          5. Composite and immutable types
          6. Type parameters
          7. Type inference
        2. Type-stability
          1. Definitions
          2. Fixing type-instability
          3. Performance pitfalls
          4. Identifying type-stability
          5. Loop variables
        3. Kernel methods
        4. Types in storage locations
          1. Arrays
          2. Composite types
          3. Parametric composite types
        5. Summary
      4. 4. Functions and Macros – Structuring Julia Code for High Performance
        1. Using globals
          1. The trouble with globals
          2. Fixing performance issues with globals
        2. Inlining
          1. Default inlining
          2. Controlling inlining
          3. Disabling inlining
        3. Closures and anonymous functions
          1. FastAnonymous
        4. Using macros for performance
          1. The Julia compilation process
          2. Using macros
          3. Evaluating a polynomial
          4. Horner's method
          5. The Horner macro
        5. Generated functions
          1. Using generated functions
          2. Using generated functions for performance
          3. Using named parameters
        6. Summary
      5. 5. Fast Numbers
        1. Numbers in Julia
          1. Integers
          2. Integer overflow
          3. BigInt
          4. The floating point
          5. Unchecked conversions for unsigned integers
        2. Trading performance for accuracy
          1. The fastmath macro
          2. The K-B-N summation
        3. Subnormal numbers
          1. Subnormal numbers to zero
        4. Summary
      6. 6. Fast Arrays
        1. Array internals in Julia
          1. Array representation and storage
          2. Column-wise storage
        2. Bound checking
          1. Removing the cost of bound checking
          2. Configuring bound checks at startup
        3. Allocations and in-place operations
          1. Preallocating function output
          2. Mutating versions
        4. Array views
        5. SIMD parallelization
        6. Yeppp!
        7. Writing generic library functions with arrays
        8. Summary
      7. 7. Beyond the Single Processor
        1. Parallelism in Julia
          1. Starting a cluster
          2. Communication between Julia processes
        2. Programming parallel tasks
          1. @everywhere
          2. @spawn
          3. Parallel for
          4. Parallel map
          5. Distributed arrays
        3. Shared arrays
          1. Threading
        4. Summary
    8. III. Module 3
      1. 1. The Julia Environment
        1. Introduction
          1. Philosophy
          2. Role in data science and big data
          3. Comparison with other languages
          4. Features
        2. Getting started
          1. Julia sources
          2. Exploring the source stack
          3. Juno
          4. IJulia
        3. A quick look at some Julia
          1. Julia via the console
          2. Installing some packages
            1. A bit of graphics creating more realistic graphics with Winston
          3. My benchmarks
        4. Package management
          1. Listing, adding, and removing
          2. Choosing and exploring packages
            1. Statistics and mathematics
            2. Data visualization
            3. Web and networking
            4. Database and specialist packages
          3. How to uninstall Julia
          4. Adding an unregistered package
        5. What makes Julia special
          1. Parallel processing
          2. Multiple dispatch
          3. Homoiconic macros
          4. Interlanguage cooperation
        6. Summary
      2. 2. Developing in Julia
        1. Integers, bits, bytes, and bools
          1. Integers
          2. Logical and arithmetic operators
          3. Booleans
        2. Arrays
          1. Operations on matrices
          2. Elemental operations
          3. A simple Markov chain – cat and mouse
        3. Char and strings
          1. Characters
          2. Strings
            1. Unicode support
            2. Regular expressions
            3. Byte array literals
            4. Version literals
          3. An example
        4. Real, complex, and rational numbers
          1. Reals
            1. Operators and built-in functions
            2. Special values
            3. BigFloats
          2. Rationals
          3. Complex numbers
            1. Juliasets
        5. Composite types
        6. More about matrices
          1. Vectorized and devectorized code
          2. Multidimensional arrays
            1. Broadcasting
          3. Sparse matrices
        7. Data arrays and data frames
        8. Dictionaries, sets, and others
          1. Dictionaries
          2. Sets
          3. Other data structures
        9. Summary
      3. 3. Types and Dispatch
        1. Functions
          1. First-class objects
          2. Passing arguments
            1. Default and optional arguments
            2. Variable argument list
            3. Named parameters
          3. Scope
          4. The Queen's problem
        2. Julia's type system
          1. A look at the rational type
          2. A vehicle datatype
            1. Typealias and unions
        3. Enumerations (revisited)
        4. Multiple dispatch
          1. Parametric types
          2. Conversion and promotion
            1. Conversion
            2. Promotion
          3. A fixed vector module
        5. Summary
      4. 4. Interoperability
        1. Interfacing with other programming environments
          1. Calling C and Fortran
            1. Mapping C types
              1. Array conversions
              2. Type correspondences
            2. Calling a Fortran routine
            3. Calling curl to retrieve a web page
          2. Python
          3. Some others to watch
          4. The Julia API
          5. Calling API from C
        2. Metaprogramming
          1. Symbols
          2. Macros
          3. Testing
            1. Error handling
          4. The enum macro
        3. Tasks
          1. Parallel operations
          2. Distributed arrays
          3. A simple MapReduce
        4. Executing commands
          1. Running commands
          2. Working with the filesystem
          3. Redirection and pipes
            1. Perl one-liners
        5. Summary
      5. 5. Working with Data
        1. Basic I/O
          1. Terminal I/O
          2. Disk files
          3. Text processing
          4. Binary files
        2. Structured datasets
          1. CSV and DLM files
          2. HDF5
          3. XML files
        3. DataFrames and RDatasets
          1. The DataFrames package
          2. DataFrames
          3. RDatasets
            1. Subsetting, sorting, and joining data
        4. Statistics
          1. Simple statistics
          2. Samples and estimations
          3. Pandas
        5. Selected topics
          1. Time series
          2. Distributions
            1. Kernel density
          3. Hypothesis testing
          4. GLM
        6. Summary
      6. 6. Scientific Programming
        1. Linear algebra
          1. Simultaneous equations
          2. Decompositions
          3. Eigenvalues and eigenvectors
          4. Special matrices
            1. A symmetric eigenproblem
        2. Signal processing
          1. Frequency analysis
          2. Filtering and smoothing
          3. Digital signal filters
          4. Image processing
        3. Differential equations
          1. The solution of ordinary differential equations
          2. Non-linear ordinary differential equations
          3. Partial differential equations
        4. Optimization problems
          1. JuMP
          2. Optim
          3. NLopt
            1. Using with the MathProgBase interface
        5. Stochastic problems
          1. Stochastic simulations
            1. SimJulia
            2. Bank teller example
          2. Bayesian methods and Markov processes
            1. Monte Carlo Markov Chains
            2. MCMC frameworks
        6. Summary
      7. 7. Graphics
        1. Basic graphics in Julia
          1. Text plotting
          2. Cairo
          3. Winston
        2. Data visualization
          1. Gadfly
          2. Compose
        3. Graphic engines
          1. PyPlot
          2. Gaston
          3. PGF plots
        4. Using the Web
          1. Bokeh
          2. Plotly
        5. Raster graphics
          1. Cairo (revisited)
          2. Winston (revisited)
          3. Images and ImageView
        6. Summary
      8. 8. Databases
        1. A basic view of databases
          1. The red pill or the blue pill?
          2. Interfacing to databases
          3. Other considerations
        2. Relational databases
          1. Building and loading
          2. Native interfaces
          3. ODBC
          4. Other interfacing techniques
          5. DBI
            1. SQLite
            2. MySQL
            3. PostgreSQL
          6. PyCall
          7. JDBC
        3. NoSQL datastores
          1. Key-value systems
          2. Document datastores
        4. RESTful interfacing
          1. JSON
          2. Web-based databases
          3. Graphic systems
        5. Summary
      9. 9. Networking
        1. Sockets and servers
          1. Well-known ports
          2. UDP and TCP sockets in Julia
          3. A "Looking-Glass World" echo server
          4. Named pipes
        2. Working with the Web
          1. A TCP web service
          2. The JuliaWeb group
          3. The "quotes" server
          4. WebSockets
        3. Messaging
          1. E-mail
          2. Twitter
          3. SMS and esendex
        4. Cloud services
          1. Introducing Amazon Web Services
          2. The AWS.jl package
          3. The Google Cloud
        5. Summary
      10. 10. Working with Julia
        1. Under the hood
          1. Femtolisp
          2. The Julia API
          3. Code generation
        2. Performance tips
          1. Best practice
          2. Profiling
          3. Lint
          4. Debugging
        3. Developing a package
          1. Anatomy
          2. Taxonomy
          3. Using Git
          4. Publishing
        4. Community groups
          1. Classifications
          2. JuliaAstro
            1. Cosmology models
            2. The Flexible Image Transport System
              1. The high-level API
              2. The low-level API
          3. JuliaGPU
        5. What's missing?
        6. Summary
    9. A. Bibliography
    10. Index

Product information

  • Title: Julia: High Performance Programming
  • Author(s): Ivo Balbaert, Avik Sengupta, Malcolm Sherrington
  • Release date: November 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781787125704