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
# bin/python3 | |
__title__ = "quad.py" | |
__author__ = "Alexander Nenninger" | |
__website__ = "https://gist.github.com/AlexanderNenninger" | |
__year__ = 2021 | |
__license__ = "MIT" | |
""" | |
Calculate coordinates of the corners of a quadrilateral from side- and |
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
use std::collections::HashSet; | |
use std::error::Error; | |
use std::fmt; | |
use std::isize; | |
use std::num::ParseIntError; | |
use std::str; | |
pub const INPUT: &str = "input/day13.txt"; | |
#[derive(Debug)] |
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
use std::boxed::Box; | |
type Callback = Box<dyn Fn(&mut f64, &f64)>; | |
type Condition = Box<dyn Fn(&f64, &f64) -> bool>; | |
type Effect = Box<dyn Fn(&mut f64, &f64)>; | |
fn step(u: &mut f64, t: &mut f64, callback: &Callback) { | |
callback(u, t); | |
*t += 1.; | |
*u += 1.; |
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
use std::boxed::Box; | |
type Callback<U, T> = Box<dyn Fn(&mut U, &T)>; | |
type Condition<U, T> = Box<dyn Fn(&U, &T) -> bool>; | |
type Effect<U, T> = Box<dyn Fn(&mut U, &T)>; | |
fn make_callback<U: 'static, T: 'static>( | |
condition: Condition<U, T>, | |
effect: Effect<U, T>, | |
) -> Callback<U, T> { |
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
stmt_index = 'ls = [0]*10000\nfor i in range(10000):\n ls[i] = i\n' | |
stmt_append = 'ls = []\nfor i in range(10000):\n ls.append(i)\n' | |
stmt_comprehension = '[i for i in range(10000)]' | |
t_index = timeit(stmt_index, number=10000) | |
# >>> 3.06s | |
t_append = timeit(stmt_append, number=10000) | |
# >>> 4.23s |
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
import time | |
import numba as nb | |
import numpy as np | |
def timeit(method): | |
"Decorator to time a function" | |
def timed(*args, **kw): | |
ts = time.time() |
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
from numba.decorators import jit | |
import numpy as np | |
#The original version is here: https://gist.github.com/ximeg/587011a65d05f067a29ce9c22894d1d2 | |
#I made small changes and used numba to do it faster. | |
@jit | |
def thresholding_algo2(y, lag, threshold, influence): | |
signals = np.zeros(len(y)) | |
filteredY = np.array(y) |
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
import numpy as np | |
from numpy import ndarray | |
import matplotlib.pyplot as plt | |
from functools import reduce | |
def up(index): | |
i, j = index | |
return i - 1, j |
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
# Lazy Array implementation. The explicit typing allows for static compilation leading to high performance. | |
using LinearAlgebra | |
using BenchmarkTools | |
# Quick implementation of a lazy Array. Yes, it's really *that* simple. | |
mutable struct LazyFunctionArray{F<:Function,T,N} <: AbstractArray{T,N} | |
const f::F # Julia 1.8 const field syntax for convenience | |
const size::NTuple{N,Int} | |
ncalls::Int |
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
*.parquet binary merge=ours | |
*.parquet filter=lfs diff=lfs merge=lfs -text |
OlderNewer