Skip to content

Instantly share code, notes, and snippets.

using Hecke
# code for solving the closest vector problem. We use Hecke's implementation of enumeration
# I stopped because Hecke's enumeration did not seem to find the closest vector. Another drawback is they only support coordinate vectors input/output
function closest_vec_enumeration(qs::QuadSpace{Hecke.Nemo.QQField, Hecke.Nemo.QQMatrix}, coords::Vector{Float64}, initial_dist_bnd::Float64)
# this is just a quick choice for the tolerance. May need to find a better value later
coords_tol = minimum([[abs(x) for x in coords]; 1/100.0])
coords_qq = QQ.(rationalize.(BigInt, coords, tol = coords_tol))
initial_dist_bnd_qq = QQ.(rationalize.(BigInt, initial_dist_bnd, tol = 0.000000001))
@davidamarquis
davidamarquis / bench.jl
Last active October 16, 2024 15:20
Julia Benchmarking
# construct a 100x100 random matrix to test multiply. Store result in a matrix.
# Observations: allocates, v*A allocates a different amount than A*v
@benchmark LinearAlgebra.mul!(B, v, A) setup = (A = rand(0x00:0x01, 100, 100); v = ones(UInt8, 1, 100); B = zeros(UInt8, 1, 100);)
# construct a 100x100 random matrix to test multiply. Store result in a vector.
# Observation: does not allocate
@benchmark LinearAlgebra.mul!(B, A, v) setup = (A = rand(0x00:0x01, 100, 100); v = ones(UInt8, 100); B = zeros(UInt8, 100);)
@davidamarquis
davidamarquis / function_timing.cpp
Created November 26, 2021 21:39
Shows how to time things with chrono and using NTL's system time
#include <NTL/tools.h>
#include <chrono>
using namespace std;
// First way: NTL has a clock for computing CPU time
double ntl_time = NTL::GetTime();
// Second way: chrono lets you compute wall-time
auto start = chrono::system_clock::now();
TIME_ME();
ntl_time = NTL::GetTime() - ntl_time;
auto end = chrono::system_clock::now();
@davidamarquis
davidamarquis / gist:4b7febcb36a5c98daec5a6dc118721b2
Created November 22, 2021 17:29 — forked from bortzmeyer/gist:1284249
The only simple way to do SSH in Python today is to use subprocess + OpenSSH...
#!/usr/bin/python
# All SSH libraries for Python are junk (2011-10-13).
# Too low-level (libssh2), too buggy (paramiko), too complicated
# (both), too poor in features (no use of the agent, for instance)
# Here is the right solution today:
import subprocess
import sys
@davidamarquis
davidamarquis / border.html
Last active November 6, 2021 15:07
Markdown border
Used for creating a small border around most markdown images
<kbd>
<img src="myimg.png">
</kbd>