SlideShare a Scribd company logo
Multimethods for abstraction and
performance
Jiahao Chen
Research Scientist
MIT CSAIL
jiahao.github.io
GitHub: @jiahao
People like to reinvent programming languages
Alan Edelman Andreas Noack Xianyi Zhang Jarrett Revels
Oscar BlumbergDavid Sanders
The
Julia Lab
at MIT
Simon Danisch
Jiahao Chen
Weijian Zhang
U. Manchester
Jake Bolewski
USAP
Shashi GowdaAmit Murthy Tanmay Mohapatra
Eka Palamadai
Collaborators
Joey Huchette
Isaac Virshup
Steven Johnson
MIT Mathematics
Yes Sian Ng Miles Lubin Iain Dunning
Jon Malmaud Simon Kornblith
Yichao Yu
Harvard
Jeremy Kepner
Lincoln Labs
Stavros
Papadopoulos
Intel Labs
Nikos
Patsopoulos
Brigham Woman’s
Hospital
Pete Szolovits
CSAIL
Alex Townsend
MIT Mathematics
Jack Poulson
Stanford
Mike Innes
Julia Computing
Summer of
Code alums
Keno Fischer
Julia Computing
Jameson Nash
Julia Computing
Simon Danisch
Julia Lab
Shashi Gowda
Julia Lab
Leah Hanson
Stripe
John Myles White
Facebook
Jarrett Revels
Julia Lab
2013
2014
2015
Jacob Quinn
Domo
Kenta Sato
U. Tokyo
Rohit Varkey Thankachan
Nat’l Inst. Tech. Karnataka
Simon Danish
Julia Lab
David Gold
U. Washington
Keno FischerJameson NashStefan KarpinskiJeff Bezanson Viral B. Shah
Alums at
Mike Innes
445 contributors to Julia
726 package authors
as of 2016-03-15
https://github.com/jiahao/ijulia-notebooks
The world of
808 packages, 726 authors
445 contributors to julia repo
6,841 stargazers
549 watchers
What’s the big deal about Julia ?
A high level language
with C-like speed
julialang.org/benchmarks
What’s the big deal about Julia ?
Normalized average lines of code (shortest = 0, longest = 1)
Execution time (C = 1)
https://groups.google.com/d/msg/julia-users/BYRAeQJuvTw/O7VK7-vp1EEJ
fast and expressive
A simple example
It bridges the divide between computer science
and computational science
What’s the big deal about Julia ?
It bridges the divide between computer science
and computational science
What’s the big deal about Julia ?
data abstraction
performance
It bridges the divide between computer science
and computational science
What’s the big deal about Julia ?
data abstraction
performance
What if you didn’t have to choose between
data abstraction and performance?
Thesis:
Users want to write generic code.
Users also want native machine performance (when available).
Julia’s generic function system with multimethods (multiple
dispatch) lets you have both.
Is Julia object oriented?
Yes, but maybe not in a way you’re familiar with.*
Generic functions** like in CLOS,
unlike C++ classes.
*G. Castagna, Object Oriented Programming: A Unified Foundation, http://link.springer.com/book/10.1007/978-1-4612-4138-6
**L. G. DeMichiel and R. P. Gabriel, §3.2 of The Common Lisp Object System: An Overview, http://www.dreamsongs.com/Files/ECOOP.pdf
Object-oriented programming with classes
What can I do with/to a thing?
methods objects
Object-oriented programming with classes
What can I do with/to a thing?
methods objects
Object-oriented programming with classes
What can I do with/to a thing?
methods objects
Object-oriented programming with classes
What can I do with/to a thing?
top up
pay fare
lose
buy
methods objects
Object-oriented programming with classes
What can I do with/to a thing?
top up
pay fare
lose
buy
top up
pay fare
lose
buy
methods objects
Object-oriented programming with classes
What can I do with/to a thing?
top up
pay fare
lose
buy
top up
pay fare
lose
buy
methods objects
Object-oriented programming with classes
What can I do with/to a thing?
top up
pay fare
lose
buy
top up
pay fare
lose
buy
pay fare
lose
buy
methods objects
Object-oriented programming with classes
What can I do with/to a thing?
top up
pay fare
lose
buy
classes are more
fundamental
than methods
top up
pay fare
lose
buy
pay fare
lose
buy
OOP with classes multimethods
What can I do with/to a thing?
top up
pay fare
lose
buy
generic
function
objectsmethods
multimethods
relationships between
objects and functions
Multimethods for linear algebra
What can I do with/to a thing?
compute spectral factorization
compute singular values
compute singular values and vectors
compute eigenvalues
generic
function
objectsmethods
Methods can take advantage of special matrix structures
eigvals
eigfact
svdvals
svdfact
Matrix
SymTridiagonal
Bidiagonal
Data types as a lattice
D. Scott, “Data types as lattices”, SIAM J. Comput. 5: 522-87, 1976, doi:10.1137/0205037
Real
Number
FloatingPoint Rational
Complex
Float64 BigFloat…
…
Integer
is a parameter of
is a subtype of
Signed BigInt
Any
Int64…
…
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
no method here
try supertype
super(Int64) = Signed
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
no method here
try supertype
super(Int64) = Signed
no method here either
super(Signed) = Integer
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
no method here
try supertype
super(Int64) = Signed
no method here either
super(Signed) = Integer
found a method
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
Signed
Multimethods with type lattice traversal
Real
Number
FloatingPoint Rational
Float64 BigFloat…
Integer
is a parameter of
is a subtype of
BigInt
Any
Int64…
…
easy to call external C
functions, e.g. CLAPACK
sstev, dstev…
So how does this help us with linear algebra?
Multi-method dispatch with generic fallbacks
Matrix operations on general rings
So how does this help us with linear algebra?
Multi-method dispatch with generic fallbacks
Matrix operations on general rings textbook algorithm
So how does this help us with linear algebra?
Multi-method dispatch with generic fallbacks
Matrix operations on general rings
Native parallelism constructs
Native parallelism constructs
Native parallelism constructs
JuMP: a domain specific language
Iain Dunning Miles Lubin
MIT
Operations Research
Joey HuchetteYes Sian Ng
http://github.com/JuliaLang/IJulia.jl
http://blog.jupyter.org/2016/02/16/jupyterdays-boston-2016/
In summary,
Types helps users express scientific computations
and helps the compiler specialize code for performance
Other advanced features for genericness and performance:
metaprogramming with macros and generated functions,
parametric polymorphism, native parallel computing, …
try Julia today!
juliabox.org
JuliaCon - June 21-25 at MIT CSAIL
juliacon.org
Other references
B. Liskov, The Power of Abstraction, Turing Award lecture,
OOPSLA’09. https://www.youtube.com/watch?
v=qAKrMdUycb8
J. Sammet, Programming Languages: History and
Fundamentals, Prentice-Hall, 1969.
Are classes really that bad?
Yes, when you break their abstraction.
http://okmij.org/ftp/Computation/Subtyping/
The circle-ellipse problem (aka the square-rectangle problem)
The circle-ellipse problem (aka the square-rectangle problem)
Is a circle an ellipse?
The circle-ellipse problem (aka the square-rectangle problem)
Is a circle an ellipse?
Yes: it is a special case of an ellipse with
degenerate foci
zero eccentricity
etc.
The circle-ellipse problem (aka the square-rectangle problem)
Is a circle an ellipse?
Yes: it is a special case of an ellipse with
degenerate foci
zero eccentricity
etc.
No: it makes no sense to change the second focus of a circle.
The circle-ellipse problem
#Program A
foo = Ellipse(r1 = 0.5, r2 = 1.0)
get_r2(foo)
The circle-ellipse problem
#Program A
foo = Ellipse(r1 = 0.5, r2 = 1.0)
get_r2(foo)
Circle(r = 0.5)
The circle-ellipse problem
#Program A
foo = Ellipse(r1 = 0.5, r2 = 1.0)
get_r2(foo)
Circle(r = 0.5)
You can make this program work: define
get_r2(x::Circle) = x.r
#Program B
foo = Ellipse()
set_r1(foo, 0.5)
set_r2(foo, 1.0)
get_r1(foo)*get_r2(foo) == 0.5
The circle-ellipse problem
#Program A
foo = Ellipse(r1 = 0.5, r2 = 1.0)
get_r2(foo)
Circle(r = 0.5)
You can make this program work: define
get_r2(x::Circle) = x.r
#Program B
foo = Ellipse()
set_r1(foo, 0.5)
set_r2(foo, 1.0)
get_r1(foo)*get_r2(foo) == 0.5
The circle-ellipse problem
#Program A
foo = Ellipse(r1 = 0.5, r2 = 1.0)
get_r2(foo)
Circle()
Circle(r = 0.5)
You can make this program work: define
get_r2(x::Circle) = x.r
#Program B
foo = Ellipse()
set_r1(foo, 0.5)
set_r2(foo, 1.0)
get_r1(foo)*get_r2(foo) == 0.5
The circle-ellipse problem
#Program A
foo = Ellipse(r1 = 0.5, r2 = 1.0)
get_r2(foo)
Circle()
Circle(r = 0.5)
You can’t substitute a Circle for an Ellipse in this program.
You can make this program work: define
get_r2(x::Circle) = x.r
#Program B
foo = Ellipse()
set_r1(foo, 0.5)
set_r2(foo, 1.0)
get_r1(foo)*get_r2(foo) == 0.5
The circle-ellipse problem
#Program A
foo = Ellipse(r1 = 0.5, r2 = 1.0)
get_r2(foo)
Circle()
Circle(r = 0.5)
You can’t substitute a Circle for an Ellipse in this program.
You can make this program work: define
get_r2(x::Circle) = x.r
If you can mutate objects (“covariant context”)*, then circles
are not ellipses because of the Liskov substitution
principle** (one of the SOLID principles).
*G. Castagna, Covariance and contravariance : conflict without a cause.
In Object Oriented Programming: A Unified Foundation, http://link.springer.com/book/10.1007/978-1-4612-4138-6
**B. Liskov, Keynote address - data abstraction and hierarchy, OOPSLA '87 Proceedings Addendum, 17-34.
B. Liskov and J. M. Wing. "A Behavioral Notion of Subtyping," ACM Trans. Programming Languages and Systems 16(6):1811-1841, Nov 1994.
n-ary operations
mylist = ListOfNumbers();
mylist.push!(1.0);
n-ary operations
Methods are associated with classes.
mylist = ListOfNumbers();
mylist.push!(1.0);
n-ary operations
Methods are associated with classes.
mylist = ListOfNumbers();
mylist.push!(1.0);
A unary operation on a class can be implemented as a
method of that class.
The abstraction of classes can break down for functions
involving multiple classes.
n-ary operations
Neither. Matrix + DiagonalMatrix needs to access private
fields, thus breaking encapsulation*.
*A loaded term; see D. J. Armstrong, The quarks of object-oriented development, Commun. ACM 49 (2): 123-8, Feb 2006, doi:10.1145/1113034.1113040
n-ary operations
Adding a diagonal matrix and an ordinary (dense) matrix:
is it a method of Matrix or DiagonalMatrix?
Neither. Matrix + DiagonalMatrix needs to access private
fields, thus breaking encapsulation*.
*A loaded term; see D. J. Armstrong, The quarks of object-oriented development, Commun. ACM 49 (2): 123-8, Feb 2006, doi:10.1145/1113034.1113040
n-ary operations
Adding a diagonal matrix and an ordinary (dense) matrix:
is it a method of Matrix or DiagonalMatrix?
class Matrix {
private:
int m, n;
float *data;
// …
friend Matrix operator+(Matrix M, DiagonalMatrix D); //non-member function
};
class DiagonalMatrix{
private:
int n;
//store only the diagonals
float *diagonaldata;
// …
friend Matrix operator+(Matrix M, DiagonalMatrix D); //non-member function
};
Neither. Matrix + DiagonalMatrix needs to access private
fields, thus breaking encapsulation*.
*A loaded term; see D. J. Armstrong, The quarks of object-oriented development, Commun. ACM 49 (2): 123-8, Feb 2006, doi:10.1145/1113034.1113040

