Neighbors find_neighbors_covertree_impl(RandomAccessIterator begin, RandomAccessIterator end, PairwiseCallback callback, IndexType k) { timed_context context("Covertree-based neighbors search"); typedef CoverTreePoint<RandomAccessIterator> TreePoint; v_array<TreePoint> points; for (RandomAccessIterator iter=begin; iter!=end; ++iter) push(points, TreePoint(iter, callback(*iter,*iter))); node<TreePoint> ct = batch_create(callback, points); v_array< v_array<TreePoint> > res; ++k; // because one of the neighbors will be the actual query point k_nearest_neighbor(callback,ct,ct,res,k); Neighbors neighbors; neighbors.resize(end-begin); assert(end-begin==res.index); for (int i=0; i<res.index; ++i) { LocalNeighbors local_neighbors; local_neighbors.reserve(k); for (IndexType j=1; j<=k; ++j) // j=0 is the query point { // The actual query point is found as a neighbor, just ignore it if (res[i][j].iter_-begin==res[i][0].iter_-begin) continue; local_neighbors.push_back(res[i][j].iter_-begin); } neighbors[res[i][0].iter_-begin] = local_neighbors; free(res[i].elements); }; free(res.elements); free_children(ct); free(points.elements); return neighbors; }
static void run_test(int fd, int num_fences, int expected_errno, unsigned flags) { struct drm_i915_gem_execbuffer2 execbuf[2]; struct drm_i915_gem_exec_object2 exec[2][2*MAX_FENCES+3]; struct drm_i915_gem_relocation_entry reloc[2*MAX_FENCES+2]; int i, n; int loop = 1000; if (flags & BUSY_LOAD) { bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); batch = intel_batchbuffer_alloc(bufmgr, devid); /* Takes forever otherwise. */ loop = 50; } if (flags & INTERRUPTIBLE) igt_fork_signal_helper(); memset(execbuf, 0, sizeof(execbuf)); memset(exec, 0, sizeof(exec)); memset(reloc, 0, sizeof(reloc)); for (n = 0; n < 2*num_fences; n++) { uint32_t handle = tiled_bo_create(fd); exec[1][2*num_fences - n-1].handle = exec[0][n].handle = handle; fill_reloc(&reloc[n], handle); } for (i = 0; i < 2; i++) { for (n = 0; n < num_fences; n++) exec[i][n].flags = EXEC_OBJECT_NEEDS_FENCE; exec[i][2*num_fences].handle = batch_create(fd); exec[i][2*num_fences].relocs_ptr = (uintptr_t)reloc; exec[i][2*num_fences].relocation_count = 2*num_fences; execbuf[i].buffers_ptr = (uintptr_t)exec[i]; execbuf[i].buffer_count = 2*num_fences+1; execbuf[i].batch_len = 2*sizeof(uint32_t); } do { if (flags & BUSY_LOAD) emit_dummy_load(); igt_assert_eq(__gem_execbuf(fd, &execbuf[0]), expected_errno); igt_assert_eq(__gem_execbuf(fd, &execbuf[1]), expected_errno); } while (--loop); if (flags & INTERRUPTIBLE) igt_stop_signal_helper(); /* Cleanup */ for (n = 0; n < 2*num_fences; n++) gem_close(fd, exec[0][n].handle); for (i = 0; i < 2; i++) gem_close(fd, exec[i][2*num_fences].handle); if (flags & BUSY_LOAD) { intel_batchbuffer_free(batch); drm_intel_bufmgr_destroy(bufmgr); } }