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
xrq-phys / softplus.hh
Created April 27, 2022 09:31
Complex-valued Softplus in C++. Useful when summing two VERY LARGE numbers.
/**
* 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 https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <complex>
#include <algorithm>
// Real softplus.
@xrq-phys
xrq-phys / MLComputeGEMM.swift
Created December 25, 2020 18:14
Very simple example of an ML Compute matrix multiplication. Naming convention somehow violated.
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
xrq-phys / A-Guide-to-Build-NumPy-on-Apple-Silicon.md
Last active December 11, 2020 22:17
Compile NumPy on M1 Chip, with Code Attached.

What

Compile NumPy on Apple Silicon M1 Chip

How

  • Create virtual env at, say export VENV=$HOME/.local:
python3 -m venv $VENV
. $VENV/bin/activate
@xrq-phys
xrq-phys / batch_define.jl
Last active September 25, 2020 16:50
Example of batch defining Julia functions. Will be used in BLIS.jl
module BatchDef
macro def_numed_fun(funname, num)
numed_funname = Symbol(string(funname, num))
@show numed_funname
return quote
$(esc(numed_funname))() = $num
end
end
@xrq-phys
xrq-phys / contract_fwd_prototype.jl
Last active July 25, 2020 15:08
Prototype for TBLIS contract for ForwardDiff.jl
# here idx has 3 entries corresponding to e.g. "ik,jk->ij".
contract!(A::Array{T},
B::Array{T},
C::Array{T},
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
xrq-phys / Code_OSS_Aarcha64.md
Last active December 26, 2020 07:57
[DEPRECATED: Official Available] Installing Native Aarch64 VSCode on Windows on Arm Devices
@xrq-phys
xrq-phys / example_bli_ker_call.cc
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
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
"""
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
xrq-phys / compile_MathLink_linux.sh
Last active April 10, 2023 19:35
Compile Wolfram Engine Backend for TeXmacs on Linux
@xrq-phys
xrq-phys / compile_MathLink_mac.sh
Last active November 27, 2019 06:44
Using TeXmacs as Frontend of WolframScript (Mathematica/Wolfram Engine) on macOS