More Related Content

Viewers also liked

Genomics data analysis in Julia
Genomics data analysis in JuliaGenomics data analysis in Julia
Genomics data analysis in Julia
Jiahao Chen
 
Understanding ECG signals in the MIMIC II database
Understanding ECG signals in the MIMIC II databaseUnderstanding ECG signals in the MIMIC II database
Understanding ECG signals in the MIMIC II database
Jiahao Chen
 
A Julia package for iterative SVDs with applications to genomics data analysis
A Julia package for iterative SVDs with applications to genomics data analysisA Julia package for iterative SVDs with applications to genomics data analysis
A Julia package for iterative SVDs with applications to genomics data analysis
Jiahao Chen
 
Julia: compiler and community
Julia: compiler and communityJulia: compiler and community
Julia: compiler and community
Jiahao Chen
 
Resolving the dissociation catastrophe in fluctuating-charge models
Resolving the dissociation catastrophe in fluctuating-charge modelsResolving the dissociation catastrophe in fluctuating-charge models
Resolving the dissociation catastrophe in fluctuating-charge modelsJiahao Chen
 
A brief introduction to Hartree-Fock and TDDFT
A brief introduction to Hartree-Fock and TDDFTA brief introduction to Hartree-Fock and TDDFT
A brief introduction to Hartree-Fock and TDDFTJiahao Chen
 
