/*
 * Copyright (c) 2020-2022, NVIDIA CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * This file is deprecated and will be removed in release 22.06.
 * Please use the cuh version instead.
 */

#ifndef __SPARSE_KNN_H
#define __SPARSE_KNN_H

#pragma once

#include <raft/distance/distance_type.hpp>
#include <raft/handle.hpp>
#include <raft/sparse/selection/detail/knn.cuh>

namespace raft {
namespace sparse {
namespace selection {

/**
 * Search the sparse kNN for the k-nearest neighbors of a set of sparse query vectors
 * using some distance implementation
 * @param[in] idxIndptr csr indptr of the index matrix (size n_idx_rows + 1)
 * @param[in] idxIndices csr column indices array of the index matrix (size n_idx_nnz)
 * @param[in] idxData csr data array of the index matrix (size idxNNZ)
 * @param[in] idxNNZ number of non-zeros for sparse index matrix
 * @param[in] n_idx_rows number of data samples in index matrix
 * @param[in] n_idx_cols
 * @param[in] queryIndptr csr indptr of the query matrix (size n_query_rows + 1)
 * @param[in] queryIndices csr indices array of the query matrix (size queryNNZ)
 * @param[in] queryData csr data array of the query matrix (size queryNNZ)
 * @param[in] queryNNZ number of non-zeros for sparse query matrix
 * @param[in] n_query_rows number of data samples in query matrix
 * @param[in] n_query_cols number of features in query matrix
 * @param[out] output_indices dense matrix for output indices (size n_query_rows * k)
 * @param[out] output_dists dense matrix for output distances (size n_query_rows * k)
 * @param[in] k the number of neighbors to query
 * @param[in] handle CUDA handle.get_stream() to order operations with respect to
 * @param[in] batch_size_index maximum number of rows to use from index matrix per batch
 * @param[in] batch_size_query maximum number of rows to use from query matrix per batch
 * @param[in] metric distance metric/measure to use
 * @param[in] metricArg potential argument for metric (currently unused)
 */
template <typename value_idx = int, typename value_t = float, int TPB_X = 32>
void brute_force_knn(const value_idx* idxIndptr,
                     const value_idx* idxIndices,
                     const value_t* idxData,
                     size_t idxNNZ,
                     int n_idx_rows,
                     int n_idx_cols,
                     const value_idx* queryIndptr,
                     const value_idx* queryIndices,
                     const value_t* queryData,
                     size_t queryNNZ,
                     int n_query_rows,
                     int n_query_cols,
                     value_idx* output_indices,
                     value_t* output_dists,
                     int k,
                     const raft::handle_t& handle,
                     size_t batch_size_index             = 2 << 14,  // approx 1M
                     size_t batch_size_query             = 2 << 14,
                     raft::distance::DistanceType metric = raft::distance::DistanceType::L2Expanded,
                     float metricArg                     = 0)
{
  detail::sparse_knn_t<value_idx, value_t>(idxIndptr,
                                           idxIndices,
                                           idxData,
                                           idxNNZ,
                                           n_idx_rows,
                                           n_idx_cols,
                                           queryIndptr,
                                           queryIndices,
                                           queryData,
                                           queryNNZ,
                                           n_query_rows,
                                           n_query_cols,
                                           output_indices,
                                           output_dists,
                                           k,
                                           handle,
                                           batch_size_index,
                                           batch_size_query,
                                           metric,
                                           metricArg)
    .run();
}

};  // namespace selection
};  // namespace sparse
};  // namespace raft

#endif