Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
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) 2015 - 2021 by 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
22// individual authors of this file include:
23// silviana amethyst, university of wisconsin - eau claire
24
31
32#ifndef BERTINI_START_SYSTEM_UTILITIES_HPP
33#define BERTINI_START_SYSTEM_UTILITIES_HPP
34
35
36
37namespace bertini{
38
39
57 template <typename T>
58 std::vector<T> IndexToSubscript(T index, std::vector<T> const& dimensions)
59 {
60
61 std::vector< T > subscripts(dimensions.size());//for forming a subscript from an index
62
63 std::vector<T> k(dimensions.size(),1);
64 for (int ii = 0; ii < dimensions.size()-1; ++ii)
65 k[ii+1] = k[ii]*dimensions[ii];
66
67
68 if (index >= k.back()*dimensions.back())
69 throw std::out_of_range("in IndexToSubscript, index exceeds max based on dimension sizes");
70
71
72 for (int ii = dimensions.size()-1; ii >= 0; --ii)
73 {
74 T I = index%k[ii];
75 T J = (index - I) / k[ii];
76 subscripts[ii] = J;
77 index = I;
78 }
79
80 return subscripts;
81 }
82
83
84
85} // re: namespace bertini
86
87
88
89
90#endif
91
92
93
94
std::shared_ptr< Node > I()
Definition special_number.cpp:42
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:58