10 ms·
Matlab–Python–Julia Cheatsheet
- ForHackernews 7y agoGreat to see Julia gaining more exposure. I worry that it will languish as an obscure research language without strong corporate champions.
- adamnemecek 7y agoJuno is developed by Uber.
- longemen3000 7y agoany source for that? the github of the juno project have 4 people, and none of them are working for Uber
- eigenspace 7y agoI think that’s some misconception coming from the fact that the package in the Atom repository is called Uber-Juno. I don’t think the Juno devs have anything to do with Uber.
- longemen3000 7y agoAhh, yes, that is a plausible explanation. It adds to the fact that not a lot of people know that Uber is a german word, indicating high hierarchy
- wallnuss 7y agoÜber just means above. So "über dir" is "above you". Urban dictionary has uber in english to mean superior, but that is not the original German meaning.
- eigenspace 7y agoThe second example in the first section is a bit misleading. They say that to create a column matrix, ie. an (n, 1) matrix, the syntax is [1 2 3]' but that will give you the (lazy) hermitian adjoint of the column vector, not a column matrix. julia> [1 2 3]' isa Matrix false Instead, if you really need a true (n, 1) matrix you should 1) not use adjoint because that will also take complex conjugates (unless that's what you wanted) and 2) use collect to turn the lazy transpose (or adjoint) into a true matrix julia> collect(transpose([1 2 3])) 3×1 Array{Int64,2}: 1 2 3 However, you almost never need to do this sort of thing and you should be fine using either transpose on a row vector or just using a real column vector. Also, near the end they talk about closures but don't actually show any closures unless one is to assume the code snippets they're showing are actually inside a function body themselves.
- throwawaymath 7y agoGood catch, that's an odd mistake. I would assume the author knows the adjoint isn't equal to the transpose unless the matrix is real. If you only ever work in R then technically that'd be fine (though notationally awkward). But that's not a good habit to keep since it would introduce pretty insidious bugs if you ever take the adjoint of a complex matrix intending to take the transpose.
- ChrisRackauckas 7y agoBut in mathematical derivations, when does a transpose which is not an adjoint ever show up? In many derivations we write transpose knowing that it would be the adjoint if complex numbers are used. That's at least true for most of applied mathematics, statistics, physics, etc.
- eigenspace 7y agoMy point at least was just that it’s a bad idea to use adjoint to construct a column matrix since in that case you likely didn’t intend to take an adjoint, you just wanted a certain shape. There’s no math or physics equation here with objects transforming under an adjoint representation, it’s just a constructor.
- mbeex 7y agoI hate these 2x2 (or nxn) matrix examples. You never know what is considered column and what is row.
- tomrod 7y agoRows, then columns. Lowest index level is column. Follows Pandas, more or less.
- throwawaymath 7y agoJulia takes after Matlab, where matrices are defined by enumerating each row followed by a semicolon. Personally I prefer Mathematica's syntax, but the Julia/Matlab syntax is still way better than Numpy syntax (though to be fair most of that is due to the lack of native matrix support in Python). If it helps at all, this is exactly what you'll see when you create a matrix in Julia: julia> mat = [1 2; 3 4] 2×2 Array{Int64,2}: 1 2 3 4
- dnautics 7y agoFYI you can also do this julia> mat = [1 2 3 4]
- throwawaymath 7y agoOh that's neat. Thanks, I wasn't aware of that.
- FridgeSeal 7y agoI definitely have this problem with Numpy: it just sort of vomits the whole matrix at you and never really makes it clear which one’s which. I haven’t had the problem with Julia though: it will actually format the output and the API’s make it clear when you’re dealing with rows or columns, and which one.
- msaharia 7y agoSo, looks like Julia would be an easier transition for a lot of academic scientists. What am I missing? I mostly use R and Python. Can anyone tell me briefly why I should use Julia over Python?
- pierre_d528 7y ago"Why Does Julia Work So Well? There is an obvious reason to choose Julia: it's faster than other scripting languages, allowing you to have the rapid development of Python/MATLAB/R while producing code that is as fast as C/Fortran" https://ucidatascienceinitiative.github.io/IntroToJulia/Html/WhyJulia https://ucidatascienceinitiative.github.io/IntroToJulia/Html...
- enriquto 7y agoyet the startup time remains slower...
- tomkwong 7y agoStartup feels instant to me. Perhaps you are talking about precompilation. In that case, it’s insignificant for most computationally intensive applications.
- enriquto 7y agoI don't know the difference between startup and precompilation, and I do not really care, but if I launch a julia script from the command line it is unbearably slow for no apparent reason. Octave, on the other hand, launches instantly and starts making computations. This is understandable, because julia is not intended to be used that way. You are supposed to "live" inside the repl. However, I prefer tools that are flexible enough that can be used comfortably in non-intended ways.
- FridgeSeal 7y agoThat’s compilation time. Currently yeah, it’s not fantastic, but I believe that’s being actively worked on.
- inamberclad 7y agoJulia is missing from the Ubuntu 18.04 repos for some reason. 16.04 is stuck at v0.45.
- eigenspace 7y agoYeah, the Julia community for better or worse seems to have an attitude of “don’t get julia from a package manager, download a binary from our website or built it from source.” No doubt this has to do with the fact that releases happen quickly and it’s a giant pain in the ass to go and push binaries to all these package managers.
- ChrisRackauckas 7y agoThis is because LLVM has bugs (like all software) and Julia carries around patched versions of LLVM. Those fixes are being upstreamed over time, but it takes time. Julia is a very hardcore test suite for numerical libraries, so it happens to find things that only show up when numerical stability is pushed to the edge, and Julia Base will have some tests fail if you don't build with the patched LLVM. That said... a lot of users might not notice a difference. But if you want what is known to be the most correct, then you should use the patched one. However, Linux package managers require that you use their LLVM, which in some cases is the wrong version, and in all cases is not the patched one.
- eigenspace 7y agoI didn’t know that the package managers require you to use Linux’s LLVM. That’s a shame. Do all the major package managers do this or is it just apt? I have a relatively new version of Julia from pacman on Arch, I wonder if it has a patched LLVM or not...
- ethelward 7y ago> I didn’t know that the package managers require you to use Linux’s LLVM. That’s a shame. They don't require you to use “Linux's LLVM” (which would not make any sense given that Linux and LLVM are two independent projects), they make you use the version of LLVM they are currently packaging. > Do all the major package managers do this or is it just apt? All the package managers will conceptually do that; however, how old is the considered LLVM will vary strongly depending on the packaging policy of your distribution.
- dzink 7y agoAre there good Tensorflow and Pytorch alternatives in the works writen in Julia?
- chrispeel 7y agoFlux (https://fluxml.ai/ https://fluxml.ai/) is one native Julia ML package. For a more detailed discussion of the use of Julia in the space see https://julialang.org/blog/2018/12/ml-language-compiler https://julialang.org/blog/2018/12/ml-language-compiler
- ChrisRackauckas 7y agoNeural differential equations are something that's worked out in Julia. Neural ordinary differential equations (ODEs), stochastic differential equations (SDEs), and delay differential equations (DDEs) can be found in this blog post (https://julialang.org/blog/2019/01/fluxdiffeq https://julialang.org/blog/2019/01/fluxdiffeq). Neural jump diffusions (jump SDEs) and neural partial differential equations (PDEs) are described here: http://www.stochasticlifestyle.com/ http://www.stochasticlifestyle.com/. All of this is built on the Flux.jl machine learning library which is extremely flexible.
- ddragon 7y agoYes, there are already a couple. The most well known is a 100% Julia neural network library called Flux.jl [1], which aims to become what Swift for Tensorflow wants as well (to make the entire Julia language a fully differentiable language) through Zygote.jl [2], and even without it has already great integration with the ecosystem, for example with the differentiable equations library through DiffEqFlux.jl [3]. Plus the source code is very high level (while being high performance, including easy GPU support), so you can easily see what each component does and implement any extension directly on your code without worrying about performance. There is also another feature complete native library that allows some very concise code, Knet.jl [4], and the Tensorflow bindings [5]. [1] https://github.com/FluxML/Flux.jl https://github.com/FluxML/Flux.jl [2] https://github.com/FluxML/Zygote.jl https://github.com/FluxML/Zygote.jl [3] https://julialang.org/blog/2019/01/fluxdiffeq https://julialang.org/blog/2019/01/fluxdiffeq [4] https://github.com/denizyuret/Knet.jl https://github.com/denizyuret/Knet.jl [5] https://github.com/malmaud/TensorFlow.jl https://github.com/malmaud/TensorFlow.jl
- timmit 7y agoI like it.
- holy_city 7y agoAre there analogs to Simulink or some of MATLAB's toolboxes in Julia? I know of a few shops that use Octave because developer pricing for MATLAB isn't enough when we have an alternative, but there's still a need for a roving license or two because there are a few things lacking in the ecosystem.
- longemen3000 7y agoTBH, Simulink is the golden standard, i don´t know any other alternative. with that in mind, the other toolboxes are easily replaceable with some julia packages, for example in the optimization Toolbox there are various options, like NLSolve(solving no-linear systems),JuMP,Optim,NLOpt (general Optimization). I know that the DifferencialEquations.jl package is the state of the art in ODE solvers. Images.jl provides a good alternative to the Image Toolbox. for what i understand, in the most simple way to put it, simulink is a giant differential equation solver, so you can implement the logic with julia, but the UX of simulink is the best right now
- dagw 7y agoFor Simulink the closest you'll get is probably OMJulia[1] which is a set of Julia bindings to OpenModelica as opposed to a stand alone library [1] https://github.com/OpenModelica/OMJulia.jl https://github.com/OpenModelica/OMJulia.jl
- ddragon 7y agoFor simulation there is also a library that reimplements the Modelica language in Julia using macros: https://github.com/ModiaSim/Modia.jl https://github.com/ModiaSim/Modia.jl
- agumonkey 7y agohow did numpy manage to override `@` in python ? ps: ohh this was introduced in python 3.5 https://stackoverflow.com/questions/27385633/what-is-the-symbol-for-in-python https://stackoverflow.com/questions/27385633/what-is-the-sym... pps: https://pastebin.com/s751DRDi https://pastebin.com/s751DRDi
- aptroninnoida 7y agoThe feature that sets Julia apart from any other language is that it is a dynamically typed, optionally interactive language that is statically analyzed to compile to efficient machine code. http://aptronnoida.in/best-python-training-in-noida.html http://aptronnoida.in/best-python-training-in-noida.html
- bwindsor 7y agoThe final MATLAB example of "Inplace modification" is not correct. function f(out, x) out = x.^2 end x = rand(10) y = zeros(length(x), 1) f(y, x) What happens here when you call f(y, x) is: 1. The arrays x and y are passed to f (no memory copying done yet, since MATLAB uses copy on write) 2. When we have `out = x.^2`, this will allocate a new array in memory and store in it the result of `x.^2`, and will call this `out`. The original `out` which was passed into the function can now be garbage collected (although it won't be, because it's still in the parent scope as 'y') 3. When the function exits, the new `out` goes out of scope and can be garbage collected. So all this example does is allocate a new array, assign x.^2 to it, and then throw that result away again. There's no in-place modification. You can't really pass a matrix by reference in MATLAB like you can in Python, however in some cases you can write your function in a specific way which will ensure in place operations are done and prevent a huge matrix copy. For example (pauses are just there so that you can watch task manager memory usage): function x = inPlace() x = rand(100000000, 1); pause(3); x = doSomething(x); pause(3) end function y = doSomething(y) y = y.^2; end Conditions required are: * Input and output variables must have same name in caller * Input and output variables must have same name in callee * Callee must be inside a function, not a script Look here for a more detailed description: https://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/ https://blogs.mathworks.com/loren/2007/03/22/in-place-operat...
- rhymer 7y agoLast week I converted a simple side project in Python to Julia. It's a sequential Bayeisan estimation problem. A pleasant surprise that the Julia version runs 30x faster than the Python counter part. I am sure the Python code can be improved using Numba and various tricks. But the Julia version simply works with minimum effort. I also feel the language really is built for people doing numerical computing. I smiled when I find out that randn(ComplexF64) gives you circularly-symmetric complex normal random variables. It feels like Julia understands what I want.