/****************************************************************************
 *   This file is part of the aGrUM/pyAgrum library.                        *
 *                                                                          *
 *   Copyright (c) 2005-2026 by                                             *
 *       - Pierre-Henri WUILLEMIN(_at_LIP6)                                 *
 *       - Christophe GONZALES(_at_AMU)                                     *
 *                                                                          *
 *   The aGrUM/pyAgrum library is free software; you can redistribute it    *
 *   and/or modify it under the terms of either :                           *
 *                                                                          *
 *    - the GNU Lesser General Public License as published by               *
 *      the Free Software Foundation, either version 3 of the License,      *
 *      or (at your option) any later version,                              *
 *    - the MIT license (MIT),                                              *
 *    - or both in dual license, as here.                                   *
 *                                                                          *
 *   (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html)    *
 *                                                                          *
 *   This aGrUM/pyAgrum library is distributed in the hope that it will be  *
 *   useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,          *
 *   INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
 *   FOR A PARTICULAR PURPOSE  AND NONINFRINGEMENT. IN NO EVENT SHALL THE   *
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,        *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR  *
 *   OTHER DEALINGS IN THE SOFTWARE.                                        *
 *                                                                          *
 *   See LICENCES for more details.                                         *
 *                                                                          *
 *   SPDX-FileCopyrightText: Copyright 2005-2026                            *
 *       - Pierre-Henri WUILLEMIN(_at_LIP6)                                 *
 *       - Christophe GONZALES(_at_AMU)                                     *
 *   SPDX-License-Identifier: LGPL-3.0-or-later OR MIT                      *
 *                                                                          *
 *   Contact  : info_at_agrum_dot_org                                       *
 *   homepage : http://agrum.gitlab.io                                      *
 *   gitlab   : https://gitlab.com/agrumery/agrum                           *
 *                                                                          *
 ****************************************************************************/


/**
 * @file
 * @brief Efficient functionals for projecting multiDimensional tables
 *
 * @author Christophe GONZALES(_at_AMU) and Pierre-Henri WUILLEMIN(_at_LIP6)
 */

#ifndef GUM_PROJECTIONS_4_MULTI_DIM_H
#define GUM_PROJECTIONS_4_MULTI_DIM_H

#include <atomic>
#include <mutex>

#include <agrum/base/multidim/implementations/multiDimArray.h>
#include <agrum/base/multidim/implementations/multiDimFunctionGraph.h>

namespace gum {

  // ==========================================================================
  /// @name Project Max for MultiDim
  // ==========================================================================
  /// @{

