Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering Julia
Mastering Julia

Mastering Julia: Develop your analytical and programming skills further in Julia to solve complex data processing problems

Arrow left icon
Profile Icon Malcolm Sherrington
Arrow right icon
$43.19 $47.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (7 Ratings)
eBook Jul 2015 410 pages 1st Edition
eBook
$43.19 $47.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Malcolm Sherrington
Arrow right icon
$43.19 $47.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (7 Ratings)
eBook Jul 2015 410 pages 1st Edition
eBook
$43.19 $47.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$43.19 $47.99
Paperback
$60.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Julia

Chapter 2. Developing in Julia

Julia is a feature-rich language. It was designed to appeal to the novice programmer and purist alike. Indeed for those whose interests lie in data science, statistics and mathematical modeling, Julia is well equipped to meet all their needs.

Our aim is to furnish the reader with the necessary knowledge to begin programming in Julia almost immediately. So rather than begin with an overview of the language's syntax, control structures and the like, we will introduce Julia's facets gradually over the rest of this book. Over the next two chapters we will look at some of the basic and advanced features of the Julia core. Many of the features such as graphics and database access, which are implemented via the package system will be left until later.

If you are familiar with programming in Python, R, MATLAB and so on, you will not find the journey terribly arduous, in fact we believe it will be a particularly pleasant one.

At the present time Julia...

Integers, bits, bytes, and bools

Julia is a strongly typed language allowing the programmer to specify a variable's type precisely. However in common with most interpreted languages it does not require the type to be declared when a variable is declared, rather it infers it from the form of the declaration.

A variable in Julia is any combination of upper or lowercase letters, digits and the underscore (_) and exclamation (!) characters. It must start with a letter or an underscore _. Conventionally variable names consist of lowercase letters with long names separated by underscores rather than using camel case.

To determine a variable type we can use the typeof() function.

So typically:

julia>  x = 2;   typeof(x)  #  =>  gives Int64
julia>  x = 2.0;  typeof(x) # =>  gives Float64

Notice that the type (see the preceding code) starts with a capital letter and ends with a number which indicates the number of bit length of the variable. The bit length defaults to the word length...

Arrays

An array is an indexable collection of (normally) homogeneous values such as integers, floats, booleans. In Julia, unlike many programming languages, the index starts at 1 not 0.

One simple way to create an array is to enumerate its values:

julia> A = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377];
15-element Array{Int64,1}

These are the first 15 values of the Fibonacci series and because all values are listed as integers the array created is of type Int64. The other number refers to the number of dimensions of the array, in this case 1.

In conjunction of loops in the Asian option example in the previous chapter, we meet the definition of a range as: start:[step]:end

julia> A = [1:10]; B = [1:3:15]; C =[1:0.5:5];

Here A is [1,2,3,4,5,6,7,8,9,10], B is [1,4,7,10,13] and C is [1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0]

Because the step in C is specified as a float value the array is of type Float64 not Int64.

Julia also provides functions such as zeros, ones and rand which provide...

Char and strings

So far we have been dealing with numeric and boolean datatypes. In this section we will look at character representation and how Julia handles ASCII and UTF-8 strings of characters. We will also introduce the concept of regular expressions, widely used in pattern matching and filtering operations.

Characters

Julia has a built-in type Char to represent a character. A character occupies 32 bits not 8, so a character can represent a UTF-8 symbol and may be assigned in a number of ways:

julia> c = 'A'
julia> c = char(65)
julia> c = '\U0041'

All these represent the ASCII character capital A.

It is possible to specify a character code of '\Uffff' but char conversion does not check that every value is valid. However, Julia provides an isvalid_char() function:

julia> c = '\Udff3';
julia> is_valid_char(c; ) # => gives false.

Julia uses the special C-like syntax for certain ASCII control characters such as '\b',&apos...

Real, complex, and rational numbers

Now we will consider how to handle real and complex numbers in Julia and also introduce an alternate representation of fixed-point reals as a fraction comprising two integers, the Rational datatype.

Further we will discuss the use of the Big() function to handle integers and real numbers which are too large to be represented by the primitive Julia numeric types.

Reals

