Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing broken doc functions and improving coverage #1030

Merged
merged 6 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions cpp/include/raft/core/device_mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ template <typename ElementType,
typename AccessorPolicy = std::experimental::default_accessor<ElementType>>
using managed_mdspan = mdspan<ElementType, Extents, LayoutPolicy, managed_accessor<AccessorPolicy>>;

namespace detail {
template <typename T, bool B>
struct is_device_mdspan : std::false_type {
};
Expand Down Expand Up @@ -83,22 +82,20 @@ using is_input_managed_mdspan_t = is_managed_mdspan<T, is_input_mdspan_v<T>>;
template <typename T>
using is_output_managed_mdspan_t = is_managed_mdspan<T, is_output_mdspan_v<T>>;

} // end namespace detail

/**
* @\brief Boolean to determine if variadic template types Tn are either raft::device_mdspan or a
* derived type
*/
template <typename... Tn>
inline constexpr bool is_device_mdspan_v = std::conjunction_v<detail::is_device_mdspan_t<Tn>...>;
inline constexpr bool is_device_mdspan_v = std::conjunction_v<is_device_mdspan_t<Tn>...>;

template <typename... Tn>
inline constexpr bool is_input_device_mdspan_v =
std::conjunction_v<detail::is_input_device_mdspan_t<Tn>...>;
std::conjunction_v<is_input_device_mdspan_t<Tn>...>;

template <typename... Tn>
inline constexpr bool is_output_device_mdspan_v =
std::conjunction_v<detail::is_output_device_mdspan_t<Tn>...>;
std::conjunction_v<is_output_device_mdspan_t<Tn>...>;

template <typename... Tn>
using enable_if_device_mdspan = std::enable_if_t<is_device_mdspan_v<Tn...>>;
Expand All @@ -114,15 +111,15 @@ using enable_if_output_device_mdspan = std::enable_if_t<is_output_device_mdspan_
* derived type
*/
template <typename... Tn>
inline constexpr bool is_managed_mdspan_v = std::conjunction_v<detail::is_managed_mdspan_t<Tn>...>;
inline constexpr bool is_managed_mdspan_v = std::conjunction_v<is_managed_mdspan_t<Tn>...>;

template <typename... Tn>
inline constexpr bool is_input_managed_mdspan_v =
std::conjunction_v<detail::is_input_managed_mdspan_t<Tn>...>;
std::conjunction_v<is_input_managed_mdspan_t<Tn>...>;

template <typename... Tn>
inline constexpr bool is_output_managed_mdspan_v =
std::conjunction_v<detail::is_output_managed_mdspan_t<Tn>...>;
std::conjunction_v<is_output_managed_mdspan_t<Tn>...>;

template <typename... Tn>
using enable_if_managed_mdspan = std::enable_if_t<is_managed_mdspan_v<Tn...>>;
Expand Down Expand Up @@ -292,18 +289,6 @@ auto make_device_vector_view(
return device_vector_view<ElementType, IndexType, LayoutPolicy>{ptr, mapping};
}

/**
* @brief Create a layout_stride mapping from extents and strides
* @param[in] extents the dimensionality of the layout
* @param[in] strides the strides between elements in the layout
* @return raft::layout_stride::mapping<Extents>
*/
template <typename Extents, typename Strides>
auto make_strided_layout(Extents extents, Strides strides)
{
return layout_stride::mapping<Extents>{extents, strides};
}

/**
* @brief Construct a strided vector layout mapping
*
Expand Down
12 changes: 3 additions & 9 deletions cpp/include/raft/core/host_mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ template <typename ElementType,
typename AccessorPolicy = std::experimental::default_accessor<ElementType>>
using host_mdspan = mdspan<ElementType, Extents, LayoutPolicy, host_accessor<AccessorPolicy>>;

namespace detail {

template <typename T, bool B>
struct is_host_mdspan : std::false_type {
};
Expand All @@ -57,22 +55,18 @@ using is_input_host_mdspan_t = is_host_mdspan<T, is_input_mdspan_v<T>>;
template <typename T>
using is_output_host_mdspan_t = is_host_mdspan<T, is_output_mdspan_v<T>>;

} // namespace detail

/**
* @\brief Boolean to determine if variadic template types Tn are either raft::host_mdspan or a
* derived type
*/
template <typename... Tn>
inline constexpr bool is_host_mdspan_v = std::conjunction_v<detail::is_host_mdspan_t<Tn>...>;
inline constexpr bool is_host_mdspan_v = std::conjunction_v<is_host_mdspan_t<Tn>...>;