  /**
   * @brief a specialized function for projecting a multiDimArray using a Max
   * operator
   * @ingroup multidim_op_group
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Max_{A,C} table (A,B,C,D).  @return function
   * ProjectMaxMultiDimArrays allocates on the heap the new T multiDimArray and
   * returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMax on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT >* projectMaxMultiDimArray(const MultiDimArray< GUM_ELEMENT >* table,
                                                        const gum::VariableSet& del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a Max
   * operator
   * @ingroup multidim_op_group
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Max_{A,C} table (A,B,C,D).  @return function
   * ProjectMaxMultiDimArrays allocates on the heap the new T multiDimArray and
   * returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMax on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectMaxMultiDimArray(const MultiDimImplementation< GUM_ELEMENT >* table,
                              const gum::VariableSet&                      del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a Max
   * operator
   * @ingroup multidim_op_group
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Max_{A,C} table (A,B,C,D).  @return function
   * ProjectMaxMultiDimArrays allocates on the heap the new T multiDimArray and
   * returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMax on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT* >*
      projectMaxMultiDimArray4Pointers(const MultiDimArray< GUM_ELEMENT* >* table,
                                       const gum::VariableSet&              del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a Max
   * operator
   * @ingroup multidim_op_group
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Max_{A,C} table (A,B,C,D).  @return function
   * ProjectMaxMultiDimArrays allocates on the heap the new T multiDimArray and
   * returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMax on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT* >*
      projectMaxMultiDimArray4Pointers(const MultiDimImplementation< GUM_ELEMENT* >* table,
                                       const gum::VariableSet&                       del_vars);

  // @}
  // ==========================================================================
  /// @name Project Min for MultiDim
  // ==========================================================================
  /// @{

  /**
   * @brief a specialized function for projecting a multiDimArray using a Min
   * operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Min_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMin on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT >* projectMinMultiDimArray(const MultiDimArray< GUM_ELEMENT >* table,
                                                        const gum::VariableSet& del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a Min
   * operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Min_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMin on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectMinMultiDimArray(const MultiDimImplementation< GUM_ELEMENT >* table,
                              const gum::VariableSet&                      del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a Min
   * operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Min_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMin on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT* >*
      projectMinMultiDimArray4Pointers(const MultiDimArray< GUM_ELEMENT* >* table,
                                       const gum::VariableSet&              del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a Min
   * operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Min_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMin on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT* >*
      projectMinMultiDimArray4Pointers(const MultiDimImplementation< GUM_ELEMENT* >* table,
                                       const gum::VariableSet&                       del_vars);

  // @}
  // ==========================================================================
  /// @name Project Sum for MultiDim
  // ==========================================================================
  /// @{

  /**
   * @brief a specialized function for projecting a multiDimArray using a
   * summation
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Sum_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectSum on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT >* projectSumMultiDimArray(const MultiDimArray< GUM_ELEMENT >* table,
                                                        const gum::VariableSet& del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a
   * summation
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Sum_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectSum on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectSumMultiDimArray(const MultiDimImplementation< GUM_ELEMENT >* table,
                              const gum::VariableSet&                      del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a
   * summation
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Sum_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectSum on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT* >*
      projectSumMultiDimArray4Pointers(const MultiDimArray< GUM_ELEMENT* >* table,
                                       const gum::VariableSet&              del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using a
   * summation
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Sum_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectSum on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT* >*
      projectSumMultiDimArray4Pointers(const MultiDimImplementation< GUM_ELEMENT* >* table,
                                       const gum::VariableSet&                       del_vars);

  // @}
  // ==========================================================================
  /// @name Project Product for MultiDim
  // ==========================================================================
  /// @{

  /**
   * @brief a specialized function for projecting a multiDimArray using
   * products
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Prod_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectProduct on MultiDimImplementation. This operator
   * will take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT >*
      projectProductMultiDimArray(const MultiDimArray< GUM_ELEMENT >* table,
                                  const gum::VariableSet&             del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using
   * products
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Prod_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectProduct on MultiDimImplementation. This operator
   * will take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectProductMultiDimArray(const MultiDimImplementation< GUM_ELEMENT >* table,
                                  const gum::VariableSet&                      del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using
   * products
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Prod_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectProduct on MultiDimImplementation. This operator
   * will take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT* >*
      projectProductMultiDimArray4Pointers(const MultiDimArray< GUM_ELEMENT* >* table,
                                           const gum::VariableSet&              del_vars);

  /**
   * @brief a specialized function for projecting a multiDimArray using
   * products
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a MultiDimArray
   * defined over A,B,C,D and if del_vars = {A,C}, then the function returns a
   * table over B,D defined as Prod_{A,C} table (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectProduct on MultiDimImplementation. This operator
   * will take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT* >*
      projectProductMultiDimArray4Pointers(const MultiDimImplementation< GUM_ELEMENT* >* table,
                                           const gum::VariableSet&                       del_vars);

  // @}
  // ==========================================================================
  /// @name Project Function for MultiDim
  // ==========================================================================
  /// @{

  /**
   * @brief a specialized function for functionally projecting a multiDimArray
   *
   * The function produces a tensorial functional combination of t1 and t2,
   * that is, if t1 and t2 are multiDimArrays over variables A,B,C,D and D,B,E
   * respectively, function combine2MultiDimArrays will return a multiDimArray
   * T defined as T[A,B,C,D,E] = f ( t1[A,B,C,D],t2[D,B,E] ) for all A,B,C,D,E.
   *
   * @return function combine2MultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it.
   */
  template < typename GUM_ELEMENT >
  MultiDimArray< GUM_ELEMENT >*
      ProjectFuncMultiDimArray(const MultiDimArray< GUM_ELEMENT >* t1,
                               const MultiDimArray< GUM_ELEMENT >* t2,
                               const GUM_ELEMENT (*f)(const GUM_ELEMENT&, const GUM_ELEMENT&));

