Skip to content

Instantly share code, notes, and snippets.

View matbesancon's full-sized avatar

Mathieu Besançon matbesancon

View GitHub Profile
@matbesancon
matbesancon / build.jl
Last active October 10, 2023 14:50
Running BinaryBuilder SCIP in debug mode
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using Pkg
Pkg.add("BinaryBuilder")
using BinaryBuilder
name = "SCIP"
version = v"800.0.400"
# Collection of sources required to complete build
@matbesancon
matbesancon / SDP.mof.json
Created June 30, 2021 09:58
SDP example
{
"name": "MathOptFormat Model",
"version": {
"major": 0,
"minor": 5
},
"variables": [
{
"name": "A_1[1,1]"
},
"""
Takes the model loaded from the MPS file and the line of the `.aux` file.
"""
function build_from_mibp(m::JuMP.Model, aux_file::Vector{String}; complete=false)
l1 = split(aux_file[1])
@assert length(l1) == 2
nl = parse(Int, l1[2])
nu = num_variables(m) - nl
l2 = split(aux_file[2])
@assert length(l2) == 2
@matbesancon
matbesancon / anim_projection.jl
Created December 24, 2020 14:45
Javis projection
using Javis
nframes = 200
function ground(args...)
background("white") # canvas background
sethue("black") # pen color
end
function object(p=O, color="black", radius=12)
@matbesancon
matbesancon / script.jl
Last active July 15, 2020 19:25
Dependencies on LightGraphs.jl
# This script assumes the Julia session is running at the root of the General repository
# https://github.com/JuliaRegistries/General
# Need these 3 installed
using LightGraphs, MetaGraphs, GraphPlot
import Pkg
function find_direct_deps(pkg_paths, source)
direct_deps = filter(pkg_paths) do pkg_path
deps_file = joinpath(pkg_path.path, "Deps.toml")
@matbesancon
matbesancon / .gitconfig
Last active January 28, 2020 14:43
Linux setup
[user]
name = Mathieu Besançon
[core]
autocrlf = true
[pager]
branch = false
@matbesancon
matbesancon / matrices.jl
Created October 2, 2019 13:18
Grow matrix versus pre-alloc
function expand_matrix(ms)
T = eltype(eltype(ms))
m2 = Matrix{T}(undef, 0, length(first(ms)))
for i in eachindex(ms)
m2 = [m2; ms[i]']
end
return m2
end
function prealloc_matrix(ms)
@matbesancon
matbesancon / setindex.jl
Last active August 20, 2019 09:12
setindex boundchecked
julia> function setindex(x::Tuple, v, i::Integer)
Base.@_inline_meta
@boundscheck 1 <= i <= length(x) || throw(BoundsError(x, i))
Base._setindex(v, i, x...)
end
julia> using BenchmarkTools
julia> const t1 = (42, "", π)
(42, "", π = 3.1415926535897...)
@matbesancon
matbesancon / sort_by_degree.jl
Created July 10, 2019 08:26
Sort vertices by reversed degree order
function sort_by_degree(g::LightGraphs.AbstractGraph)
vs = vertices(g)
degrees = (degree(g, v) for v in vs)
vertex_pairs = collect(zip(vs, degrees))
sort!(vertex_pairs, by = p -> p[2], rev = true)
end
julia> sort_by_degree(path_graph(5))
5-element Array{Tuple{Int64,Int64},1}:
(2, 2)
@matbesancon
matbesancon / bench.jl
Last active June 20, 2019 07:59
Sampling mini-benchmark
# julia v1.1.1
import Random
using Distributions # v0.21.0
import RandomNumbers # v1.3.0
using BenchmarkTools # v0.4.2
function f(µ::T, rng::Random.AbstractRNG) where {T<:Real}
n = 0
Σx = zero(T)
X = Normal(µ, one(T))