ITE / code / shared / embedded / ann_wrapperM / @ann / frsearch.m

function [idx dst inr] = frsearch(ann, query, r, k, epsl, asm)
% kNN FR search
%   Usage:
%     [idx dst inr] = frsearch(ann, query, rad, k, eps, asm)
% Inputs:
%   ann - ann class object
%   query - (d)x(N) query points
%   k - number of nearest nieghbors (if points in ann < k than less than k
%                                    points are returned)
%   epsl - epsilon search precision 
%   asm - allow self match flag, if false points with dst = 0 are ignored 
%         (defualt is true)
if nargin == 5
    asm = true;

if ~asm
    k = k+1;

if ~isa(query, ann.ccls)
    query = ann.cfun(query);

[idx dst inr] = annmex(ann.modes.FRSEARCH, ann.kd_ptr, query, k, epsl, r);
% for points that has less than k ANN within the proper rad
% idx equals -1 and dst is a very large const for the entries larger than
% inr

% remove self matches
if ~asm
    gsm = dst(1,:)==0;
    dst(1:end-1,gsm) = dst(2:end,gsm);
    idx(1:end-1,gsm) = idx(2:end,gsm);
    dst(end,:) = [];
    idx(end,:) = [];
    inr(gsm) = inr(gsm)-1;

not_found = idx == -1;
idx(not_found) = -2; % cannot assign NaN to int32 variable
dst(not_found) = inf;

idx = idx + 1; % fix zero indexing of ann
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.