Skip to content

Instantly share code, notes, and snippets.

@lungben
lungben / Python Interoperability.jl
Created November 16, 2020 16:57
A Pluto.jl notebook illustrating the interoperability of Julia and Python
### A Pluto.jl notebook ###
# v0.12.10
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
using BenchmarkTools
using PyCall
using DataFrames
using CSV
py"""import timeit
import numpy as np"""
py"""def py_time(f, number=1_000):
@lungben
lungben / mandelbrot.jl
Created December 26, 2020 18:43
Mandelbrot with Pluto.jl
### A Pluto.jl notebook ###
# v0.12.17
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
### A Pluto.jl notebook ###
# v0.12.11
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
@lungben
lungben / python_julia_comparison.md
Last active March 21, 2020 19:52
Comparison of Julia and Python

Comparison of Julia and Python

Python name Python meaning Julia name Julia meaning
def f(x,y): named function - duck-typing, no polymorphism fuction f(x,y) duck-typing, multiple dispatch to methods
lambda x: x anonymous function (x) -> x anonymous function
class MyClass(Parent) classical OOP class, multiple inheritance struct MyStruct{TypeParameters} <: AbstractParent data and constructor only, types inside struct can be parametrized, can inherit only from abstract types
def __init__(self, x): constructor of a class, one per class MyStruct(x) (outer constructor), MyStruct(x) = new(x) (inner constructor) Constructor method (multiple constructors can be defined, selected using multiple dispatch)
method function that belongs to a class (single dispatch on first argument self) method function implementation for concete parameter types (multiple dispatch on all arguments)
a = MyClass(x), x.func(y) Creating an object, calling a method de