template <typename... Tn>
inline constexpr bool is_input_host_mdspan_v =
std::conjunction_v<detail::is_input_host_mdspan_t<Tn>...>;
inline constexpr bool is_input_host_mdspan_v = std::conjunction_v<is_input_host_mdspan_t<Tn>...>;

template <typename... Tn>
inline constexpr bool is_output_host_mdspan_v =
std::conjunction_v<detail::is_output_host_mdspan_t<Tn>...>;
inline constexpr bool is_output_host_mdspan_v = std::conjunction_v<is_output_host_mdspan_t<Tn>...>;

template <typename... Tn>
using enable_if_host_mdspan = std::enable_if_t<is_input_mdspan_v<Tn...>>;
Expand Down
12 changes: 12 additions & 0 deletions cpp/include/raft/core/mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ auto make_mdspan(ElementType* ptr, extents<IndexType, Extents...> exts)
return mdspan<ElementType, decltype(exts), LayoutPolicy, accessor_type>{ptr, exts};
}

/**
* @brief Create a layout_stride mapping from extents and strides
* @param[in] extents the dimensionality of the layout
* @param[in] strides the strides between elements in the layout
* @return raft::layout_stride::mapping<Extents>
*/
template <typename Extents, typename Strides>
auto make_strided_layout(Extents extents, Strides strides)
cjnolet marked this conversation as resolved.
Show resolved Hide resolved
{
return layout_stride::mapping<Extents>{extents, strides};
}

/**
* @brief Create raft::extents to specify dimensionality
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#pragma once
#include "curand_wrappers.hpp"
#include "random_types.hpp"
#include <cmath>
#include <memory>
#include <optional>
Expand All @@ -26,6 +25,7 @@
#include <raft/linalg/detail/cusolver_wrappers.hpp>
#include <raft/linalg/matrix_vector_op.cuh>
#include <raft/linalg/unary_op.cuh>
#include <raft/random/random_types.hpp>
#include <raft/util/cuda_utils.cuh>
#include <raft/util/cudart_utils.hpp>
#include <rmm/device_uvector.hpp>
Expand Down
23 changes: 0 additions & 23 deletions cpp/include/raft/random/detail/random_types.hpp

This file was deleted.

19 changes: 1 addition & 18 deletions cpp/include/raft/random/multi_variable_gaussian.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include "detail/multi_variable_gaussian.cuh"
#include <raft/random/random_types.hpp>

namespace raft::random {

Expand Down Expand Up @@ -59,24 +60,6 @@ class multi_variable_gaussian : public detail::multi_variable_gaussian_impl<T> {
~multi_variable_gaussian() { deinit(); }
}; // end of multi_variable_gaussian

/**
* @brief Matrix decomposition method for `compute_multi_variable_gaussian` to use.
*
* `compute_multi_variable_gaussian` can use any of the following methods.
*
* - `CHOLESKY`: Uses Cholesky decomposition on the normal equations.
* This may be faster than the other two methods, but less accurate.
*
* - `JACOBI`: Uses the singular value decomposition (SVD) computed with
* cuSOLVER's gesvdj algorithm, which is based on the Jacobi method
* (sweeps of plane rotations). This exposes more parallelism
* for small and medium size matrices than the QR option below.
*
* - `QR`: Uses the SVD computed with cuSOLVER's gesvd algorithm,
* which is based on the QR algorithm.
*/
using detail::multi_variable_gaussian_decomposition_method;

template <typename ValueType>
void compute_multi_variable_gaussian(
const raft::handle_t& handle,
Expand Down
39 changes: 39 additions & 0 deletions cpp/include/raft/random/random_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2018-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.
*/

#pragma once

namespace raft::random {

/**
* @brief Matrix decomposition method for `compute_multi_variable_gaussian` to use.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this docstring supposed to appear in the API docs? I do not see it there.

*
* `compute_multi_variable_gaussian` can use any of the following methods.
*
* - `CHOLESKY`: Uses Cholesky decomposition on the normal equations.
* This may be faster than the other two methods, but less accurate.
*
* - `JACOBI`: Uses the singular value decomposition (SVD) computed with
* cuSOLVER's gesvdj algorithm, which is based on the Jacobi method
* (sweeps of plane rotations). This exposes more parallelism
* for small and medium size matrices than the QR option below.
*
* - `QR`: Uses the SVD computed with cuSOLVER's gesvd algorithm,
* which is based on the QR algorithm.
*/
enum class multi_variable_gaussian_decomposition_method { CHOLESKY, JACOBI, QR };

}; // end of namespace raft::random
5 changes: 5 additions & 0 deletions cpp/include/raft/random/rng.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ template <typename T>
using weight_t = typename weight_alias<T>::type;
} // namespace sample_without_replacement_impl

