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
Learning Julia
Learning Julia

Learning Julia: Build high-performance applications for scientific computing

Arrow left icon
Profile Icon Anshul Joshi Profile Icon Lakhanpal
Arrow right icon
€8.99 €29.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
eBook Nov 2017 316 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Anshul Joshi Profile Icon Lakhanpal
Arrow right icon
€8.99 €29.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
eBook Nov 2017 316 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

Learning Julia

Revisiting programming paradigms


Before solving a problem, we should always try to understand where it came from, then break the problem into the steps that we will perform to solve it. We should make sure that we consider all the scenarios and the agents that will be involved in solving the problem.

The programming paradigm refers to the breaking up of the programming activity into a structure of thoughts. It is an approach towards a problem and the orientation of sub-tasks. Although a problem can be approached using different paradigms, one paradigm may be more suited to solving it than another.

There are many programming paradigms, so we will only be discussing a few of them here:

  • Imperative
  • Logical
  • Functional
  • Object-oriented

Understanding the programming paradigm is recommended, as one programming language may be more suited to one particular paradigm. For example, C is suited to imperative programming, Haskell is suited to functional programming, and Smalltalk is for object-oriented programming...

Starting with Julia REPL


We have already learned how to start the Julia REPL and evaluate basic statements in it.

There are various options provided by Julia for running the program. We can directly run statements without even opening the REPL:

$ julia -e 'println("Hello World")'
Hello World

We can even run a loop without starting the REPL:

$ julia -e 'for i=1:5; println("Hello World"); end'
Hello World
Hello World

It is also possible to pass arguments:

$ julia -e 'for i in ARGS; println(i); end' k2so r2d2 c3po r4 bb8
k2so
r2d2
c3po
r4
bb8

ARGS is used to take command-line arguments to the script.

We can find the different options that Julia supports using the --help option:

$ julia --help

julia [switches] -- [programfile] [args...]
-v, --version             Display version information
-h, --help                Print this message
-H, --home <dir>          Set location of `julia` executable
-e, --eval <expr>         Evaluate <expr>
-E, --print <expr>        Evaluate and...

Variables in Julia


Just as in other programming languages, we use a variable to store a value that is obtained from a computation or external source.

Start the REPL by typing julia in the Terminal:

$ julia

# assign 100 to a variable x
julia> x = 100
100

# multiple the value in the variable by 5
julia> x*5
500

We can change the values stored in a variable or mutate the state:

# assign a different value to x
# this will replace the existing value in x
julia> x = 24
24

# create another variable y
julia> y = 10
10

Simple operations, such as swapping, are easy:

# swap values of x and y
julia> x,y = y,x
(10,24)

julia> x
10
julia> y
24

The names of variables can start with a character or a "_" (underscore). Julia also allows Unicode names (UTF-8), but not all Unicode names are accepted in the variable name:

julia> _ab = 40
40
julia> @ab = 10
ERROR: syntax: unexpected "="
julia> 1000
1000

Please note "!" (exclamation mark) shouldn't be used in the variable name as functions...

Integers, bits, bytes, and bools


Integers, bits, bytes, bools, and floating point numbers are used in arithmetic operations. Built-in representations of them are called as numeric primitives, and numeric literals are their representations as values in code.

Let’s understand Julia’s primitive numeric types. The following is a table of Integer types, which includes bits, bytes, and bool:

Type

Number of bits

Smallest value

Largest value

Int8

8

-2^7

2^7 - 1

UInt8

8

0

2^8 - 1

Int16

16

-2^15

2^15 - 1

UInt16

16

0

2^16 - 1

Int32

32

-2^31

2^31 - 1

UInt32

32

0

2^32 - 1

Int64

64

-2^63

2^63 - 1

UInt64

64

0

2^64 - 1

Int128

128

-2^127

2^127 - 1

UInt128

128

0

2^128 - 1

Bool

8

false (0)

true (1)

 

The UInt type refers to unsigned integers. These are those integers whose values start from 0.

This table shows the smallest and the largest values that a particular type of integer can hold.

We can also find the smallest and the largest value of a type of integer using the typemin() and typemax() function:

julia> typemax(Int32)
2147483647