Group meeting 3/11 - sticky electrons
Group meeting 3/11 - sticky electronsGroup meeting 3/11 - sticky electrons
Group meeting 3/11 - sticky electronsJiahao Chen
 
Excitation Energy Transfer In Photosynthetic Membranes
Excitation Energy Transfer In Photosynthetic MembranesExcitation Energy Transfer In Photosynthetic Membranes
Excitation Energy Transfer In Photosynthetic MembranesJiahao Chen
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in JuliaJiahao Chen
 
Theory and application of fluctuating-charge models
Theory and application of fluctuating-charge modelsTheory and application of fluctuating-charge models
Theory and application of fluctuating-charge models
Jiahao Chen
 
Python as number crunching code glue
Python as number crunching code gluePython as number crunching code glue
Python as number crunching code glue
Jiahao Chen
 

Viewers also liked (11)

Genomics data analysis in Julia
Genomics data analysis in JuliaGenomics data analysis in Julia
Genomics data analysis in Julia
 
Understanding ECG signals in the MIMIC II database
Understanding ECG signals in the MIMIC II databaseUnderstanding ECG signals in the MIMIC II database
Understanding ECG signals in the MIMIC II database
 
A Julia package for iterative SVDs with applications to genomics data analysis
A Julia package for iterative SVDs with applications to genomics data analysisA Julia package for iterative SVDs with applications to genomics data analysis
A Julia package for iterative SVDs with applications to genomics data analysis
 