We have met real numbers a few times already. The generic type is FloatingPoint which is sub-classed from Real:

abstract Real <: Number
abstract FloatingPoint <: Real
bitstype 16 Float16 <: FloatingPoint
bitstype 32 Float32 <: FloatingPoint
bitstype 64 Float64 <: FloatingPoint

A float can be defined as x = 100.0 or x = 1e2 or x = 1f2; all represent the number 100.

The first will be of the type equivalent to WORD_SIZE, the second of type Float64 and the third (using f rather than the e notation) of type Float32.

There is also a p notation which can be used with hexadecimals, that...

Composite types

A composition type is a collection of named fields, grouped together and treated as a single entity; these are termed records and structures in some programming languages.

If the type can also have functions (methods) associated with them the resulting collection is termed an object and the languages which support them (Java, C++, Python, Ruby, and so on) as object-oriented.

In Julia, functions are not bundled up with the data structures they operate on. The choice of the method a function uses is termed dispatch. When the types of ALL of a function's arguments are considered when determining the method employed, this is termed multiple dispatch and Julia uses this rather than the single dispatch we associated with object methods. We will be considering the implication of multiple dispatch in detail in the next chapter.

Composite type details are defined with the type keyword, followed by a list of field names, optionally annotated with the :: operator and terminated with...

Integers, bits, bytes, and bools


Julia is a strongly typed language allowing the programmer to specify a variable's type precisely. However in common with most interpreted languages it does not require the type to be declared when a variable is declared, rather it infers it from the form of the declaration.

A variable in Julia is any combination of upper or lowercase letters, digits and the underscore (_) and exclamation (!) characters. It must start with a letter or an underscore _. Conventionally variable names consist of lowercase letters with long names separated by underscores rather than using camel case.

To determine a variable type we can use the typeof() function.

So typically:

julia>  x = 2;   typeof(x)  #  =>  gives Int64
julia>  x = 2.0;  typeof(x) # =>  gives Float64

Notice that the type (see the preceding code) starts with a capital letter and ends with a number which indicates the number of bit length of the variable. The bit length defaults to the word length of...

Arrays


An array is an indexable collection of (normally) homogeneous values such as integers, floats, booleans. In Julia, unlike many programming languages, the index starts at 1 not 0.

One simple way to create an array is to enumerate its values:

julia> A = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377];
15-element Array{Int64,1}

These are the first 15 values of the Fibonacci series and because all values are listed as integers the array created is of type Int64. The other number refers to the number of dimensions of the array, in this case 1.

In conjunction of loops in the Asian option example in the previous chapter, we meet the definition of a range as: start:[step]:end

julia> A = [1:10]; B = [1:3:15]; C =[1:0.5:5];

Here A is [1,2,3,4,5,6,7,8,9,10], B is [1,4,7,10,13] and C is [1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0]

Because the step in C is specified as a float value the array is of type Float64 not Int64.

Julia also provides functions such as zeros, ones and rand which provide...

Char and strings


So far we have been dealing with numeric and boolean datatypes. In this section we will look at character representation and how Julia handles ASCII and UTF-8 strings of characters. We will also introduce the concept of regular expressions, widely used in pattern matching and filtering operations.

Characters

Julia has a built-in type Char to represent a character. A character occupies 32 bits not 8, so a character can represent a UTF-8 symbol and may be assigned in a number of ways:

julia> c = 'A'
julia> c = char(65)
julia> c = '\U0041'

All these represent the ASCII character capital A.

It is possible to specify a character code of '\Uffff' but char conversion does not check that every value is valid. However, Julia provides an isvalid_char() function:

julia> c = '\Udff3';
julia> is_valid_char(c; ) # => gives false.

Julia uses the special C-like syntax for certain ASCII control characters such as '\b','\t','\n','\r',\'f' for backspace, tab, newline, carriage...

Real, complex, and rational numbers


Now we will consider how to handle real and complex numbers in Julia and also introduce an alternate representation of fixed-point reals as a fraction comprising two integers, the Rational datatype.

Further we will discuss the use of the Big() function to handle integers and real numbers which are too large to be represented by the primitive Julia numeric types.

Reals

