Skip to content

Instantly share code, notes, and snippets.

View hollance's full-sized avatar

Matthijs Hollemans hollance

View GitHub Profile
@pcuenca
pcuenca / MakeContiguousKernel.metal
Created July 29, 2022 12:29
Metal Kernel to make a contiguous copy of MLMultiArray storage
//
// MakeContiguousKernel.metal
//
// Created by Pedro Cuenca on 20220307.
// Copyright © 2022 LateNiteSoft S.L. All rights reserved.
//
#include <metal_stdlib>
using namespace metal;
# IDA (disassembler) and Hex-Rays (decompiler) plugin for Apple AMX
#
# WIP research. (This was edited to add more info after someone posted it to
# Hacker News. Click "Revisions" to see full changes.)
#
# Copyright (c) 2020 dougallj
# Based on Python port of VMX intrinsics plugin:
# Copyright (c) 2019 w4kfu - Synacktiv
@petewarden
petewarden / convert_cc_to_tflite.py
Created February 27, 2020 23:55
Example of converting a .cc TensorFlow Lite C data array file back into a binary flatbuffer on disk
import re
output_data = bytearray()
with open('tensorflow/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.cc', 'r') as file:
for line in file:
values_match = re.match(r"\W*(0x[0-9a-fA-F,x ]+).*", line)
if values_match:
list_text = values_match.group(1)
values_text = filter(None, list_text.split(","))
values = [int(x, base=16) for x in values_text]
output_data.extend(values)
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 16, 2024 01:02
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kendricktan
kendricktan / capsule_networks.py
Last active August 17, 2021 17:12
Clean Code for Capsule Networks
"""
Dynamic Routing Between Capsules
https://arxiv.org/abs/1710.09829
"""
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision.transforms as transforms
@jesseengel
jesseengel / rainbowgram.py
Created September 5, 2017 17:10
Script to plot "rainbowgrams" from NSynth (https://arxiv.org/abs/1704.01279)
import os
import librosa
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['svg.fonttype'] = 'none'
import numpy as np
from scipy.io.wavfile import read as readwav
# Constants
@yossorion
yossorion / what-i-wish-id-known-about-equity-before-joining-a-unicorn.md
Last active April 7, 2024 22:55
What I Wish I'd Known About Equity Before Joining A Unicorn

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@venkatperi
venkatperi / CGContextExt.swift
Created April 24, 2015 20:54
CGContext Syntactic Sugar
// CGContextABCD(context!, ...) becomes context?.ABCD(...)
import Cocoa
extension CGContext {
func saveGState() { CGContextSaveGState(self) }
func restoreGState() { CGContextRestoreGState(self) }
func scaleCTM( sx: CGFloat, sy: CGFloat) { CGContextScaleCTM(self, sx, sy) }
func translateCTM( tx: CGFloat, ty: CGFloat) { CGContextTranslateCTM(self, tx, ty) }
func rotateCTM( angle: CGFloat) { CGContextRotateCTM(self, angle) }