-
Notifications
You must be signed in to change notification settings - Fork 15
7ML7W Julia Day 3: Become One With Julia
What day? What page? What PDF page?...
There will be no fans at this meeting - they have been 'removed'.
The chapter is pretty short.
The setup process can be quite long for all the tooling. Julia downloads some packages for you that are dependencies of the Julia things we're installing.
It's just quite surprising to see it go off and take an hour downloading it's own homebrew and everything else.
We remembered that factor did something similar - perhaps when running '+' in the repl it'd download a load of stuff in the background... we can't remember exactly.
Tom: if i'd made a programming language I'd try and make sure that it's easily possible to install and use a particular language.
James: how much of that is just homebrew though?
Seems the book does actually say which version the chapter uses...
- Macros in Julia
- Building an image codec
One does not appear to be a pre-requisite for the other...
The Julia days appear to have sampled from the different features that Julia has, rather than having any particular thread throughout.
Murray: is what makes Julia interesting that it's got lots of stuff in it?
Elena: [paraphrasing] remember that it's meant to be an alternative to R. I find it easier to read. I'm sold.
Chris: [paraphrasing] in the docs there's more of an emphasis on the similarities with mathematical syntax.
[repl] Investigation into what the Types of things like :(println("Hello!"))
actually are. Can we annotate their types?
If you want, you can dynamically generate these expressions like so:
Expr(:call, +, 1, 2, myVariable)
Murray+James: Expressions are the first step towards building macros in Julia.
We can use interpolation if we want like this:
julia> quote
println($s)
end
[Elena] I remember that there was an unquote
in factor but not whether it was
doing the same sort of thing...
julia> macro ...
Tom: macro
is a special type of function that returns some code. When using
it, we call the function, get the code back from it and run that code with the
arguments we have.
Murray: it's an important feature that the code isn't eagerly evaluated.
Murray: Why do we invoke macros with the @ sign? It doesn't seem to be required, but is perhaps just a marker for a macro so we're aware of it.
[end macro section 👋]
Elena: Aren't excel macros also preceded with a macro.
James: Excel macros aren't in the spreadsheet like functions. If a spreadsheet is source code then maybe they are macros.
Macros seems to just mean 'scripts' in a few other places.
Chris: do Julia programmers use and define macros a lot?
Murray: the concurrency stuff is all based on macros, and there are a load of them in the std lib. So I expect they use them a lot.
Murray: do lisp programmers even write lots of macros?
James: macros are probably most useful for expanding all the magic behind the scenes of julia's features.
Tom: And macros don't need to just be a source code string interpolation, it can have logic itself to change the behaviour.
[detour into expanding butts with the @parallel macro]
We see that the macro returns an error that "butts" can't be run in parallel.
Tom: [not paraphrasing] where does it evaluate butts?
We started playing with the @macroexpand
macro to see what gets return from
our @parallel "butts"
call.
It seems to be doing some interesting numbering of the local variables - perhaps something about making them unique.
Calling the macro again it seems to increase the number prepended to variables.
Chris: can we macroexpand macroexpand?
Murray: will it ever end. Macroexpand seems to quote the result returned by the macro. Doing it again and again just inserts more quotes...
Moving on...
There's a bit of background on codec and compression.
We wonder if lossy compression can be generalised. It seems that throwing away the things we don't need is common but the means of choosing what to bin is dependent on the media.
James: Compressing a book might be removing all the vowels.
... and that's going to look very different from our JPEG code here.
julia> Pkg.add("Images")
**INFO:** Initializing package repository /home/jack/.julia/v0.3
**INFO:** Cloning METADATA from git://github.com/JuliaLang/METADATA.jl
...
Murray: that ...
implies a lot of output and a lot of time!
It creates its own homebrew installation and sometimes it breaks and it's a bit of a fiddle.
It create it's own private usr folder just with the packages julia needs. It also makes this available to the current Julia installation.
Tom: the downside of course being that you need to rebuild a whole load of stuff.
We expect there are some platform specific things going on here. What does it do on Linux? chroot? containers? We don't know, we may never know.
[James later on: seems that it has a custom tool to manage it's packages and downloads a bunch of stuff from git in the process.]
Using the images library, what you get is an image thing:
julia> img = testimage("cameraman")
Gray Image with:
Now we get a large 2d array of pixels. It doesn't seem to have the Image type any more :( this makes following the book a little harder...
[detour of a few adjustments to see the camera man image, TODO: Murray?]
At the moment, we have a 2d array of Gray
things. Gray is the color space of
our image.
Just looking at the raw pixels it's hard to tell which pixels are the important
ones. Luckily we can use Fourier transform
to get the frequencies. If we trust
that the result of the frequencies transform tells us the 'important' pixels,
then we can see which values in the grid we'd like to keep in our image.
[we're missing some knowledge on what exactly is doing on in the transform here]
James: we should see this grid at the end as a just a list of color we might use, and given that one is much more common, we should use that one.
We subtracted the new array from the original pixels and found that it seems to have worked quite well.
julia> pixels1[1:8,1:8] - pixels2
[grid of very small differences that we've removed in pixels2]
[We see that it's removing the information but still using the same amount of space to store it...]
[I'm missing some notes as I struggle to understand this and eat some more bread
- feel free to expand this section]
Murray: one of the exercises is to actually compress it.
James: we could use run length encoding to see this
[Tom: some of them are negative -0.0s, great]
some time later...
Murray shows the resulting image with clear JPEG-like artefacts. Then proceeds to clean the TV with his cursor alone.
We could maybe do a session on implementing JPEG at some point. We're not sure which parts of it we missed out here in our Julia example.
Why Julia? It's fast and it's got lots of cool things. It's also got concurrency, 'real-macros' (AST transforming rather just strings).
Murray: Julia just feels like a more normal programming language than R which seems to have two ways of assigning to variables...
What are the downsides?
Murray: it seems to be doing a good job of saying this doesn't work any more - do this instead.
Tom: is it strange that it's not reached 1.0 yet? People seem to be using it.
Murray: [paraphrasing] they might not want the expectation that things will stabilize.
BREAKING
Elena: Julia 1.0 is IN STORES NOW [paraphrasing]
Julia con is happening as we speak!
James: [answering the homebrew question] Cairo within Julia is choosing what to install based on the current operating system. E.g. it'll use apt when it's available, or homebrew etc etc.
There are people, not naming any names, that would like a meeting on the remaining two languages.
We're not sure if these would be best following the book or having a DIY session.
We're also not sure if we want one or two meetings for the languages.
We can decide if we need another meeting at the first meeting.
We can likely do our usual thing but if someone did do some more leg work that'd be excellent.
Tom: Why is Benedict Cumberbatch in the bath?
- Home
- Documentation
- Choosing a Topic
- Shows & Tells
- Miscellaneous
- Opt Art
- Reinforcement Learning: An Introduction
- 10 Technical Papers Every Programmer Should Read (At Least Twice)
- 7 More Languages in 7 Weeks
- Lua, Day 1: The Call to Adventure
- Lua, Day 2: Tables All the Way Down
- Lua, Day 3
- Factor, Day 1: Stack On, Stack Off
- Factor, Day 2: Painting the Fence
- Factor, Day 3: Balancing on a Boat
- Elm, Day 1: Handling the Basics
- Elm, Day 2: The Elm Architecture
- Elm, Day 3: The Elm Architecture
- Elixir, Day 1: Laying a Great Foundation
- Elixir, Day 2: Controlling Mutations
- Elixir, Day 3: Spawning and Respawning
- Julia, Day 1: Resistance Is Futile
- Julia, Day 2: Getting Assimilated
- Julia, Day 3: Become One With Julia
- Minikanren, Days 1-3
- Minikanren, Einstein's Puzzle
- Idris Days 1-2
- Types and Programming Languages
- Chapter 1: Introduction
- Chapter 2: Mathematical Preliminaries
- Chapter 3: Untyped Arithmetic Expressions
- Chapter 4: An ML Implementation of Arithmetic Expressions
- Chapter 5: The Untyped Lambda-Calculus
- Chapters 6 & 7: De Bruijn Indices and an ML Implementation of the Lambda-Calculus
- Chapter 8: Typed Arithmetic Expressions
- Chapter 9: The Simply-Typed Lambda Calculus
- Chapter 10: An ML Implementation of Simple Types
- Chapter 11: Simple Extensions
- Chapter 11 Redux: Simple Extensions
- Chapter 13: References
- Chapter 14: Exceptions
- Chapter 15: Subtyping – Part 1
- Chapter 15: Subtyping – Part 2
- Chapter 16: The Metatheory of Subtyping
- Chapter 16: Implementation
- Chapter 18: Case Study: Imperative Objects
- Chapter 19: Case Study: Featherweight Java
- The New Turing Omnibus
- Errata
- Chapter 11: Search Trees
- Chapter 8: Random Numbers
- Chapter 35: Sequential Sorting
- Chapter 58: Predicate Calculus
- Chapter 27: Perceptrons
- Chapter 9: Mathematical Research
- Chapter 16: Genetic Algorithms
- Chapter 37: Public Key Cryptography
- Chapter 6: Game Trees
- Chapter 5: Gödel's Theorem
- Chapter 34: Satisfiability (also featuring: Sentient)
- Chapter 44: Cellular Automata
- Chapter 47: Storing Images
- Chapter 12: Error-Correcting Codes
- Chapter 32: The Fast Fourier Transform
- Chapter 36: Neural Networks That Learn
- Chapter 41: NP-Completeness
- Chapter 55: Iteration and Recursion
- Chapter 19: Computer Vision
- Chapter 61: Searching Strings
- Chapter 66: Church's Thesis
- Chapter 52: Text Compression
- Chapter 22: Minimum spanning tree
- Chapter 64: Logic Programming
- Chapter 60: Computer Viruses
- Show & Tell
- Elements of Computing Systems
- Archived pages