This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%'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, ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
OlderNewer