Skip to content

Instantly share code, notes, and snippets.

Avatar
🕵️‍♂️
Deep into the code

Fredrik Johansson fredrik-johansson

🕵️‍♂️
Deep into the code
View GitHub Profile
View gist:b6b65bbab0c0c3eaf583976d0ab1ecbc
bits euclidean binary euclidean_improved
8 3.46e-07 5.05e-07 9.09e-08
16 5.91e-07 7.61e-07 1.65e-07
32 9.65e-07 1.55e-06 2.26e-07
64 5.48e-06 3.89e-06 1.05e-06
128 2.45e-05 1.4e-05 7.41e-06
256 6.06e-05 3.57e-05 1.82e-05
512 0.00015 4.11e-05
1024 0.000459 0.000103
2048 0.00176 0.000248
View color_function.py
from colorsys import hls_to_rgb, rgb_to_hls
import math
import cmath
CLAMP = lambda y: max(0.0, min(y, 1.0))
BLEND = lambda x, y: 0.5*x + 0.5*y
DODGE = lambda a, b: a / (1.0 - b + 1/256.0)
# gimp color balance algorithm
def balance_channel(value, l, shadows, midtones, highlights):
View gr.c
/*
Generic Flint-style rings using void pointers + context objects.
todo: write -> print
Principles/goals/benefits:
* Small code size, fast compilation.
* Possible to pack data efficiently (down to 1 byte / element).
* Plain C, similar interface to existing Flint code.
@fredrik-johansson
fredrik-johansson / nmul.c
Created Apr 5, 2021
Some new nmod_poly multiplication code
View nmul.c
#include "flint/nmod_poly.h"
#include "flint/profiler.h"
/*
Multiplication/squaring using Kronecker substitution at 2^b and -2^b.
*/
void
_nmod_poly_mul_KS2B(mp_ptr res, mp_srcptr op1, slong n1,
mp_srcptr op2, slong n2, nmod_t mod)
@fredrik-johansson
fredrik-johansson / matperf.c
Created Mar 22, 2021
Some old matrix profiling code
View matperf.c
#include "flint/fmpz_mat.h"
#include "flint/profiler.h"
#define TIMEIT_PRINT1(__var, __timer, __reps) \
__var = __timer->cpu*0.001/__reps;
#define TIMEIT_REPEAT1(__timer, __reps) \
do \
{ \
slong __timeit_k; \
@fredrik-johansson
fredrik-johansson / rademacher.py
Created Jul 28, 2020
Extended Rademacher series
View rademacher.py
from flint import fmpq, fmpz
from cmath import *
from mpmath import plot
def dedekind_sum(r, k, _cache={}):
key = (r << 24) | k
if key in _cache:
return _cache[key]
if fmpz(r).gcd(k) != 1:
v = None
View illinois.c
#include "acb_dirichlet.h"
/* todo: separate prec, eval_prec... */
void
acb_dirichlet_zeta_zero_refine_illinois(arb_t res, const arf_t ra, const arf_t rb, slong prec)
{
arf_t a, b, fa, fb, c, fc, t;
acb_t z;
slong k;
int asign, bsign, csign;
View Arbdemo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View stieltjes.c
/*
Copyright (C) 2018 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
View pearcey.c
#include <string.h>
#include "acb_calc.h"
#include "flint/profiler.h"
/* the integrand */
int
f_pearcey(acb_ptr res, const acb_t z, void * param, slong order, slong prec)
{
acb_t t, u;