Skip to content

Instantly share code, notes, and snippets.

View robertknight's full-sized avatar

Robert Knight robertknight

View GitHub Profile
@robertknight
robertknight / accelerate_gemv.cpp
Created March 14, 2024 08:58
Apple Accelerate sgemv benchmark
#include <algorithm>
#include <chrono>
#include <iostream>
#include <iterator>
#include <random>
#include <vector>
#include <Accelerate/Accelerate.h>
#include <cblas.h>
@robertknight
robertknight / rectify.py
Last active March 2, 2024 09:48
Rectify a portion of an image using OpenCV
import cv2
import numpy as np
import argparse
def warp_quadrilateral(
input_path: str,
src_points: list[tuple[int, int]],
output_path: str,
output_size: tuple[int, int],
@robertknight
robertknight / rten_ndarray_conv.rs
Last active January 24, 2024 07:52
rten-ndarray conversion
use ndarray::{Array, Array2, ArrayView, Dim, Dimension, Ix, StrideShape};
use rten_tensor::prelude::*;
use rten_tensor::{NdTensor, NdTensorView};
/// Convert an N-dimensional ndarray view to an [NdTensorView].
///
/// Returns `None` if the view is not in the standard layout (see
/// [ArrayView::is_standard_layout]).
fn as_ndtensor_view<'a, T, const N: usize>(
@robertknight
robertknight / avx-512-gemm-kernel.s
Created December 29, 2023 18:20
Annotated AVX-512 gemm kernel
# At entry params are:
#
# tile_ptr (rdi)
# tile_row_stride (rsi)
# a (rdx, rcx)
# b (r8, r9)
# depth (stack)
# alpha (xmm0)
# beta (xmm1)
.section __TEXT,__text,regular,pure_instructions
//! Port of https://github.com/danieldk/gemm-benchmark/ for comparison of
//! matrix multiplication performance against other popular libraries.
use std::time::Duration;
use wasnn::gemm;
use wasnn_tensor::prelude::*;
use wasnn_tensor::NdTensor;
use rayon::iter::IntoParallelIterator;
@robertknight
robertknight / istanbul.md
Last active December 23, 2023 20:01
How Istanbul works

Istanbul Notes

These are some notes I made while reviewing hypothesis/client#156 to understand how Istanbul works

Istanbul instruments code in order to generate code coverage metrics for tests by adding code to record lines, statements etc. that are executed.

It adds a global __coverage__ variable to the generated code which is a map from file path to coverage information. The code for each module is then augmented with:

@robertknight
robertknight / shallowRender.js
Created April 1, 2017 09:15
Shallow rendering implementation for Preact
import { options, render } from 'preact';
import { ATTR_KEY } from 'preact/src/constants';
/**
* Returns the input properties that were passed to an element when it was
* rendered.
*
* See `shallowRender` documentation for usage example.
*/
@robertknight
robertknight / using-nvda-in-a-windows-vm-on-mac.md
Created July 3, 2017 13:23
Testing the Windows screenreader NVDA on a Mac

How to test NVDA screen reader behaviour on a Mac:

  1. Download Microsoft Edge VM from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
  2. Download Virtualbox and import the Edge VM image.

Then in the VM:

  1. Install guest addons in the VM
  2. Download & install latest NVDA from nvaccess.org
  3. Download & install SharpKeys and use it to map left an alternative key (eg. Left Ctrl) to the Insert key. This is needed because Macs do not typically have an “Insert” key which is the prefix for many NVDA commands.
@robertknight
robertknight / fetch-annotation-pages.py
Last active February 6, 2023 11:17
Script to page through annotations in a Hypothesis group
import os
import requests
search_after = ""
page_size = 200
group = os.environ["HYPOTHESIS_GROUP"]
access_token = os.environ["HYPOTHESIS_ACCESS_TOKEN"]
max_to_fetch = 10_000 # Max annotations to fetch before we stop
@robertknight
robertknight / license-report.md
Last active January 17, 2023 22:37
License report for Hypothesis project dependencies