Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Path: gap4r8 / pkg / NormalizInterface-1.0.2 / Normaliz.git / Qsource / libQnormaliz / Qvector_operations.h
Views: 418384/*1* Normaliz2* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger3* This program is free software: you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation, either version 3 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program. If not, see <http://www.gnu.org/licenses/>.15*16* As an exception, when this program is distributed through (i) the App Store17* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play18* by Google Inc., then that store may impose any digital rights management,19* device limits and/or redistribution restrictions that are required by its20* terms of service.21*/22//---------------------------------------------------------------------------23#ifndef VECTOR_OPERATIONS_H24#define VECTOR_OPERATIONS_H25//---------------------------------------------------------------------------2627#include <vector>28#include <ostream>29#include <list>3031#include <libQnormaliz/libQnormaliz.h>32#include <libQnormaliz/Qinteger.h>33#include <libQnormaliz/Qconvert.h>3435namespace libQnormaliz {36using std::vector;3738//---------------------------------------------------------------------------39// Data access40//---------------------------------------------------------------------------4142template <typename T>43std::ostream& operator<< (std::ostream& out, const vector<T>& vec) {44for (size_t i=0; i<vec.size(); ++i) {45out << vec[i] << " ";46}47out << std::endl;48return out;49}5051//---------------------------------------------------------------------------52// Vector operations53//---------------------------------------------------------------------------54template<typename Number>55Number v_scalar_product(const vector<Number>& a,const vector<Number>& b);5657//returns the scalar product of the vector a with the end of the vector b58template<typename Number>59Number v_scalar_product_unequal_vectors_end(const vector<Number>& a,const vector<Number>& b);6061//returns the addition a + b, vectors must be of equal size62template<typename Number>63vector<Number> v_add(const vector<Number>& a,const vector<Number>& b);64template<typename Number>65vector<Number> v_add_overflow_check(const vector<Number>& a,const vector<Number>& b);66template<typename Number>67void v_add_result(vector<Number>& result, const size_t length, const vector<Number>& a,const vector<Number>& b);68697071//---------------------------------------------------------------------------72// Scalar operations73//---------------------------------------------------------------------------7475//v = v * scalar76template<typename Number>77void v_scalar_multiplication(vector<Number>& v, const Number scalar){78size_t i,size=v.size();79for (i = 0; i <size; i++) {80v[i] *= scalar;81}82}8384//---------------------------------------------------------------------------8586template<typename Number>87void v_scalar_division(vector<Number>& v, const Number scalar){88size_t i,size=v.size();89for (i = 0; i <size; i++) {90v[i] /= scalar;91}92}9394//---------------------------------------------------------------------------95// General vector operations96//---------------------------------------------------------------------------9798//returns a new vector with the content of a extended by b99template<typename T>100vector<T> v_merge(const vector<T>& a, const T& b);101102//returns a new vector with the content of a and b103template<typename T>104vector<T> v_merge(const vector<T>& a, const vector<T>& b);105106//returns a new vector with the last size entries of v107template<typename T>108vector<T> v_cut_front(const vector<T>& v, size_t size);109110//the input vectors must be ordered of equal size111//if u is different from v by just one element, it returns that element112//else returns 0 (the elements of u and v are >0)113//int v_difference_ordered_fast(const vector<size_t>& u,const vector<size_t>& v);114115116template<typename Number>117bool compare_last (const vector<Number>& a, const vector<Number>& b)118{119return a.back() < b.back();120}121122//returns a key vector containing the positions of non-zero entrys of v123template<typename Number>124vector<key_t> v_non_zero_pos(const vector<Number>& v);125126// counts the number of positive entries127template<typename Number>128size_t v_nr_positive(const vector<Number>& v);129130// check whether the vector only contains 0131template<typename Number>132bool v_is_zero(const vector<Number>& v);133134template<typename Number>135bool v_is_symmetric(const vector<Number>& v);136137template<typename Number>138bool v_is_nonnegative(const vector<Number>& v);139140template<typename Number>141Number v_max_abs(const vector<Number>& v){142Number tmp = 0;143for (size_t i=0; i<v.size(); i++){144if (Iabs(v[i])>tmp) tmp=Iabs(v[i]);145}146return tmp;147}148149//---------------------------------------------------------------------------150// bool vector operations151//---------------------------------------------------------------------------152153vector<bool> v_bool_andnot(const vector<bool>& a, const vector<bool>& b);154155// swaps entry i and j of the vector<bool> v156void v_bool_entry_swap(vector<bool>& v, size_t i, size_t j);157158//---------------------------------------------------------------------------159// Special160//---------------------------------------------------------------------------161162// computes integral simplex containing a rational vector163template<typename Number>164void approx_simplex(const vector<Number>& q, std::list<vector<Number> >& approx,const long k);165166vector<key_t> identity_key(size_t n);167168//---------------------------------------------------------------------------169// Sorting170//---------------------------------------------------------------------------171172template <typename T>173void order_by_perm(vector<T>& v, const vector<key_t>& permfix);174175} // namespace176177//---------------------------------------------------------------------------178#endif179//---------------------------------------------------------------------------180181182