Skip to content

Instantly share code, notes, and snippets.

View Gnimuc's full-sized avatar
🍤

Yupei Qi Gnimuc

🍤
  • Tokyo
  • 07:43 (UTC +09:00)
  • X @Gnimuc
View GitHub Profile
@Gnimuc
Gnimuc / test.jl
Created October 4, 2015 09:26
[SO] Assign the object reference not the object
type Chain
value :: Int
right :: Chain
left :: Chain
#Make the last link in the chain point to itself
#so as to spare us from the julia workaround for nulls
Chain(value::Int) = (chain = new(); chain.value = value; chain.right = chain; chain.left = chain; chain)
end
# load dependency packages
using GLFW, ModernGL
# set up OpenGL context version
@osx_only const VERSION_MAJOR = 4 # it seems OSX will stuck on OpenGL 4.1.
@osx_only const VERSION_MINOR = 1
# initialize GLFW library, error check is already wrapped.
GLFW.Init()
@Gnimuc
Gnimuc / test.jl
Created November 17, 2015 04:23
[SO] Multiple selection from Julia array
function foo(genconv, I, J)
genconv[sub2ind(size(genconv),I,J)]
end
function bar(genconv, I, J)
diag(sub(genconv, I, J))
end
function baz(genconv, I, J)
[genconv[i,j] for (i,j) in zip(I, J)]
end
@Gnimuc
Gnimuc / test.jl
Created January 13, 2016 14:16
[SO]Julia vs MATLAB: Why is my Julia code so slow?
using Dierckx
function foo()
x = [0., 1., 2., 3., 4.]
y = [-1., 0., 7., 26., 63.]
spl = Spline1D(x, y)
a = evaluate(spl, ones(10000))
reshape(a,100,100)
end
function bar()
@Gnimuc
Gnimuc / toy_topology_preservation.jl
Created June 3, 2016 08:59
[NRIRHOPM] Topology Preservation Dilemma
function topology(s1::Tuple{Int64,Int64}, s2::Tuple{Int64,Int64}, s3::Tuple{Int64,Int64}, a::Tuple{Int64,Int64}, b::Tuple{Int64,Int64}, c::Tuple{Int64,Int64})
ks1 = (s1[1]+a[1], s1[2]+a[2])
ks2 = (s2[1]+b[1], s2[2]+b[2])
ks3 = (s3[1]+c[1], s3[2]+c[2])
dφ1 = ks2[1] - ks1[1]
dr1 = s2[1] - s1[1]
dφ2 = ks2[2] - ks3[2]
dr2 = s2[2] - s3[2]
dφ3 = ks2[2] - ks1[2]
# dr3 = dr1

Yum

shell> cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core) 

julia> versioninfo()
Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
  System: Linux (x86_64-pc-linux-gnu)
@Gnimuc
Gnimuc / cxx-cygwin.md
Last active February 18, 2017 09:14
Cxx-win
_       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0-dev.2842 (2017-02-17 17:00 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit ded2d87* (0 days old master)
|__/                   |  x86_64-w64-mingw32

julia> Pkg.build("Cxx")
@Gnimuc
Gnimuc / toy-conv.jl
Last active September 27, 2017 11:40
# this is actually cross-correlation
function toyconv(x::AbstractArray{T,3}, w::AbstractArray{T,4}, pad::Integer, _stride::Integer) where T<:Real
xSpatialDims = size(x, 1, 2)
kernelSpatialDims = size(w, 1, 2)
channelNum, kernelNum = size(w, 3, 4)
ySpatialDims = 1 .+ (xSpatialDims .+ 2pad .- kernelSpatialDims) .÷ _stride
δ = kernelSpatialDims[1] ÷ 2
padSpatialDims = xSpatialDims .+ 2pad
xOffset = OffsetArray(x, pad, pad, 0)
xPadded = PaddedView(zero(T), xOffset, (padSpatialDims..., channelNum))
@Gnimuc
Gnimuc / Hungarian.jl.mem
Last active February 12, 2018 03:38
memory allocation
- module Hungarian
-
-
- # Zero markers used in hungarian algorithm
- # 0 => NON => Non-zero
- # 1 => Z => ordinary zero
- # 2 => STAR => starred zero
- # 3 => PRIME => primed zero
- const NON = Int8(0)
- const Z = Int8(1)
@Gnimuc
Gnimuc / Munkres.jl,mem
Created February 12, 2018 10:05
Updated
- """
- munkres(costMat) -> Zs
-
- Find an optimal solution of the assignment problem represented by the square
- matrix `costMat`. Return an sparse matrix illustrating the optimal matching.
-
- # Examples
-
- ```julia
- julia> costMat = ones(3, 3) - eye(3, 3)