Skip to content

Instantly share code, notes, and snippets.

View tehrengruber's full-sized avatar

Till Ehrengruber tehrengruber

  • ETH Zuerich
  • Zürich
View GitHub Profile
@tehrengruber
tehrengruber / subtitle_shift.jl
Last active August 29, 2015 14:26
open a subtitle file (typically srt format) from src, shift the time by Δt and write it to dest
# open a subtitle file (typically srt format) from src, shift the time by Δt and write it to dest
Δt = Dates.Second(0)
src = ""
dest = ""
subs = readall(src);
new_subs = replace(subs, r"(\d+):(\d+):(\d+),(\d+)",
(match) -> begin
time_point = DateTime(match, "H:M:S,s")-Δt
@sprintf "%02d:%02d:%02d,%03d" Dates.hour(time_point) Dates.minute(time_point) Dates.second(time_point) Dates.millisecond(time_point)
@tehrengruber
tehrengruber / Convert.hpp
Last active August 29, 2015 14:27
Dune <-> Eigen Matrix, Vector Converter
#include <type_traits>
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
#include <Eigen/Dense>
namespace NPDE15 {
template <class T1, class T2, class Enable = void>
struct Convert{};
/*
@tehrengruber
tehrengruber / split.jl
Created September 11, 2015 15:15
split array into equal parts
A=rand(20)
[A[ceil(step*i)+1:floor(step*(i+1)-0.1)+1] for i=0:parts-1, step=length(A)/parts]

Keybase proof

I hereby claim:

  • I am tehrengruber on github.
  • I am tehrengruber (https://keybase.io/tehrengruber) on keybase.
  • I have a public key whose fingerprint is 675A 2D63 6334 66F9 E5E6 BDD1 D07E 4BB3 AF4C 76E3

To claim this, I am signing this object:

# given some code
code = """
for(int i=0; i<10; ++i) {
a=2
}
"""
# turn code into an array of tokens
# write a function tokenize(code) using https://www.lysator.liu.se/c/ANSI-C-grammar-y.html
# and https://github.com/iamed2/PyLexYacc.jl that allows you to do this
immutable Bla{A}
end
a() = Bla{3*2}
@code_warntype a()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tehrengruber
tehrengruber / field_descriptor.cpp
Created May 5, 2021 21:09
ghex non-type template argument problem for py bindings
template<typename T, typename Arch, typename DomainDescriptor, typename Order>
void export(py::class_<gridtools::ghex::structured::regular::field_descriptor<T, Arch, DomainDescriptor, Order>>> cls) {
// add bindings to cls
// ...
}
using orders = gridtools::meta::list<int_tuple_constant<0, 1, 2>, int_tuple_constant<2, 1, 0>>;
GHEX_PYBIND11_EXPORT_TYPE(gridtools::ghex::structured::regular::field_descriptor,
ghex4py::type_list::architecture_types,
@stencil
def flux_x(phi):
return flux(phi[I - 1], phi)
@stencil
def flux_y(phi):
return flux(phi[J - 1], phi)
@stencil
def step(phi, fx, fy, dx, dy, dt):
@tehrengruber
tehrengruber / bla.py
Last active May 28, 2021 13:21
bla.py
def laplacian(grid: Grid, f: Field[I, J, K, Matrix[3, 3, dtype]]):
def stencil((i, j, k), m):
return l2_norm(m @ [1, 2, 3])
#def stencil(i, j, k, val):
# if (i, j, k) in grid[(I, J, K), "interior"]:
# return -4*f[i, j, k]+f[i-1, j, k]+f[i+1, j, k]+f[i, j-1, k]+f[i, j+1, k]
# else:
...
#return Field(f.domain, stencil)