Skip to content

Instantly share code, notes, and snippets.

View j2kun's full-sized avatar
💭
Math math math math math math math

Jeremy Kun j2kun

💭
Math math math math math math math
View GitHub Profile
public static <T> boolean verifyApproximateDp(
T[] samplesA, T[] samplesB, double epsilon, double delta, double deltaTolerance) {
Map<T, Long> histogramA = buildHistogram(samplesA);
Map<T, Long> histogramB = buildHistogram(samplesB);
double testValueA = computeAproximateDpTestValue(histogramA, histogramB, epsilon, samplesA.length);
double testValueB = computeAproximateDpTestValue(histogramB, histogramA, epsilon, samplesA.length);
return testValueA < delta + deltaTolerance && testValueB < delta + deltaTolerance;
}
private static <T> double computeAproximateDpTestValue(
@j2kun
j2kun / mappings.lua
Created August 18, 2022 22:07
Open BUILD file in vsplit
function open_build_in_vsplit()
local current_filepath = vim.fn.expand('%:p:h')
local current_filename = vim.fn.expand('%:t')
vim.api.nvim_command('vsp ' .. current_filepath .. "/BUILD")
vim.api.nvim_command('/' .. current_filename)
end
vim.keymap.set('n', '<leader>vb', ':lua open_build_in_vsplit()<CR>')
@j2kun
j2kun / fft.py
Created November 28, 2022 19:05
Naive negacyclic FFT
import numpy as np
def poly_mul(a, b):
a_preprocessed = np.concatenate([a, -a], dtype=np.complex64)
b_preprocessed = np.concatenate([b, -b], dtype=np.complex64)
a_ft = np.fft.fft(a_preprocessed)
b_ft = np.fft.fft(b_preprocessed)
prod = a_ft * b_ft
np_fft_mul = np.round(0.5 * np.real(np.fft.ifft(prod))).astype(np.int64)
@j2kun
j2kun / broken_tangent_fft.py
Last active November 29, 2022 17:01
Broken negacyclic polynomial multiplication based on nufhe docs https://github.com/nucypher/nufhe/blob/master/doc/source/implementation_details.rst
import numpy as np
import math
def primitive_nth_root(n):
"""Return a primitive nth root of unity."""
return math.cos(2 * math.pi / n) + 1.0j * math.sin(2 * math.pi / n)
def poly_mul(a, b):
@j2kun
j2kun / tangent_fft.py
Created November 28, 2022 19:28
Negacyclic polymul based on tangent fft
import numpy as np
import math
def primitive_nth_root(n):
"""Return a primitive nth root of unity."""
return math.cos(2 * math.pi / n) + 1.0j * math.sin(2 * math.pi / n)
def poly_mul(a, b):
@j2kun
j2kun / model.v
Last active July 13, 2023 17:20
Slow write_verilog repro
This file has been truncated, but you can view the full file.
module for_17083425188857115422(
input wire signed [7:0] arg1,
input wire signed [7:0] arg2,
input wire signed [31:0] arg3,
output wire signed [31:0] _out_
);
wire signed [15:0] v4;
wire signed [15:0] v5;
wire signed [15:0] v6;
wire signed [31:0] v7;
@j2kun
j2kun / WORKSPACE
Last active July 18, 2023 16:54
Minimal WORKSPACE repro
workspace(name = "xls_repro")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Install XLS and its transitive dependencies.
http_archive(
name = "com_google_xls",
sha256 = "c0653f9e3979e311ef9c8660d13f60d1217d9830fdb22011d22954a429f898e5",
strip_prefix = "xls-dce44c5c896773c85c2b8078f9d38d7b8b39912e",
url = "https://github.com/google/xls/archive/dce44c5c896773c85c2b8078f9d38d7b8b39912e.tar.gz",
@j2kun
j2kun / Passes.h.inc
Created August 7, 2023 18:01
The code generated by mlir-tblgen for AffineFullUnroll
/* Autogenerated by mlir-tblgen; don't manually edit */
#ifdef GEN_PASS_DECL
// Generate declarations for all passes.
#define GEN_PASS_DECL_AFFINEFULLUNROLL
#define GEN_PASS_DECL_AFFINEFULLUNROLLPATTERNREWRITE
#undef GEN_PASS_DECL
#endif // GEN_PASS_DECL
//===----------------------------------------------------------------------===//
This file has been truncated, but you can view the full file.
cmake_minimum_required(VERSION 2.8.8)
project(b'bug')
add_library(_2 OBJECT
/home/j2kun/fhe/bug/external/llvm-project/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
/usr/include/c++/11/system_error
/home/j2kun/fhe/bug/bazel-out/k8-fastbuild/bin/external/llvm-project/mlir/_virtual_includes/OpenACCOpsIncGen/mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc
/home/j2kun/fhe/bug/external/llvm-project/mlir/include/mlir/Conversion/ArithToLLVM/ArithToLLVM.h
/home/j2kun/fhe/bug/bazel-out/k8-fastbuild/bin/external/llvm-project/mlir/_virtual_includes/IRDLTypesIncGen/mlir/Dialect/IRDL/IR/IRDLTypesGen.h.inc
/home/j2kun/fhe/bug/external/llvm-project/llvm/include/llvm/ADT/MapVector.h
@j2kun
j2kun / PolyTypes.cpp.inc
Created August 18, 2023 22:57
PolyTypes generated files after adding a type parameter
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* TypeDef Definitions *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
#ifdef GET_TYPEDEF_LIST
#undef GET_TYPEDEF_LIST