<commit_before>/*
 *  Copyright 2008-2014 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.
 */

/*! \file multilevel.h
 *  \brief Multilevel hierarchy
 *
 */

#pragma once

#include <cusp/detail/config.h>
#include <cusp/detail/lu.h>
#include <cusp/detail/type_traits.h>

#include <cusp/array1d.h>
#include <cusp/linear_operator.h>

#include <cusp/precond/smoother/jacobi_smoother.h>

#include <thrust/detail/use_default.h>

namespace cusp
{
namespace detail
{
  template <typename FormatType, typename MemorySpace>
  struct select_format_type
  {
    typedef typename thrust::detail::eval_if<
        thrust::detail::is_same<MemorySpace, cusp::host_memory>::value
      , thrust::detail::identity_<cusp::csr_format>
      , thrust::detail::identity_<cusp::hyb_format>
      >::type DefaultFormat;

    typedef typename thrust::detail::eval_if<
          thrust::detail::is_same<FormatType, thrust::use_default>::value
        , thrust::detail::identity_<DefaultFormat>
        , thrust::detail::identity_<FormatType>
      >::type type;
  };

  template <typename SmootherType, typename ValueType, typename MemorySpace>
  struct select_smoother_type
  {
    typedef cusp::precond::aggregation::jacobi_smoother<ValueType,MemorySpace> JacobiSmoother;

    typedef typename thrust::detail::eval_if<
          thrust::detail::is_same<SmootherType, thrust::use_default>::value
        , thrust::detail::identity_<JacobiSmoother>
        , thrust::detail::identity_<SmootherType>
      >::type type;
  };

  template <typename SolverType, typename ValueType, typename MemorySpace>
  struct select_solver_type
  {
    typedef cusp::detail::lu_solver<ValueType,cusp::host_memory> LUSolver;

    typedef typename thrust::detail::eval_if<
          thrust::detail::is_same<SolverType, thrust::use_default>::value
        , thrust::detail::identity_<LUSolver>
        , thrust::detail::identity_<SolverType>
      >::type type;
  };
} // end detail namespace

/*! \addtogroup iterative_solvers Iterative Solvers
 *  \addtogroup preconditioners Preconditioners
 *  \ingroup iterative_solvers
 *  \{
 */

/*! \p multilevel : multilevel hierarchy
 *
 *
 *  TODO
 */
template <typename IndexType,
          typename ValueType,
          typename MemorySpace,
          typename FormatType   = thrust::use_default,
          typename SmootherType = thrust::use_default,
          typename SolverType   = thrust::use_default>
class multilevel
: public cusp::linear_operator<ValueType,MemorySpace>
{
private:

    typedef typename detail::select_format_type<FormatType,MemorySpace>::type                   Format;
    typedef typename detail::matrix_type<IndexType,ValueType,MemorySpace,Format>::type          MatrixType;
    typedef typename detail::select_smoother_type<SmootherType,ValueType,MemorySpace>::type     Smoother;
    typedef typename detail::select_solver_type<SolverType,ValueType,MemorySpace>::type         Solver;

public:

    /* \cond */
    struct level
    {
        MatrixType R;  // restriction operator
        MatrixType A;  // matrix
        MatrixType P;  // prolongation operator<commit_msg>Updated multilevel types for access by inherited classes<commit_after>/*
 *  Copyright 2008-2014 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.
 */

/*! \file multilevel.h
 *  \brief Multilevel hierarchy
 *
 */

#pragma once

#include <cusp/detail/config.h>
#include <cusp/detail/lu.h>
#include <cusp/detail/type_traits.h>

#include <cusp/array1d.h>
#include <cusp/linear_operator.h>

#include <cusp/precond/smoother/jacobi_smoother.h>

#include <thrust/detail/use_default.h>

namespace cusp
{
namespace detail
{
  template <typename FormatType, typename MemorySpace>
  struct select_format_type
  {
    typedef typename thrust::detail::eval_if<
        thrust::detail::is_same<MemorySpace, cusp::host_memory>::value
      , thrust::detail::identity_<cusp::csr_format>
      , thrust::detail::identity_<cusp::hyb_format>
      >::type DefaultFormat;

    typedef typename thrust::detail::eval_if<
          thrust::detail::is_same<FormatType, thrust::use_default>::value
        , thrust::detail::identity_<DefaultFormat>
        , thrust::detail::identity_<FormatType>
      >::type type;
  };

  template <typename SmootherType, typename ValueType, typename MemorySpace>
  struct select_smoother_type
  {
    typedef cusp::precond::aggregation::jacobi_smoother<ValueType,MemorySpace> JacobiSmoother;

    typedef typename thrust::detail::eval_if<
          thrust::detail::is_same<SmootherType, thrust::use_default>::value
        , thrust::detail::identity_<JacobiSmoother>
        , thrust::detail::identity_<SmootherType>
      >::type type;
  };

  template <typename SolverType, typename ValueType, typename MemorySpace>
  struct select_solver_type
  {
    typedef cusp::detail::lu_solver<ValueType,cusp::host_memory> LUSolver;

    typedef typename thrust::detail::eval_if<
          thrust::detail::is_same<SolverType, thrust::use_default>::value
        , thrust::detail::identity_<LUSolver>
        , thrust::detail::identity_<SolverType>
      >::type type;
  };
} // end detail namespace

/*! \addtogroup iterative_solvers Iterative Solvers
 *  \addtogroup preconditioners Preconditioners
 *  \ingroup iterative_solvers
 *  \{
 */

/*! \p multilevel : multilevel hierarchy
 *
 *
 *  TODO
 */
template <typename IndexType,
          typename ValueType,
          typename MemorySpace,
          typename FormatType   = thrust::use_default,
          typename SmootherType = thrust::use_default,
          typename SolverType   = thrust::use_default>
class multilevel
: public cusp::linear_operator<ValueType,MemorySpace>
{
protected:

    typedef typename detail::select_format_type<FormatType,MemorySpace>::type                   Format;
    typedef typename detail::matrix_type<IndexType,ValueType,MemorySpace,Format>::type          MatrixType;
    typedef typename detail::select_smoother_type<SmootherType,ValueType,MemorySpace>::type     Smoother;
    typedef typename detail::select_solver_type<SolverType,ValueType,MemorySpace>::type         Solver;

public:

    /* \cond */
    struct level
    {
        MatrixType R;  // restriction operator
        MatrixType A;  // matrix
        MatrixType P;  // prolongation operator
{'fraction_non_alphanumeric': 0.10405571487095452, 'fraction_numerical': 0.0035504574627884746, 'mean_word_length': 3.915436241610738, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2231656', 'n_tokens_mistral': 2232, 'n_tokens_neox': 2120, 'n_words': 494}