Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
NdSamplerFromGrid.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef _FUNCTIONUTILS_NDSAMPLERFROMGRID_H
20#define _FUNCTIONUTILS_NDSAMPLERFROMGRID_H
21
23#include "NdArray/NdArray.h"
24#include "NdArray/Operations.h"
25
26namespace Euclid {
27namespace MathUtils {
28
29template <typename Seq>
30struct ExtractKnots {};
31
32template <std::size_t... Is>
34 template <typename... Axes>
36 return std::tuple<std::vector<Axes>...>{{std::get<Is>(axes).begin(), std::get<Is>(axes).end()}...};
37 }
38
39 template <typename... Axes>
41 return std::vector<std::size_t>{std::get<sizeof...(Is) - Is - 1>(axes).size()...};
42 }
43};
44
55template <typename... Axes>
56std::unique_ptr<NdSampler<Axes...>>
63
82template <typename CellAxis, typename... GridAxes>
83std::unique_ptr<NdSampler<CellAxis, GridAxes...>>
86 auto grid_knots = ExtractKnots<Euclid::_make_index_sequence<sizeof...(GridAxes)>>::extract(grid.getAxesTuple());
87 auto pdf_shape = ExtractKnots<Euclid::_make_index_sequence<sizeof...(GridAxes)>>::extractShape(grid.getAxesTuple());
88
89 // Add one extra
90 pdf_shape.push_back(cell_axis.size());
92
93 // Build PDF considering the cell the last axis
96 for (auto& cell : grid) {
98 for (auto& cv : cell) {
100 pdf.at(coords) = cv;
101 }
102 }
103
105}
106
115template <typename... GridAxes>
123
124} // namespace MathUtils
125} // namespace Euclid
126
127#endif // _FUNCTIONUTILS_NDSAMPLERFROMGRID_H
T at(T... args)
T begin(T... args)
Provides information related with an axis of a GridContainer.
Definition GridAxis.h:49
Representation of a multi-dimensional grid which contains axis information.
T end(T... args)
T iota(T... args)
T make_tuple(T... args)
T move(T... args)
std::unique_ptr< NdSampler< Axes... > > createSamplerFromGrid(const GridContainer::GridContainer< std::vector< double >, Axes... > &grid)
std::array< std::vector< double >, N > Coordinates
Used to pass the grid coordinates to interpn. Internally will make a copy of the required values.
std::vector< std::size_t > unravel_index(std::size_t index, const std::vector< std::size_t > &shape)
std::unique_ptr< T > make_unique(Args &&... args)
Constructs an object of type T and wraps it in a std::unique_ptr using args as the parameter list for...
typename _index_sequence_helper< N >::type _make_index_sequence
T size(T... args)
static std::tuple< std::vector< Axes >... > extract(const std::tuple< GridContainer::GridAxis< Axes >... > &axes)
static std::vector< std::size_t > extractShape(const std::tuple< GridContainer::GridAxis< Axes >... > &axes)
T tuple_cat(T... args)