Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
utility.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/system/start/utility.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/system/start/utility.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/system/start/utility.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
28
29#ifndef BERTINI_START_SYSTEM_UTILITIES_HPP
30#define BERTINI_START_SYSTEM_UTILITIES_HPP
31
32
33
34namespace bertini{
35
36
54 template <typename T>
55 std::vector<T> IndexToSubscript(T index, std::vector<T> const& dimensions)
56 {
57
58 std::vector< T > subscripts(dimensions.size());//for forming a subscript from an index
59
60 std::vector<T> k(dimensions.size(),1);
61 for (size_t ii = 0; ii+1 < dimensions.size(); ++ii)
62 k[ii+1] = k[ii]*dimensions[ii];
63
64
65 if (index >= k.back()*dimensions.back())
66 throw std::out_of_range("in IndexToSubscript, index exceeds max based on dimension sizes");
67
68
69 for (int ii = static_cast<int>(dimensions.size())-1; ii >= 0; --ii)
70 {
71 T I = index%k[static_cast<size_t>(ii)];
72 T J = (index - I) / k[static_cast<size_t>(ii)];
73 subscripts[static_cast<size_t>(ii)] = J;
74 index = I;
75 }
76
77 return subscripts;
78 }
79
80
81
82} // re: namespace bertini
83
84
85
86
87#endif
Definition algorithm_builder.hpp:36
std::vector< T > IndexToSubscript(T index, std::vector< T > const &dimensions)
Convert a zero-based index to a zero-based subscript vector.
Definition utility.hpp:55