julia> typemin(Int32...

Floating point numbers in Julia


It is easy to represent floating point numbers in Julia. They are represented in a similar fashion as they are in other languages:

# Add a decimal point
julia> 100.0
100.0

julia> 24.
24.0

# It is not required to precede a number from the decimal point
julia> .10
0.1

julia> typeof(ans)
Float64

There is a concept of positive zero and negative zero in Julia. They are equal but with different binary representations:

# equating two zeroes
julia> 0.0 == -0.0
true

julia> bits(0.0)
"0000000000000000000000000000000000000000000000000000000000000000"

# different first bit for negative zero
julia> bits(-0.0)
"1000000000000000000000000000000000000000000000000000000000000000"

Exponential notation can be very useful and convenient in various scenarios. It can be used in Julia using e:

julia> 2.99e8
2.99e8

julia> 2.99e8>999999
true

We have been using Float64 in the preceding examples. We can also use Float32 on 64-bit computers if required:

#...

Logical and arithmetic operations in Julia


Logical and arithmetic operations are very similar to in other programming languages. Julia has an exhaustive collection of all the operators required.

Let's start with the most common operators--arithmetic operators.

Performing arithmetic operations

Performing arithmetic operations, as discussed in the examples in previous sections, is straightforward. Julia provides a complete set of operators to work on.

Binary operators: +, -, *, /, ^, and %. These are just the most used and small subset of the binary operators that are available.

julia> a = 10;  b = 20; a + b
30

Unary operators: +, and -.

These are the unary plus and unary minus. The former performs the identity operation and the latter maps the values to their additive inverses.

julia> -4
-4

julia> -(-4)
4

There is a special operator ! that can be used with bool types. It is used to perform negation:

julia> !(4>2)
false

Performing bitwise operations

These are not frequently used, except...

Understanding arrays, matrices, and multidimensional arrays


An array is an indexable collection of objects such as integers, floats, and Booleans, which are stored in a multidimensional grid. Arrays in Julia can contain values of the Any type. Arrays are implemented internally in Julia itself.

In most of the other languages, the indexing of arrays starts with 0. In Julia, it starts with 1:

# creating an array
julia> simple_array = [100,200,300,400,500]
5-element Array{Int64,1}:
100
200
300
400
500

# accessing elements in array
julia> simple_array[2]
200

julia> simple_array[2:4]
3-element Array{Int64,1}:
200
300
400

In the preceding example, we can see that, unlike other programming languages, indexes start from 1.

# creating an array using randomly generated values
julia> rand_array = rand(1:1000,6)
6-element Array{Int64,1}:
378
 57
...

We previously discussed that the types of values in an array are homogeneous:

# types of values in array are homogeneous
julia> another_simple_array...

Understanding DataFrames


A DataFrame is a data structure that has labeled columns, which may individually have different data types. Like a SQL table or a spreadsheet, it has two dimensions. It can also be thought of as a list of dictionaries, but fundamentally, it is different.

DataFrames are the recommended data structure for statistical analysis. Julia provides a package called DataFrames.Jl, which has all the necessary functions to work with DataFrames.

Julia's package, DataFrames, provides three data types:

  • NA: A missing value in Julia is represented by a specific data type, NA.
  • DataArray: The array type defined in the standard Julia library, though it has many features, doesn't provide any specific functionalities for data analysis. The DataArray type provided in DataFrames.jl provides such features (for example if we needed to store some missing values in the array).
  • DataFrame: This is a two-dimensional data structure, such as spreadsheets. It is much like R or Pandas DataFrames and provides...

Summary


In this chapter, we revisited programming paradigms to understand the best approach to the problem. We then explored Julia using the REPL and found out that it is quite easy to get started with Julia. In subsequent sections, we went through the concepts and how primitive data types are used and operated in Julia. After studying integers and floating point operations, we went through important and widely used data structures, arrays, and matrices. Multidimensional arrays used in numerical computing were explained in the section that followed. After arrays, we explored DataArray and DataFrame packages, which are more suited to representing real-world data and are widely used in statistical computing. In the next chapter, we will study functions in Julia.

 

 

 

 

Summary

In this chapter, we revisited programming paradigms to understand the best approach to the problem. We then explored Julia using the REPL and found out that it is quite easy to get started with Julia. In subsequent sections, we went through the concepts and how primitive data types are used and operated in Julia. After studying integers and floating point operations, we went through important and widely used data structures, arrays, and matrices. Multidimensional arrays used in numerical computing were explained in the section that followed. After arrays, we explored DataArray and DataFrame packages, which are more suited to representing real-world data and are widely used in statistical computing. In the next chapter, we will study functions in Julia.

 

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Set up Julia's environment and start building simple programs
  • Explore the technical aspects of Julia and its potential when it comes to speed and data processing
  • Write efficient and high-quality code in Julia

Description

Julia is a highly appropriate language for scientific computing, but it comes with all the required capabilities of a general-purpose language. It allows us to achieve C/Fortran-like performance while maintaining the concise syntax of a scripting language such as Python. It is perfect for building high-performance and concurrent applications. From the basics of its syntax to learning built-in object types, this book covers it all. This book shows you how to write effective functions, reduce code redundancies, and improve code reuse. It will be helpful for new programmers who are starting out with Julia to explore its wide and ever-growing package ecosystem and also for experienced developers/statisticians/data scientists who want to add Julia to their skill-set. The book presents the fundamentals of programming in Julia and in-depth informative examples, using a step-by-step approach. You will be taken through concepts and examples such as doing simple mathematical operations, creating loops, metaprogramming, functions, collections, multiple dispatch, and so on. By the end of the book, you will be able to apply your skills in Julia to create and explore applications of any domain.

Who is this book for?

This book allows existing programmers, statisticians and data scientists to learn the Julia and take its advantage while building applications with complex numerical and scientific computations. Basic knowledge of mathematics is needed to understand the various methods that will be used or created in the book to exploit the capabilities for which Julia is made.

What you will learn

  • Understand Julia s ecosystem and create simple programs
  • Master the type system and create your own types in Julia
  • Understand Julia s type system, annotations, and conversions
  • Define functions and understand meta-programming and multiple dispatch
  • Create graphics and data visualizations using Julia
  • Build programs capable of networking and parallel computation
  • Develop real-world applications and use connections for RDBMS and NoSQL
  • Learn to interact with other programming languages–C and Python—using Julia

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 24, 2017
Length: 316 pages
Edition : 1st
Language : English
ISBN-13 : 9781785885365
Category :
Languages :

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 24, 2017
Length: 316 pages
Edition : 1st
Language : English
ISBN-13 : 9781785885365
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 153.97
Learning Julia
€36.99
Julia for Data Science
€41.99
Julia: High Performance Programming
€74.99
Total 153.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Understanding Julia&#x27;s Ecosystem Chevron down icon Chevron up icon
Programming Concepts with Julia Chevron down icon Chevron up icon
Functions in Julia Chevron down icon Chevron up icon
Understanding Types and Dispatch Chevron down icon Chevron up icon
Working with Control Flow Chevron down icon Chevron up icon
Interoperability and Metaprogramming Chevron down icon Chevron up icon
Numerical and Scientific Computation with Julia Chevron down icon Chevron up icon
Data Visualization and Graphics Chevron down icon Chevron up icon
Connecting with Databases Chevron down icon Chevron up icon
Julia’s Internals Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 0%
1 star 50%
Abhay Aggarwal Dec 12, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Here's a dirty little secret... Programmers love Julia! Only now, the rest of the world is discovering it....I heard about Julia recently from my programming friends, and was intrigued by the claimed possibilities. I thought of it more as marketing hyperbole, since the language is relatively new, and only now gaining traction. I picked this book over the weekend, and went through it, dipping my toes into the Julia world.The book is nicely laid out, introducing you to the origins of Julia, and straightaway taking you into starting with & using Julia. It then walks you through the syntax, operations, structures, operations, and more. Since Julia is primarily used in the field of data science, it has enough content & knowledge to keep the experts happy on harnessing Julia to aid them in their analysis.Overall, I liked the following:1) Structure & detailed layout of the book2) Good intro to engage new users of Julia3) Open source callouts at every turn4) Deep dive content for people who have already been using Julia before5) Conciseness & nice examples to get your hands dirty on actual codeBottomline: This book has enough content to induce new programmers to try out Julia, while keeping current Julia users engaged with stuff they might not know! I recommend it heartily.
Amazon Verified review Amazon
Randy Ford Feb 17, 2018
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
What poorly written book! Bad grammar, filled with jargon, and even though it has been out for 4 months, the example code isn't up yet. I am pretty sure that the 3 five star reviews were written by friends.
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.