  /**
   * @brief a specialized function for functionally projecting a multiDimArray
   *
   * The function produces a tensorial functional combination of t1 and t2,
   * that is, if t1 and t2 are multiDimArrays over variables A,B,C,D and D,B,E
   * respectively, function combine2MultiDimArrays will return a multiDimArray
   * T defined as T[A,B,C,D,E] = f ( t1[A,B,C,D],t2[D,B,E] ) for all A,B,C,D,E.
   *
   * @return function combine2MultiDimArrays allocates on the heap the new T
   * multiDimArray and returns it.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      combine2MultiDimArrays(const MultiDimImplementation< GUM_ELEMENT >* t1,
                             const MultiDimImplementation< GUM_ELEMENT >* t2,
                             const GUM_ELEMENT (*f)(const GUM_ELEMENT&, const GUM_ELEMENT&));

  // @}
  // ==========================================================================
  /// @name Projectors For Function Graphs
  // ==========================================================================
  /// @{

  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph using
   * a Max operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Max_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraph allocates on the heap the
   * new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMax on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimFunctionGraph< GUM_ELEMENT >*
      projectMaxMultiDimFunctionGraph(const MultiDimFunctionGraph< GUM_ELEMENT >* table,
                                      const gum::VariableSet&                     del_vars);

  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph using
   * a Max operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Max_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraph allocates on the heap the
   * new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMax on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectMaxMultiDimFunctionGraph(const MultiDimImplementation< GUM_ELEMENT >* table,
                                      const gum::VariableSet&                      del_vars);


  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph
   * using a Min operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Min_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraphs allocates on the heap
   * the new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMin on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimFunctionGraph< GUM_ELEMENT >*
      projectMinMultiDimFunctionGraph(const MultiDimFunctionGraph< GUM_ELEMENT >* table,
                                      const gum::VariableSet&                     del_vars);

  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph
   * using a Min operator
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Min_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraphs allocates on the heap
   * the new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectMin on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectMinMultiDimFunctionGraph(const MultiDimImplementation< GUM_ELEMENT >* table,
                                      const gum::VariableSet&                      del_vars);


  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph using
   * a summation
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Sum_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraphs allocates on the heap
   * the new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectSum on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimFunctionGraph< GUM_ELEMENT >*
      projectSumMultiDimFunctionGraph(const MultiDimFunctionGraph< GUM_ELEMENT >* table,
                                      const gum::VariableSet&                     del_vars);

  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph using
   * a summation
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Sum_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraphs allocates on the heap
   * the new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectSum on MultiDimImplementation. This operator will
   * take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectSumMultiDimFunctionGraph(const MultiDimImplementation< GUM_ELEMENT >* table,
                                      const gum::VariableSet&                      del_vars);


  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph using
   * products
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Prod_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraphs allocates on the heap
   * the new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectProduct on MultiDimImplementation. This operator
   * will take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimFunctionGraph< GUM_ELEMENT >*
      projectProductMultiDimFunctionGraph(const MultiDimFunctionGraph< GUM_ELEMENT >* table,
                                          const gum::VariableSet&                     del_vars);

  /**
   * @brief a specialized function for projecting a multiDimFunctionGraph using
   * products
   *
   * The function projects a table over the subset of its variables NOT IN the
   * set of variables del_vars. For instance, if table is a
   * MultiDimFunctionGraph defined over A,B,C,D and if del_vars = {A,C}, then
   * the function returns a table over B,D defined as Prod_{A,C} table
   * (A,B,C,D).
   *
   * @return function ProjectMaxMultiDimFunctionGraphs allocates on the heap
   * the new T multiDimFunctionGraph and returns it
   *
   * @warning In practice, do not use this function but rather
   * operator/function projectProduct on MultiDimImplementation. This operator
   * will take care to select this function if it is appropriate for your
   * projection.
   */
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectProductMultiDimFunctionGraph(const MultiDimImplementation< GUM_ELEMENT >* table,
                                          const gum::VariableSet&                      del_vars);

