Skip to content

Instantly share code, notes, and snippets.

View seba-1511's full-sized avatar

Séb Arnold seba-1511

View GitHub Profile
import torch
import torch.utils.dlpack
import jax
import jax.dlpack
# A generic mechanism for turning a JAX function into a PyTorch function.
def j2t(x_jax):
x_torch = torch.utils.dlpack.from_dlpack(jax.dlpack.to_dlpack(x_jax))
return x_torch
@seba-1511
seba-1511 / hello_world.md
Created April 4, 2020 19:31 — forked from lava/hello_world.md
Hello, world: Deep analysis of a shallow program.

Hello, world!

Please explain in detail what will happen if the following program is executed:

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
}
@seba-1511
seba-1511 / cython_tricks.md
Created February 24, 2020 02:59 — forked from ctokheim/cython_tricks.md
cython tricks

Cython

Cython has two major benefits:

  1. Making python code faster, particularly things that can't be done in scipy/numpy
  2. Wrapping/interfacing with C/C++ code

Cython gains most of it's benefit from statically typing arguments. However, statically typing is not required, in fact, regular python code is valid cython (but don't expect much of a speed up). By incrementally adding more type information, the code can speed up by several factors. This gist just provides a very basic usage of cython.

@seba-1511
seba-1511 / config_dict.py
Created February 21, 2019 18:40 — forked from JACKHAHA363/config_dict.py
A principled way to have config dictionary that can be saved/restored, support pre-defined type and default values, and support cmd parsing
import yaml
import argparse
class _ConfigDict(dict):
""" A subclass of dict that supports required args
"""
# Change this to customize it
fields = []
@classmethod
@seba-1511
seba-1511 / ram_image_example.py
Created November 19, 2018 04:52 — forked from alexlee-gk/ram_image_example.py
Get color and depth image as numpy array using Panda3d 1.10.0 and python 3.5
import numpy as np
import time
import cv2
from direct.showbase.ShowBase import ShowBase
from panda3d.core import FrameBufferProperties, WindowProperties
from panda3d.core import GraphicsPipe, GraphicsOutput
from panda3d.core import Texture
from panda3d.core import loadPrcFileData
loadPrcFileData('', 'show-frame-rate-meter true')
@seba-1511
seba-1511 / example
Created September 15, 2017 19:02 — forked from takluyver/example
Debug on interrupt
$ python3 interrupt-debug.py
0
1
2
3
^C--Return--
> /home/takluyver/scratch/interrupt-debug.py(6)handle_sigint()->None
-> pdb.set_trace()
(Pdb) p a
4