public ulong knn(
            DenseColumnMajorMatrixStorage <float> query,
            DenseColumnMajorMatrixStorage <float> indices,//int
            DenseColumnMajorMatrixStorage <float> dists2,
            Vector <float> maxRadii,
            int k,
            float epsilon,
            SearchOptionFlags optionFlags)
        {
            checkSizesKnn(query, indices, dists2, k, optionFlags, maxRadii);

            bool allowSelfMatch = optionFlags.HasFlag(SearchOptionFlags.AllowSelfMatch);
            //bool sortResults = optionFlags.HasFlag(SearchOptionFlags.SortResults);
            float maxError2 = ((1 + epsilon) * (1 + epsilon));

            Debug.Assert(nodes.Count > 0);
            ulong leafTouchedCount = 0;

            var off = new float[this.dimensions];

            // TODO: Parallel.for?
            for (int i = 0; i < query.ColumnCount; ++i)
            {
                var   heap       = new ListPriorityQueue <BucketEntry>(k);
                float maxRadius  = maxRadii[i];
                float maxRadius2 = maxRadius * maxRadius;
                leafTouchedCount += onePointKnn(query, indices, dists2, i, heap, off, maxError2, maxRadius2, allowSelfMatch);
            }

            return(leafTouchedCount);
        }
Beispiel #2
0
        private ulong onePointKnn(
            DenseColumnMajorMatrixStorage <float> query,
            int i,
            DenseColumnMajorMatrixStorage <int> indices,
            DenseColumnMajorMatrixStorage <float> dists2,
            Vector <float> maxRadii,
            int k,
            float epsilon,
            SearchOptionFlags optionFlags)
        {
            var results = new ListPriorityQueue <int>(maxSize: k);

            var queryMatrix = new MathNet.Numerics.LinearAlgebra.Single.DenseMatrix(query);
            var q           = queryMatrix.Column(i);

            for (int j = 0; j < cloud.ColumnCount; j++)
            {
                var c = cloud.Column(j);

                var   diff = (c - q);
                float l2   = diff * diff;

                results.Enqueue(j, l2);
            }

            int kIdx = 0;

            foreach (var j in results.Items)
            {
                indices.At(kIdx, i, j);
                kIdx++;
            }

            kIdx = 0;
            foreach (var d2 in results.Priorities)
            {
                dists2.At(kIdx, i, d2);
            }

            return(0);
        }