On Mon, 29 May 2017, Riccardo (Jack) Lucchetti wrote:
Ok, two more things on this: (1) it turn out that if you combine the
matrix-based algorithm with a divide-and-conquer strategy you do get some
improvement. (2) The timings of the loop-based versions depend heavily on how
many different values are contaned in the column to be serched: this is the
scalar called H in the script below. Have fun.
A little refinement on the divide-and-conquer algorithm: (1) use the
golden ration to split the vector (2) fix a bug ;)
<hansl>
function scalar find_3(const matrix a, scalar column, scalar target)
n = rows(a)
h = floor(n * 0.381966)
c = find_0(a[1:h,column], 1, target)
if ok(c)
return c
else
c = find_3(a[h+1:,1], 1, target)
endif
return c
end function
</hansl>
This version, on my laptop, is faster than the loop-based functions with
N=500000 and H=10000; with H=1000, the loop-based versions are much
faster.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------