Julia: compiler and community
Julia: compiler and communityJulia: compiler and community
Julia: compiler and community
 
Resolving the dissociation catastrophe in fluctuating-charge models
Resolving the dissociation catastrophe in fluctuating-charge modelsResolving the dissociation catastrophe in fluctuating-charge models
Resolving the dissociation catastrophe in fluctuating-charge models
 
A brief introduction to Hartree-Fock and TDDFT
A brief introduction to Hartree-Fock and TDDFTA brief introduction to Hartree-Fock and TDDFT
A brief introduction to Hartree-Fock and TDDFT
 
Group meeting 3/11 - sticky electrons
Group meeting 3/11 - sticky electronsGroup meeting 3/11 - sticky electrons
Group meeting 3/11 - sticky electrons
 
Excitation Energy Transfer In Photosynthetic Membranes
Excitation Energy Transfer In Photosynthetic MembranesExcitation Energy Transfer In Photosynthetic Membranes
Excitation Energy Transfer In Photosynthetic Membranes
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in Julia
 
Theory and application of fluctuating-charge models
Theory and application of fluctuating-charge modelsTheory and application of fluctuating-charge models
Theory and application of fluctuating-charge models
 
Python as number crunching code glue
Python as number crunching code gluePython as number crunching code glue
Python as number crunching code glue
 

