Skip to content

Instantly share code, notes, and snippets.

View yberreby's full-sized avatar

Yohaï-Eliel Berreby yberreby

View GitHub Profile
@yberreby
yberreby / jax_mlp.py
Created December 13, 2023 21:06
Minimal MLP in JAX - excerpt from the "Working with Pytrees" section of the JAX manual
import numpy as np
import jax
import jax.numpy as jnp
import matplotlib.pyplot as plt
def init_mlp_params(layer_widths):
params = []
for n_in, n_out in zip(layer_widths[:-1], layer_widths[1:]):
params.append(
dict(weights=np.random.normal(size=(n_in, n_out)) * np.sqrt(2/n_in),
@ TOTAL=10000,DT=.1,xlo=0,xhi=1,ylo=-100,yhi=100
@ NPLOT=1,XP1=w,YP1=V
@ MAXSTOR=10000000
@ BOUNDS=100000
@ dsmin=1e-5,dsmax=0.5,parmin=0,parmax=3,autoxmin=0,autoxmax=1,Ntst=150,Nmax=2000,Npr=500,Ds=0.02,EPSL=1e-7,EPSU=1e-7,EPSS=1e-7,*Y-axis=V
@ autoymax=100,autoymin=-100
@yberreby
yberreby / results
Created September 4, 2016 13:34
Rust Benchmark - printing to stdout
print_macro: 105 ns/iter (+/- 20)
print_macro_locked_stdoutbench: 87 ns/iter (+/- 22)
direct_locked_stdout: 17 ns/iter (+/- 2)
direct_unlocked_stdout: 51 ns/iter (+/- 9)
#![feature(test)]
extern crate test;
use test::Bencher;
const LARGE_NUMBER: i32 = 1_000_000;
#[bench]
fn bench_even_imperative(b: &mut Bencher) {
b.iter(|| {
let mut list = Vec::with_capacity(LARGE_NUMBER as usize / 2 + 1);
### Keybase proof
I hereby claim:
* I am filsmick on github.
* I am yberreby (https://keybase.io/yberreby) on keybase.
* I have a public key whose fingerprint is 0D2A 6DC4 BFB5 8105 832B A469 803E 20B3 F3E1 9D9F
To claim this, I am signing this object:
@yberreby
yberreby / mod.rs
Created June 28, 2015 14:03
src/libstd/rt/unwind/mod.rs - panic handler PoC
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rt)]
#![feature(unmarked_api)]
use std::thread;
use std::any::Any;
use std::rt::unwind::set_panic_handler;
fn main() {
// Use the default handler
panic!("Something's wrong"); // Prints "thread '<main>' panicked at 'Something's wrong', /Users/yohai/code/panic_handlers_test.rs:10"
client_cargo/../src/sector_client.rs:121:32: 121:46 error: no method named `should_close` found for type `core::cell::Ref<'_, glutin_window::GlutinWindow>` in the current scope
client_cargo/../src/sector_client.rs:121 if window.borrow().should_close() { break; }
^~~~~~~~~~~~~~
client_cargo/../src/sector_client.rs:121:32: 121:46 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
client_cargo/../src/sector_client.rs:121:32: 121:46 help: candidate #1: use `window::Window`
client_cargo/../src/sector_client.rs:161:49: 161:50 error: mismatched types:
expected `event::event::Event<input::Input>`,
found `event::event::Event`
(expected enum `input::Input`,
found a different enum `input::Input`) [E0308]
@yberreby
yberreby / array_binsearch.cpp
Created September 11, 2014 11:26
Binary search implementation for native arrays
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
int binary_search(const T& elem, const T* a, const size_t length) {
int middleIndex = length / 2;
T midpoint = a[middleIndex];
if (midpoint == elem) return middleIndex;