Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Julia High Performance

You're reading from   Julia High Performance Optimizations, distributed computing, multithreading, and GPU programming with Julia 1.0 and beyond

Arrow left icon
Product type Paperback
Published in Jun 2019
Publisher Packt
ISBN-13 9781788298117
Length 218 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Avik Sengupta Avik Sengupta
Author Profile Icon Avik Sengupta
Avik Sengupta
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Julia is Fast FREE CHAPTER 2. Analyzing Performance 3. Types, Type Inference, and Stability 4. Making Fast Function Calls 5. Fast Numbers 6. Using Arrays 7. Accelerating Code with the GPU 8. Concurrent Programming with Tasks 9. Threads 10. Distributed Computing with Julia 11. Licences
12. Other Books You May Enjoy

Array views

Julia, similarly to most scientific languages, has a very convenient syntax for array slicing. Consider the following example that sums each column of a two-dimensional matrix. First, we will define a function that sums the elements of a vector to produce a scalar. We will then use this function inside a loop to sum the columns of a matrix, passing each column one by one to our vector adder as follows:

function sum_vector(x::Array{Float64, 1}) 
s = zero(eltype(x))
for i in 1:length(x)
s = s + x[i]
end
return s
end

function sum_cols_matrix(x::Array{Float64, 2})
num_cols = size(x, 2)
s = zeros(num_cols)
for i = 1:num_cols
s[i] = sum_vector(x[:, i])
end
return s
end

The x[:, j] syntax denotes all the row elements of the jth column. In other words, it slices a matrix into its individual columns. Benchmarking this function, we will...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime