ts=linspace(0,20,500000);
tic;
for i=1:1000
f=min(find(ts>10));
end;
toc
function [data,x,lower,upper]= find_halfspace_rec(data,x,lower,upper);
mp=floor((lower+upper)/2);
if mp~=lower
if data(mp)<x
[data,x,lower,upper]= find_halfspace_rec(data,x,mp,upper);
else
[data,x,lower,upper]= find_halfspace_rec(data,x,lower,mp);
end;
end;
function l = find_halfspace(data,x);
% returns the number of the last sample in the ASCENDING array data that is
% &lt; x using a simple half space search
upper = numel(data); lower = 1;
[data,x,l,u] = find_halfspace_rec(data,x,lower,upper);
ts=linspace(0,20,500000);
tic;
Fast lookup in sorted array | Jakob Voigts http://jvoigts.scripts.mit.edu/blog/fast-sorted-array-lookup/
第 1 頁,共 3 頁 2015/3/9 下午 06:18
for i=1:1000
f=find_halfspace(ts,10);
end;
toc
#include "mex.h"
/*
* find_halfspace_mex.c
* same as find_halfspace.m
*/
int binary_search(double a[], int low, int high, double target[]) {
int result=-1;
while (low = a[middle])
low = middle + 1;
else
return middle;
result=middle;
}
return result+1;
}
void find_halfspace_mex(double y[], double x[],double f[],int low, int high)
{
y[0]=binary_search(x, low, high, f);
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *x,*y, *f;
size_t mrows,ncols,maxsize;
/* Check for proper number of arguments. */
if(nrhs!=2) {
mexErrMsgIdAndTxt( "MATLAB:find_halfspace_mex:invalidNumInputs", "two inputs required."
} else if(nlhs&gt;1) {
mexErrMsgIdAndTxt( "MATLAB:timestwo:maxlhs", "Too many output arguments.");
}
/* The input must be a noncomplex scalar double.*/
mrows = mxGetM(prhs[0]);
ncols = mxGetN(prhs[0]);
if (mrows&gt;ncols)
maxsize = mrows;
else
maxsize = ncols;
/* Create matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
/* Assign pointers to each input and output. */
x = mxGetPr(prhs[0]);
f = mxGetPr(prhs[1]);
y = mxGetPr(plhs[0]);
if ((mrows==0)||(ncols==0))
y[0]=-1;
else
find_halfspace_mex(y,x,f,0,maxsize);
Fast lookup in sorted array | Jakob Voigts http://jvoigts.scripts.mit.edu/blog/fast-sorted-array-lookup/
第 2 頁,共 3 頁 2015/3/9 下午 06:18
}
ts=linspace(0,20,500000);
tic;
for i=1:1000
f=find_halfspace_mex(ts,10);
end;
toc
Fast lookup in sorted array | Jakob Voigts http://jvoigts.scripts.mit.edu/blog/fast-sorted-array-lookup/
第 3 頁,共 3 頁 2015/3/9 下午 06:18

More Related Content

PDF
PDF
Py lecture5 python plots
PDF
Mi primer map reduce
PDF
Mi primer map reduce
PDF
Python grass
PPT
Doublylinklist
PPTX
Statistics - ArgMax Equation
Py lecture5 python plots
Mi primer map reduce
Mi primer map reduce
Python grass
Doublylinklist
Statistics - ArgMax Equation

What's hot (18)

PDF
On fuctional programming, high order functions, ML
PDF
benjielloyd1234
PDF
6. binary tree
DOCX
CLUSTERGRAM
PDF
04 stacks
PDF
Java Week10 Notepad
PDF
Lambda Calculus
PPTX
Linked list part-3
PDF
The simplest existential graph system
PDF
Functional programming in Swift
PDF
Recursion concepts by Divya
PDF
Intoduction to numpy
PDF
Aggregators: Data Day Texas, 2015
PPTX
Lecture 6: linked list
PPTX
Exercise roots of equations
PDF
R basic programs
PDF
Stack concepts by Divya
PPTX
Introduction to the lambda calculus
On fuctional programming, high order functions, ML
benjielloyd1234
6. binary tree
CLUSTERGRAM
04 stacks
Java Week10 Notepad
Lambda Calculus
Linked list part-3
The simplest existential graph system
Functional programming in Swift
Recursion concepts by Divya
Intoduction to numpy
Aggregators: Data Day Texas, 2015
Lecture 6: linked list
Exercise roots of equations
R basic programs
Stack concepts by Divya
Introduction to the lambda calculus
Ad

Similar to Fast lookup in sorted array jakob voigts (11)

PDF
Question 1,2,4 ------------------------------------Please check.pdf
PPTX
Data structure and application experential learning project
PPTX
Demonstrate interpolation search
PDF
Orthogonal Range Searching
DOCX
UNIT V.docx
PPT
arrays1.ppt python programme arrays insertion
PPTX
Searching techniques with progrms
PDF
UNIT IV -Data Structures.pdf
PPTX
Searching in Data Structure
DOCX
lab 2 in microprocessior and coontrolew.docx
PPT
Advanced Search Techniques
Question 1,2,4 ------------------------------------Please check.pdf
Data structure and application experential learning project
Demonstrate interpolation search
Orthogonal Range Searching
UNIT V.docx
arrays1.ppt python programme arrays insertion
Searching techniques with progrms
UNIT IV -Data Structures.pdf
Searching in Data Structure
lab 2 in microprocessior and coontrolew.docx
Advanced Search Techniques
Ad

Recently uploaded (20)

PPT
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
PPT
statistics analysis - topic 3 - describing data visually
PDF
OneRead_20250728_1808.pdfhdhddhshahwhwwjjaaja
PPTX
DS-40-Pre-Engagement and Kickoff deck - v8.0.pptx
PPTX
statsppt this is statistics ppt for giving knowledge about this topic
PDF
Best Data Science Professional Certificates in the USA | IABAC
PPTX
Crypto_Trading_Beginners.pptxxxxxxxxxxxxxx
PPTX
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
PPTX
Machine Learning and working of machine Learning
PPTX
eGramSWARAJ-PPT Training Module for beginners
PPTX
SET 1 Compulsory MNH machine learning intro
PDF
Systems Analysis and Design, 12th Edition by Scott Tilley Test Bank.pdf
PPTX
Tapan_20220802057_Researchinternship_final_stage.pptx
PPT
statistic analysis for study - data collection
PDF
Jean-Georges Perrin - Spark in Action, Second Edition (2020, Manning Publicat...
PPT
Image processing and pattern recognition 2.ppt
PPTX
Business_Capability_Map_Collection__pptx
PPT
expt-design-lecture-12 hghhgfggjhjd (1).ppt
PPTX
FMIS 108 and AISlaudon_mis17_ppt_ch11.pptx
PPTX
Topic 5 Presentation 5 Lesson 5 Corporate Fin
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
statistics analysis - topic 3 - describing data visually
OneRead_20250728_1808.pdfhdhddhshahwhwwjjaaja
DS-40-Pre-Engagement and Kickoff deck - v8.0.pptx
statsppt this is statistics ppt for giving knowledge about this topic
Best Data Science Professional Certificates in the USA | IABAC
Crypto_Trading_Beginners.pptxxxxxxxxxxxxxx
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
Machine Learning and working of machine Learning
eGramSWARAJ-PPT Training Module for beginners
SET 1 Compulsory MNH machine learning intro
Systems Analysis and Design, 12th Edition by Scott Tilley Test Bank.pdf
Tapan_20220802057_Researchinternship_final_stage.pptx
statistic analysis for study - data collection
Jean-Georges Perrin - Spark in Action, Second Edition (2020, Manning Publicat...
Image processing and pattern recognition 2.ppt
Business_Capability_Map_Collection__pptx
expt-design-lecture-12 hghhgfggjhjd (1).ppt
FMIS 108 and AISlaudon_mis17_ppt_ch11.pptx
Topic 5 Presentation 5 Lesson 5 Corporate Fin

Fast lookup in sorted array jakob voigts

  • 1. ts=linspace(0,20,500000); tic; for i=1:1000 f=min(find(ts>10)); end; toc function [data,x,lower,upper]= find_halfspace_rec(data,x,lower,upper); mp=floor((lower+upper)/2); if mp~=lower if data(mp)<x [data,x,lower,upper]= find_halfspace_rec(data,x,mp,upper); else [data,x,lower,upper]= find_halfspace_rec(data,x,lower,mp); end; end; function l = find_halfspace(data,x); % returns the number of the last sample in the ASCENDING array data that is % &lt; x using a simple half space search upper = numel(data); lower = 1; [data,x,l,u] = find_halfspace_rec(data,x,lower,upper); ts=linspace(0,20,500000); tic; Fast lookup in sorted array | Jakob Voigts http://jvoigts.scripts.mit.edu/blog/fast-sorted-array-lookup/ 第 1 頁,共 3 頁 2015/3/9 下午 06:18
  • 2. for i=1:1000 f=find_halfspace(ts,10); end; toc #include "mex.h" /* * find_halfspace_mex.c * same as find_halfspace.m */ int binary_search(double a[], int low, int high, double target[]) { int result=-1; while (low = a[middle]) low = middle + 1; else return middle; result=middle; } return result+1; } void find_halfspace_mex(double y[], double x[],double f[],int low, int high) { y[0]=binary_search(x, low, high, f); } void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *x,*y, *f; size_t mrows,ncols,maxsize; /* Check for proper number of arguments. */ if(nrhs!=2) { mexErrMsgIdAndTxt( "MATLAB:find_halfspace_mex:invalidNumInputs", "two inputs required." } else if(nlhs&gt;1) { mexErrMsgIdAndTxt( "MATLAB:timestwo:maxlhs", "Too many output arguments."); } /* The input must be a noncomplex scalar double.*/ mrows = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]); if (mrows&gt;ncols) maxsize = mrows; else maxsize = ncols; /* Create matrix for the return argument. */ plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); /* Assign pointers to each input and output. */ x = mxGetPr(prhs[0]); f = mxGetPr(prhs[1]); y = mxGetPr(plhs[0]); if ((mrows==0)||(ncols==0)) y[0]=-1; else find_halfspace_mex(y,x,f,0,maxsize); Fast lookup in sorted array | Jakob Voigts http://jvoigts.scripts.mit.edu/blog/fast-sorted-array-lookup/ 第 2 頁,共 3 頁 2015/3/9 下午 06:18
  • 3. } ts=linspace(0,20,500000); tic; for i=1:1000 f=find_halfspace_mex(ts,10); end; toc Fast lookup in sorted array | Jakob Voigts http://jvoigts.scripts.mit.edu/blog/fast-sorted-array-lookup/ 第 3 頁,共 3 頁 2015/3/9 下午 06:18