Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using InteractiveUtils, Pkg | |
for pk in ["Transducers", "LoopVectorization"] | |
if pk ∉ keys(Pkg.project().dependencies) | |
Pkg.add(pk) | |
end | |
end | |
using Transducers, LoopVectorization | |
function picalc_kernel(r, a, b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools | |
function _pi(x::Vector, y::Vector) | |
acc = 0 | |
@inbounds @simd for i ∈ eachindex(x) | |
acc += (x[i]*x[i] + y[i]*y[i]) < 1.0 | |
end | |
4acc/length(x) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools, StaticArrays, Transducers | |
function _pi_kernel_static() | |
xs = @SVector rand(50) | |
ys = @SVector rand(50) | |
sum(((x, y),) -> x^2 + y^2 < 1.0, zip(xs, ys)) | |
end | |
function _pi_kernel(r) | |
xs = rand(r) | |
ys = rand(r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Syms | |
export sym, Sym | |
#-------------------------------------------------------------------------------- | |
# Set up some symbolic types | |
#-------------------------------------------------------------------------------- | |
abstract type Symbolic{T} end # Symbolic{T} will act like it is <: T | |
struct Sym{T} <: Symbolic{T} | |
name::Symbol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#+BEGIN_SRC jupyter-julia | |
using Interpolations | |
xs = range(-10, 10, length=50) # 50 evenly spaced points from -5 to 5 | |
# model function, some Gaussian | |
f(x; A=1, σ=2, b=0) = A * exp(-x^2/2σ) + b | |
ys = f.(xs) | |
method = BSpline(Cubic(Line(OnGrid()))) #interpolation method | |
f_itp = scale(interpolate(ys, method), xs) # interpolation function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#+BEGIN_SRC julia | |
const ketpat = r"\|.*?\>" | |
ketrep(str) = "Ket("*(match(r"(?<=\|).*?(?=>)", str).match)*")" | |
const brapat = r"\<.*?\|" | |
brarep(str) = "Bra("*(match(r"(?<=<).*?(?=\|)", str).match)*")" | |
function rep_braket(str) | |
replace(replace(str, brapat => brarep), ketpat => ketrep) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#+BEGIN_SRC jupyter-julia | |
using CUDA | |
struct StaticString{N} <: AbstractString | |
chars::NTuple{N, Char} | |
end | |
macro s_str(s) | |
chars = tuple(collect(s)...) | |
N = length(chars) | |
esc(:(StaticString{$N}($chars))) | |
end |
OlderNewer