Similar to Julia: Multimethods for abstraction and performance

Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
Ruth Marvin
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
Kevlin Henney
 
Array computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyDataArray computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyData
Travis Oliphant
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
Tariq Rashid
 
Python made easy
Python made easy Python made easy
Python made easy
Abhishek kumar
 
Algorithms - a brief introduction
Algorithms - a brief introductionAlgorithms - a brief introduction
Algorithms - a brief introduction
Giacomo Belocchi
 
The Python Workshop.pdf
The Python Workshop.pdfThe Python Workshop.pdf
The Python Workshop.pdf
Sergio Tavares Coutinho
 
The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2
Coursetro Com
 
Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.
Olivier Teytaud
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
Ruth Marvin
 
FP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad NawatheFP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad Nawathe
Chandulal Kavar
 
Creating Profiling Tools to Analyze and Optimize FiPy Presentation
Creating Profiling Tools to Analyze and Optimize FiPy PresentationCreating Profiling Tools to Analyze and Optimize FiPy Presentation
Creating Profiling Tools to Analyze and Optimize FiPy Presentationdmurali2
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
kavinilavuG
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python
Jean Carlo Machado
 
Artificial intelligence for Social Good
Artificial intelligence for Social GoodArtificial intelligence for Social Good
Artificial intelligence for Social Good
Oana Tifrea-Marciuska
 
Python breakdown-workbook
Python breakdown-workbookPython breakdown-workbook
Python breakdown-workbook
HARUN PEHLIVAN
 
Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)
Scott Wlaschin
 
Pythonlearn-01-Intro.pptx
Pythonlearn-01-Intro.pptxPythonlearn-01-Intro.pptx
Pythonlearn-01-Intro.pptx
MrHackerxD
 

Similar to Julia: Multimethods for abstraction and performance (20)

Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
Array computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyDataArray computing and the evolution of SciPy, NumPy, and PyData
Array computing and the evolution of SciPy, NumPy, and PyData
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
 
Python made easy
Python made easy Python made easy
Python made easy
 
Algorithms - a brief introduction
Algorithms - a brief introductionAlgorithms - a brief introduction
Algorithms - a brief introduction
 
The Python Workshop.pdf
The Python Workshop.pdfThe Python Workshop.pdf
The Python Workshop.pdf
 
The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2
 
Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.Evolutionary deep learning: computer vision.
Evolutionary deep learning: computer vision.
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
 
FP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad NawatheFP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad Nawathe
 
Creating Profiling Tools to Analyze and Optimize FiPy Presentation
Creating Profiling Tools to Analyze and Optimize FiPy PresentationCreating Profiling Tools to Analyze and Optimize FiPy Presentation
Creating Profiling Tools to Analyze and Optimize FiPy Presentation
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python
 
Artificial intelligence for Social Good
Artificial intelligence for Social GoodArtificial intelligence for Social Good
Artificial intelligence for Social Good
 
Python breakdown-workbook
Python breakdown-workbookPython breakdown-workbook
Python breakdown-workbook
 
Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)
 
Pythonlearn-01-Intro.pptx
Pythonlearn-01-Intro.pptxPythonlearn-01-Intro.pptx
Pythonlearn-01-Intro.pptx
 

