Skip to content

Instantly share code, notes, and snippets.

View chappjc's full-sized avatar
🏁

Jonathan Chappelow chappjc

🏁
View GitHub Profile
@chappjc
chappjc / solution_referee_timeit.m
Last active August 29, 2015 14:08
Benchmarking for CST-Link's challenge
% solution_referee_timeit.m
clear all
N = 100e3; % 60000;
%// Input (Keep N as big as possible)
list_of_words = repmat({'02_04_04_52_23_14_54_672_0'},N,1);
f1 = @() eval_and_loops_solution(list_of_words);
time_eval = timeit(f1);
clear f1
@chappjc
chappjc / test_all_numscan.m
Last active August 29, 2015 14:08
Benchmarking v2 for CST-Link's challenge
%'test_all_numscan.m'
clc;
feature accel on; %'tune for speed'
%'low memory stress'
referee_timing( ...
referee_test_case(10^4), ...
@eval_and_loops_solution, ...
@single_sscanf_solution, ...
@approach1, ...
@chappjc
chappjc / solution_mex_chappjc_vc12.cpp
Created October 25, 2014 08:04
MEX solution based on Amro's, but using character to byte processing
#include "mex.h"
#include <string>
#include <sstream>
#include <algorithm>
namespace {
// get i-th string from cell-array of strings
std::string getString(const mxArray *cellstr, const mwIndex idx)
{
@chappjc
chappjc / solution_mex_chappjc_vc12.cpp
Created October 29, 2014 17:14
MEX solution based on Amro's, but manually doing an "atoi", also with OpenMP
// solution_mex_chappjc_vc12.cpp
// mex -v -largeArrayDims COMPFLAGS="$COMPFLAGS /openmp" ...
// LINKFLAGS="$LINKFLAGS /openmp" solution_mex_chappjc_vc12.cpp ...
// -output solution_mex_chappjc_vc12_omp.mexw64
#include "mex.h"
#include <string>
#include <sstream>
#include <algorithm>
function out = rld_cumsum(vals,runlens)
% gnovice's solution to run-length-decoding
% (http://stackoverflow.com/a/1975835/2778484)
index = zeros(1,sum(runlens));
index([1 cumsum(runlens(1:end-1))+1]) = 1;
out = vals(cumsum(index));
return
function out = rld_cumsum_diff(vals,runlens)
% Divakar's solution to run-length-decoding
% (http://stackoverflow.com/a/29079288/2778484)
clens = cumsum(runlens);
idx(clens(end))=0;
idx([1 clens(1:end-1)+1]) = diff([0 vals]);
out = cumsum(idx);
return
% benchmark code for RLD solutions posted at http://stackoverflow.com/q/1975772/2778484
% Results posted in CW: http://stackoverflow.com/a/29084077/2778484
%% bench
datasizes = [reshape(linspace(10,70,4).'*10.^(0:4),1,[]) 10^6 2*10^6]; %//'
fcns = {'repelem','rld_cumsum','rld_cumsum_diff'}; %// approaches to be benchmarked
tsec = zeros(numel(fcns),numel(datasizes));
for k1 = 1:numel(datasizes),
n = datasizes(k1); %// Create random inputs
function V = knedlsepp5cumsumaccumarray(values, runLengths)
% knedlsepp's solution to run-length-decoding originally from http://stackoverflow.com/a/28615814/2778484
% (results in http://stackoverflow.com/a/29079288/2778484)
%// Actual computation using column vectors
V = cumsum(accumarray(cumsum([1; runLengths(:)]), 1));
V = V(1:end-1);
V = reshape(values(V),[],1);
end
function d = naive_jit_test(vals,runlens)
% basic loop approach to run length decoding
% (http://stackoverflow.com/a/29084077/2778484)
d(sum(runlens))=0;
jj=1;
for ii=1:numel(vals),
d(jj:jj+runlens(ii)-1) = vals(ii);
jj = jj + runlens(ii);
end
@chappjc
chappjc / pylon_mex_camera_interface.cpp
Last active November 18, 2021 20:24
Add comments/documentation. Append checkHandle() and getHandle() definitions.
// pylon_mex_camera_interface.cpp
// Code for StackOverflow Q&A: http://stackoverflow.com/a/32529850/2778484
// by Jon Chappelow (chappjc)
// For example MATLAB-side implementation (class wrapper), see https://github.com/chappjc/MATLAB/tree/master/cppClass
// Use:
// 1. Enumerate the different actions (e.g. New, Delete, Insert, etc.) in the
// Actions enum. For each enumerated action, specify a string (e.g.
// "new", "delete", "insert", etc.) to be passed as the first argument to
// the MEX function in MATLAB.