  /// @}

  /// The function to be used to project a MultiDimImplementation using a Max
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectMax(const MultiDimImplementation< GUM_ELEMENT >& table,
                 const gum::VariableSet&                      del_vars);

  /// The function to be used to project a MultiDimImplementation using a Min
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectMin(const MultiDimImplementation< GUM_ELEMENT >& table,
                 const gum::VariableSet&                      del_vars);

  /// The function to be used to project a MultiDimImplementation using a Sum
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectSum(const MultiDimImplementation< GUM_ELEMENT >& table,
                 const gum::VariableSet&                      del_vars);

  /// The function to be used to project a MultiDimImplementation using a
  /// Product
  template < typename GUM_ELEMENT >
  MultiDimImplementation< GUM_ELEMENT >*
      projectProduct(const MultiDimImplementation< GUM_ELEMENT >& table,
                     const gum::VariableSet&                      del_vars);


  // ==========================================================================
  // DO NOT FORGET TO REGISTER YOUR PROJECTION FUNCTIONS AT THE END OF FILE
  // projections4MultiDim_tpl.h
  // ==========================================================================

  /**
   * @brief the function used to register all the projection operators on
   * multidimImplementations over non-pointers types.
   */
  template < typename GUM_ELEMENT >
  void projections4MultiDimInit();

  /**
   * @brief the function used to register all the projections on
   * multidimImplementations over pointers types.
   */
  template < typename GUM_ELEMENT >
  void pointerProjections4MultiDimInit();

  /**
   * @brief a class used to register projections over non-pointers types
   *
   * This class is of course completely redundant with function
   * projections4MultiDimInit. Its aim is to enable specialization of function
   * projections4MultiDimInit for pointer types: C++ allows partial
   * specialization of templated classes (e.g., create different
   * implementations for C<T> and C<T*>) but it does not allows partial
   * specialization for functions. Hence, by creating a class the primary
   * purpose of which is to run function projections4MultiDimInit, we allow
   * this partial specialization. This is most effective to produce different
   * codes for pointer types and non-pointer types.
   */
  template < typename GUM_ELEMENT >
  struct Projections4MultiDimInitialize {
    void init();
  };

  /**
   * @brief a class used to register projections over pointers types
   *
   * This class is of course completely redundant with function
   * pointerProjections4MultiDimInit. Its aim is to enable different
   * implementations of the projections for multidims depending in whether
   * these multidim contain pointers or not. Actually, C++ allows partial
   * specialization of templated classes (e.g., create different
   * implementations for C<T> and C<T*>) but it does not allows partial
   * specialization for functions. Hence, by creating a class the primary
   * purpose of which is to run function projections4MultiDimInit or
   * pointerProjections4MultiDimInit, we allow this partial specialization to
   * obtain.
   */
  template < typename GUM_ELEMENT >
  struct Projections4MultiDimInitialize< GUM_ELEMENT* > {
    void init();
  };

} /* namespace gum */

// always include the templatized implementations
#include <agrum/base/multidim/utils/operators/projections4MultiDim_tpl.h>

#endif /* GUM_PROJECTIONS_4_MULTI_DIM_H */
