Skip to content

Instantly share code, notes, and snippets.

View xrq-phys's full-sized avatar
Even when working remote, don't forget to drink water!

RuQing Xu xrq-phys

Even when working remote, don't forget to drink water!
View GitHub Profile
xrq-phys / softplus.hh
Created April 27, 2022 09:31
Complex-valued Softplus in C++. Useful when summing two VERY LARGE numbers.
View softplus.hh
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at
#pragma once
#include <complex>
#include <algorithm>
// Real softplus.
xrq-phys / MLComputeGEMM.swift
Created December 25, 2020 18:14
Very simple example of an ML Compute matrix multiplication. Naming convention somehow violated.
View MLComputeGEMM.swift
import Foundation
import MLCompute
import PlaygroundSupport
let iPage = PlaygroundPage.current
iPage.needsIndefiniteExecution = true
* Apple says MLCMatMulLayer does a ``batch matrix multiplication''
* but didn't make clear its meaning.
xrq-phys /
Last active December 11, 2020 22:17
Compile NumPy on M1 Chip, with Code Attached.


Compile NumPy on Apple Silicon M1 Chip


  • Create virtual env at, say export VENV=$HOME/.local:
python3 -m venv $VENV
. $VENV/bin/activate
xrq-phys / batch_define.jl
Last active September 25, 2020 16:50
Example of batch defining Julia functions. Will be used in BLIS.jl
View batch_define.jl
module BatchDef
macro def_numed_fun(funname, num)
numed_funname = Symbol(string(funname, num))
@show numed_funname
return quote
$(esc(numed_funname))() = $num
xrq-phys / contract_fwd_prototype.jl
Last active July 25, 2020 15:08
Prototype for TBLIS contract for ForwardDiff.jl
View contract_fwd_prototype.jl
# here idx has 3 entries corresponding to e.g. "ik,jk->ij".
idx) where {T<:Dual} = contract!(T, sizeof(T)/sizeof(tovalue(T)), # tovalue unveils base type.
A, 0, B, 0, C, 0, idx)
contract!(Type::Dual{Tg, T, ND}, topst, # top-level stride
A::Array, sftA, # arrays here are all at their top-level (not dispatched)
B::Array, sftB,
xrq-phys /
Last active December 26, 2020 07:57
[DEPRECATED: Official Available] Installing Native Aarch64 VSCode on Windows on Arm Devices
xrq-phys /
Last active March 18, 2020 13:18
Trying to make a simple example of calling BLIS kernel (direct call to GEMM kernel). Maybe useful if we're to play with special matrices not available in BLAS.
#include <iostream>
#include <blis/blis.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main(const int argc, const char *argv[])
// these two doesn't conflict.
using namespace std;
using namespace boost::numeric::ublas;
xrq-phys / Tensordot.jl
Last active November 28, 2023 17:56
Julia Implementation of NumPy's Tensordot Functon, Compatible with Flux/Zygote's Automatic Differentiation
View Tensordot.jl
Tensordot.jl - Minimal Tensordot Implementation
Minimal tensordot for supporting Zygote's automatic differentiation.
This bunch of code is also compatible with FluxML's Tracker module.
module Tensordot
using Zygote: @adjoint
using LinearAlgebra
xrq-phys /
Last active April 10, 2023 19:35
Compile Wolfram Engine Backend for TeXmacs on Linux
xrq-phys /
Last active November 27, 2019 06:44
Using TeXmacs as Frontend of WolframScript (Mathematica/Wolfram Engine) on macOS