//@{
benfred marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Sample the input vector without replacement, optionally based on the
* input weight vector for each element in the array.
Expand Down Expand Up @@ -824,6 +826,7 @@ void sample_without_replacement(const raft::handle_t& handle,
* compiler find the above overload, in case users pass in
* `std::nullopt` for one or both of the optional arguments.
*
*
* Please see above for documentation of `sample_without_replacement`.
*/
template <typename... Args, typename = std::enable_if_t<sizeof...(Args) == 5>>
Expand All @@ -832,6 +835,8 @@ void sample_without_replacement(Args... args)
sample_without_replacement(std::forward<Args>(args)..., std::nullopt);
}

//@}

/**
* @brief Legacy version of @c sample_without_replacement (see above)
* that takes raw arrays instead of device mdspan.
Expand Down
6 changes: 3 additions & 3 deletions cpp/test/random/multi_variable_gaussian.cu
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ class MVGMdspanTest : public ::testing::TestWithParam<MVGInputs<T>> {
static auto old_enum_to_new_enum(typename multi_variable_gaussian<T>::Decomposer method)
{
if (method == multi_variable_gaussian<T>::chol_decomp) {
return detail::multi_variable_gaussian_decomposition_method::CHOLESKY;
return multi_variable_gaussian_decomposition_method::CHOLESKY;
} else if (method == multi_variable_gaussian<T>::jacobi) {
return detail::multi_variable_gaussian_decomposition_method::JACOBI;
return multi_variable_gaussian_decomposition_method::JACOBI;
} else {
return detail::multi_variable_gaussian_decomposition_method::QR;
return multi_variable_gaussian_decomposition_method::QR;
}
}

Expand Down
2 changes: 0 additions & 2 deletions docs/source/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
C++ API Reference
~~~~~~~~~~~~~~~~~



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall the section heads below be in alphabetical order?

.. _api:

.. toctree::
Expand Down
4 changes: 4 additions & 0 deletions docs/source/cpp_api/cluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Cluster
This page provides C++ class references for the publicly-exposed elements of the `raft/cluster` headers. RAFT provides
fundamental clustering algorithms which are, themselves, considered reusable building blocks for other algorithms.

.. role:: py(code)
:language: c++
:class: highlight

K-Means
-------

Expand Down
5 changes: 5 additions & 0 deletions docs/source/cpp_api/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ require minimal dependencies, can be compiled without `nvcc`, and thus are safe
the headers in the `raft/core` include directory, any headers in the codebase with the suffix `_types.hpp` are also safe to
expose in public APIs.

.. role:: py(code)
:language: c++
:class: highlight


handle_t
########

Expand Down
5 changes: 5 additions & 0 deletions docs/source/cpp_api/distance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Distance
This page provides C++ class references for the publicly-exposed elements of the `raft/distance` package. RAFT's
distances have been highly optimized and support a wide assortment of different distance measures.

.. role:: py(code)
:language: c++
:class: highlight


Distance
########

Expand Down
5 changes: 5 additions & 0 deletions docs/source/cpp_api/linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ In addition to providing highly optimized arithmetic and matrix/vector operation
by providing common BLAS routines, standard linear system solvers, factorization and eigenvalue solvers. Some of these routines
hide the complexities of lower-level C-based libraries provided in the CUDA toolkit

.. role:: py(code)
:language: c++
:class: highlight


.. doxygennamespace:: raft::linalg
:project: RAFT
:members:
5 changes: 5 additions & 0 deletions docs/source/cpp_api/matrix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Matrix
This page provides C++ class references for the publicly-exposed elements of the `raft/matrix` headers. The `raft/matrix`
headers cover many operations on matrices that are otherwise not covered by `raft/linalg`.

.. role:: py(code)
:language: c++
:class: highlight


.. doxygennamespace:: raft::matrix
:project: RAFT
:members:
Loading