We have met real numbers a few times already. The generic type is FloatingPoint which is sub-classed from Real:

abstract Real <: Number
abstract FloatingPoint <: Real
bitstype 16 Float16 <: FloatingPoint
bitstype 32 Float32 <: FloatingPoint
bitstype 64 Float64 <: FloatingPoint

A float can be defined as x = 100.0 or x = 1e2 or x = 1f2; all represent the number 100.

The first will be of the type equivalent to WORD_SIZE, the second of type Float64 and the third (using f rather than the e notation) of type Float32.

There is also a p notation which can be used with hexadecimals, that is...

Left arrow icon Right arrow icon

Description

Julia is a well-constructed programming language with fast execution speed, eliminating the classic problem of performing analysis in one language and translating it for performance into a second. This book will help you develop and enhance your programming skills in Julia to solve real-world automation challenges. This book starts off with a refresher on installing and running Julia on different platforms. Next, you will compare the different ways of working with Julia and explore Julia's key features in-depth by looking at design and build. You will see how data works using simple statistics and analytics, and discover Julia's speed, its real strength, which makes it particularly useful in highly intensive computing tasks and observe how Julia can cooperate with external processes in order to enhance graphics and data visualization. Finally, you will look into meta-programming and learn how it adds great power to the language and establish networking and distributed computing with Julia.

What you will learn

  • Install and build Julia and configure it with your environment Build a data science project through the entire cycle of ETL, analytics, and data visualization Understand the type system and principles of multiple dispatch for a better coding experience in Julia Interact with data files and data frames to study simple statistics and analytics Display graphics and visualizations to carry out modeling and simulation in Julia Use Julia to interact with SQL and NoSQL databases Work with distributed systems on the Web and in the cloud Develop your own packages and contribute to the Julia Community

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 22, 2015
Length: 410 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553327
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 22, 2015
Length: 410 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553327
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 159.97
Getting started with Julia Programming Language
$43.99
Mastering Julia
$60.99
Julia for Data Science
$54.99
Total $ 159.97 Stars icon

Table of Contents

11 Chapters
1. The Julia Environment Chevron down icon Chevron up icon
2. Developing in Julia Chevron down icon Chevron up icon
3. Types and Dispatch Chevron down icon Chevron up icon
4. Interoperability Chevron down icon Chevron up icon
5. Working with Data Chevron down icon Chevron up icon
6. Scientific Programming Chevron down icon Chevron up icon
7. Graphics Chevron down icon Chevron up icon
8. Databases Chevron down icon Chevron up icon
9. Networking Chevron down icon Chevron up icon
10. Working with Julia Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(7 Ratings)
5 star 57.1%
4 star 28.6%
3 star 14.3%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




James Jul 01, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Came recommended from a friend, the book helped allot with my studies. I can highly recommend this book to anyone who wants to learn or is learning about Julia.
Amazon Verified review Amazon
Amazon Customer Dec 11, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The definitive work on Julia and its capabilities.
Amazon Verified review Amazon
Alessandro Piovaccari Sep 24, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have been using many programming languages over the years, and I find Julia efficient and fascinating. Julia combines the power and versatility of Python and it's extension, with the simplicity of Matlab. This, like many other PACKT books, is very well written and quite useful if are seriously thinking about using Julia for your scientific computing.
Amazon Verified review Amazon
Jan Galkowski Dec 06, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Nice introduction. Doesn't answer the basic question, though, of why to use Julia when there are so many other good options out there.
Amazon Verified review Amazon
Amazon Customer Nov 10, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I thought this was a very good book because I find the Julia documentation lacking. The Julia language can do so many things and the author tried to explore them all, but this was also why it got 4 stars and not 5. It is entitled Mastering Julia, but when I finished I didn't feel like I had mastered Julia. I did have a much better understanding of Julia, though, and for that I thank the author. I have been a professional programmer since the 1980s and worked with at least a dozen different languages. I really like the Julia language, it's portability, and it's ease of use especially when doing the parallel programming aspects. I ask the author to look at the book pairings like: Java in a Nutshell and Java Examples in a Nutshell. Programmers learn by example when moving to another language. I think more fledged out examples would be helpful.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Modal Close icon
Modal Close icon