Recently uploaded

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Julia: Multimethods for abstraction and performance

  • 1. Multimethods for abstraction and performance Jiahao Chen Research Scientist MIT CSAIL jiahao.github.io GitHub: @jiahao
  • 2. People like to reinvent programming languages
  • 3.
  • 4. Alan Edelman Andreas Noack Xianyi Zhang Jarrett Revels Oscar BlumbergDavid Sanders The Julia Lab at MIT Simon Danisch Jiahao Chen Weijian Zhang U. Manchester Jake Bolewski USAP Shashi GowdaAmit Murthy Tanmay Mohapatra Eka Palamadai Collaborators Joey Huchette Isaac Virshup Steven Johnson MIT Mathematics Yes Sian Ng Miles Lubin Iain Dunning Jon Malmaud Simon Kornblith Yichao Yu Harvard Jeremy Kepner Lincoln Labs Stavros Papadopoulos Intel Labs Nikos Patsopoulos Brigham Woman’s Hospital Pete Szolovits CSAIL Alex Townsend MIT Mathematics Jack Poulson Stanford
  • 5. Mike Innes Julia Computing Summer of Code alums Keno Fischer Julia Computing Jameson Nash Julia Computing Simon Danisch Julia Lab Shashi Gowda Julia Lab Leah Hanson Stripe John Myles White Facebook Jarrett Revels Julia Lab 2013 2014 2015 Jacob Quinn Domo Kenta Sato U. Tokyo Rohit Varkey Thankachan Nat’l Inst. Tech. Karnataka Simon Danish Julia Lab David Gold U. Washington Keno FischerJameson NashStefan KarpinskiJeff Bezanson Viral B. Shah Alums at Mike Innes
  • 6. 445 contributors to Julia 726 package authors as of 2016-03-15
  • 7. https://github.com/jiahao/ijulia-notebooks The world of 808 packages, 726 authors 445 contributors to julia repo 6,841 stargazers 549 watchers
  • 8. What’s the big deal about Julia ? A high level language with C-like speed julialang.org/benchmarks
  • 9. What’s the big deal about Julia ? Normalized average lines of code (shortest = 0, longest = 1) Execution time (C = 1) https://groups.google.com/d/msg/julia-users/BYRAeQJuvTw/O7VK7-vp1EEJ fast and expressive
  • 11. It bridges the divide between computer science and computational science What’s the big deal about Julia ?
  • 12. It bridges the divide between computer science and computational science What’s the big deal about Julia ? data abstraction performance
  • 13. It bridges the divide between computer science and computational science What’s the big deal about Julia ? data abstraction performance What if you didn’t have to choose between data abstraction and performance?
  • 14. Thesis: Users want to write generic code. Users also want native machine performance (when available). Julia’s generic function system with multimethods (multiple dispatch) lets you have both.
  • 15. Is Julia object oriented? Yes, but maybe not in a way you’re familiar with.* Generic functions** like in CLOS, unlike C++ classes. *G. Castagna, Object Oriented Programming: A Unified Foundation, http://link.springer.com/book/10.1007/978-1-4612-4138-6 **L. G. DeMichiel and R. P. Gabriel, §3.2 of The Common Lisp Object System: An Overview, http://www.dreamsongs.com/Files/ECOOP.pdf
  • 16. Object-oriented programming with classes What can I do with/to a thing?
  • 17. methods objects Object-oriented programming with classes What can I do with/to a thing?
  • 18. methods objects Object-oriented programming with classes What can I do with/to a thing?
  • 19. methods objects Object-oriented programming with classes What can I do with/to a thing? top up pay fare lose buy
  • 20. methods objects Object-oriented programming with classes What can I do with/to a thing? top up pay fare lose buy top up pay fare lose buy
  • 21. methods objects Object-oriented programming with classes What can I do with/to a thing? top up pay fare lose buy top up pay fare lose buy
  • 22. methods objects Object-oriented programming with classes What can I do with/to a thing? top up pay fare lose buy top up pay fare lose buy pay fare lose buy
  • 23. methods objects Object-oriented programming with classes What can I do with/to a thing? top up pay fare lose buy classes are more fundamental than methods top up pay fare lose buy pay fare lose buy
  • 24. OOP with classes multimethods What can I do with/to a thing? top up pay fare lose buy generic function objectsmethods multimethods relationships between objects and functions
  • 25. Multimethods for linear algebra What can I do with/to a thing? compute spectral factorization compute singular values compute singular values and vectors compute eigenvalues generic function objectsmethods Methods can take advantage of special matrix structures eigvals eigfact svdvals svdfact Matrix SymTridiagonal Bidiagonal
  • 26. Data types as a lattice D. Scott, “Data types as lattices”, SIAM J. Comput. 5: 522-87, 1976, doi:10.1137/0205037 Real Number FloatingPoint Rational Complex Float64 BigFloat… … Integer is a parameter of is a subtype of Signed BigInt Any Int64… …
  • 27. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… …
  • 28. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… …
  • 29. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… …
  • 30. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… … no method here try supertype super(Int64) = Signed
  • 31. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… … no method here try supertype super(Int64) = Signed no method here either super(Signed) = Integer
  • 32. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… … no method here try supertype super(Int64) = Signed no method here either super(Signed) = Integer found a method
  • 33. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… …
  • 34. Signed Multimethods with type lattice traversal Real Number FloatingPoint Rational Float64 BigFloat… Integer is a parameter of is a subtype of BigInt Any Int64… …
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42. easy to call external C functions, e.g. CLAPACK sstev, dstev…
  • 43. So how does this help us with linear algebra? Multi-method dispatch with generic fallbacks Matrix operations on general rings
  • 44. So how does this help us with linear algebra? Multi-method dispatch with generic fallbacks Matrix operations on general rings textbook algorithm
  • 45. So how does this help us with linear algebra? Multi-method dispatch with generic fallbacks Matrix operations on general rings
  • 49. JuMP: a domain specific language Iain Dunning Miles Lubin MIT Operations Research Joey HuchetteYes Sian Ng
  • 51.
  • 52. In summary, Types helps users express scientific computations and helps the compiler specialize code for performance Other advanced features for genericness and performance: metaprogramming with macros and generated functions, parametric polymorphism, native parallel computing, … try Julia today! juliabox.org JuliaCon - June 21-25 at MIT CSAIL juliacon.org
  • 53. Other references B. Liskov, The Power of Abstraction, Turing Award lecture, OOPSLA’09. https://www.youtube.com/watch? v=qAKrMdUycb8 J. Sammet, Programming Languages: History and Fundamentals, Prentice-Hall, 1969.
  • 54. Are classes really that bad? Yes, when you break their abstraction. http://okmij.org/ftp/Computation/Subtyping/
  • 55. The circle-ellipse problem (aka the square-rectangle problem)
  • 56. The circle-ellipse problem (aka the square-rectangle problem) Is a circle an ellipse?
  • 57. The circle-ellipse problem (aka the square-rectangle problem) Is a circle an ellipse? Yes: it is a special case of an ellipse with degenerate foci zero eccentricity etc.
  • 58. The circle-ellipse problem (aka the square-rectangle problem) Is a circle an ellipse? Yes: it is a special case of an ellipse with degenerate foci zero eccentricity etc. No: it makes no sense to change the second focus of a circle.
  • 59. The circle-ellipse problem #Program A foo = Ellipse(r1 = 0.5, r2 = 1.0) get_r2(foo)
  • 60. The circle-ellipse problem #Program A foo = Ellipse(r1 = 0.5, r2 = 1.0) get_r2(foo) Circle(r = 0.5)
  • 61. The circle-ellipse problem #Program A foo = Ellipse(r1 = 0.5, r2 = 1.0) get_r2(foo) Circle(r = 0.5) You can make this program work: define get_r2(x::Circle) = x.r
  • 62. #Program B foo = Ellipse() set_r1(foo, 0.5) set_r2(foo, 1.0) get_r1(foo)*get_r2(foo) == 0.5 The circle-ellipse problem #Program A foo = Ellipse(r1 = 0.5, r2 = 1.0) get_r2(foo) Circle(r = 0.5) You can make this program work: define get_r2(x::Circle) = x.r
  • 63. #Program B foo = Ellipse() set_r1(foo, 0.5) set_r2(foo, 1.0) get_r1(foo)*get_r2(foo) == 0.5 The circle-ellipse problem #Program A foo = Ellipse(r1 = 0.5, r2 = 1.0) get_r2(foo) Circle() Circle(r = 0.5) You can make this program work: define get_r2(x::Circle) = x.r
  • 64. #Program B foo = Ellipse() set_r1(foo, 0.5) set_r2(foo, 1.0) get_r1(foo)*get_r2(foo) == 0.5 The circle-ellipse problem #Program A foo = Ellipse(r1 = 0.5, r2 = 1.0) get_r2(foo) Circle() Circle(r = 0.5) You can’t substitute a Circle for an Ellipse in this program. You can make this program work: define get_r2(x::Circle) = x.r
  • 65. #Program B foo = Ellipse() set_r1(foo, 0.5) set_r2(foo, 1.0) get_r1(foo)*get_r2(foo) == 0.5 The circle-ellipse problem #Program A foo = Ellipse(r1 = 0.5, r2 = 1.0) get_r2(foo) Circle() Circle(r = 0.5) You can’t substitute a Circle for an Ellipse in this program. You can make this program work: define get_r2(x::Circle) = x.r If you can mutate objects (“covariant context”)*, then circles are not ellipses because of the Liskov substitution principle** (one of the SOLID principles). *G. Castagna, Covariance and contravariance : conflict without a cause. In Object Oriented Programming: A Unified Foundation, http://link.springer.com/book/10.1007/978-1-4612-4138-6 **B. Liskov, Keynote address - data abstraction and hierarchy, OOPSLA '87 Proceedings Addendum, 17-34. B. Liskov and J. M. Wing. "A Behavioral Notion of Subtyping," ACM Trans. Programming Languages and Systems 16(6):1811-1841, Nov 1994.
  • 66. n-ary operations mylist = ListOfNumbers(); mylist.push!(1.0);
  • 67. n-ary operations Methods are associated with classes. mylist = ListOfNumbers(); mylist.push!(1.0);
  • 68. n-ary operations Methods are associated with classes. mylist = ListOfNumbers(); mylist.push!(1.0); A unary operation on a class can be implemented as a method of that class. The abstraction of classes can break down for functions involving multiple classes.
  • 69. n-ary operations Neither. Matrix + DiagonalMatrix needs to access private fields, thus breaking encapsulation*. *A loaded term; see D. J. Armstrong, The quarks of object-oriented development, Commun. ACM 49 (2): 123-8, Feb 2006, doi:10.1145/1113034.1113040
  • 70. n-ary operations Adding a diagonal matrix and an ordinary (dense) matrix: is it a method of Matrix or DiagonalMatrix? Neither. Matrix + DiagonalMatrix needs to access private fields, thus breaking encapsulation*. *A loaded term; see D. J. Armstrong, The quarks of object-oriented development, Commun. ACM 49 (2): 123-8, Feb 2006, doi:10.1145/1113034.1113040
  • 71. n-ary operations Adding a diagonal matrix and an ordinary (dense) matrix: is it a method of Matrix or DiagonalMatrix? class Matrix { private: int m, n; float *data; // … friend Matrix operator+(Matrix M, DiagonalMatrix D); //non-member function }; class DiagonalMatrix{ private: int n; //store only the diagonals float *diagonaldata; // … friend Matrix operator+(Matrix M, DiagonalMatrix D); //non-member function }; Neither. Matrix + DiagonalMatrix needs to access private fields, thus breaking encapsulation*. *A loaded term; see D. J. Armstrong, The quarks of object-oriented development, Commun. ACM 49 (2): 123-8, Feb 2006, doi:10.1145/1113034.1113040