File: singularTermOrderData.h

package info (click to toggle)
polymake 4.15-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,892 kB
  • sloc: cpp: 168,945; perl: 43,410; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (248 lines) | stat: -rw-r--r-- 7,162 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/* Copyright (c) 1997-2024
   Ewgenij Gawrilow, Michael Joswig, and the polymake team
   Technische Universität Berlin, Germany
   https://polymake.org

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
--------------------------------------------------------------------------------
*/

#pragma once

#include "polymake/client.h"
#include "polymake/Polynomial.h"

#include "polymake/ideal/internal/singularInclude.h"
#include "polymake/ideal/internal/singularUtils.h"

namespace polymake { 
namespace ideal {
namespace singular {

// since singular commit 90f715a0b0 the type of the term order is rRingOrder_t* instead of int*
// in various functions (e.g. rDefault) and as member for ip_sring
// since there is no version number to determine this we use the type of the member here
typedef typename std::remove_pointer<decltype(ip_sring::order)>::type singular_order_type;

singular_order_type StringToSingularTermOrder(std::string ringOrderName);

template <typename OrderType>
class SingularTermOrderData_base {

protected:
   const OrderType orderData;
   const int n_vars;

public:
   // Constructor:
   SingularTermOrderData_base(const int n_vars_, const OrderType& order)
     : orderData(order)
     , n_vars(n_vars_)
   {
      if (n_vars == 0) 
         throw std::runtime_error("Given ring is not a polynomial ring.");
   }

   // Comparison:
   bool operator== (const SingularTermOrderData_base<OrderType>& other)
   {
      return orderData == other.orderData;
   }

   // Getters:
   // Not depending on template
   int get_ord_size() const;
   int* get_block0() const;
   int* get_block1() const;
   // Depending on template
   int** get_wvhdl() const;
   singular_order_type* get_ord() const;

  const OrderType& get_orderData() const { return orderData; }
};

template <typename OrderType> 
class SingularTermOrderData : public SingularTermOrderData_base<OrderType> {
public:
//   SingularTermOrderData(const Ring<>& r, const OrderType& order) : SingularTermOrderData_base<OrderType>(r,order) {}
};

// Methods that do not depend on template
template<typename OrderType>
int SingularTermOrderData_base<OrderType>::get_ord_size() const {
   return 2;
}

template<typename OrderType>
int* SingularTermOrderData_base<OrderType>::get_block0() const {
   int ord_size = this->get_ord_size();
   int* block0 = (int*)omalloc0((ord_size+1)*sizeof(int));
   block0[0]=1;
   block0[1]=0;
   block0[2]=0;
   return block0;
}

template<typename OrderType>
int* SingularTermOrderData_base<OrderType>::get_block1() const {
   int ord_size = this->get_ord_size();
   int* block1 = (int*)omalloc0((ord_size+1)*sizeof(int));
   block1[0]=n_vars;
   block1[1]=0;
   block1[2]=0;
   return block1;
}




// Methods that do depend on template


template <typename Scalar>
class SingularTermOrderData<Matrix<Scalar>> : public SingularTermOrderData_base<Matrix<Scalar>> {
public:
   using SingularTermOrderData_base<Matrix<Scalar>>::SingularTermOrderData_base;

   int get_ord_size() const
   {
     return safe_cast(this->orderData.rows()+1);
   }

   int* get_block0() const
   {
      int ord_size = this->get_ord_size();
      int* block0 = (int*)omalloc0((ord_size+2)*sizeof(int));
      for (int i = 0; i < ord_size; ++i) {
        block0[i] = 1;
      }
      block0[ord_size]=0;
      block0[ord_size+1]=0;
      return block0;
   }

   int* get_block1() const
   {
      int ord_size = this->get_ord_size();
      int nvars = this->n_vars;
      int* block1 = (int*)omalloc0((ord_size+2)*sizeof(int));
      for(int i = 0; i < ord_size; ++i) {
        block1[i] = nvars;
      }
      block1[ord_size]=0;
      block1[ord_size+1]=0;
      return block1;
   }

   singular_order_type* get_ord() const
   {
      int ord_size = this->get_ord_size();
      singular_order_type* ord=(singular_order_type*)omalloc0((ord_size+2)*sizeof(singular_order_type));
      for(int i = 0; i < ord_size-1; ++i) {
        ord[i] = ringorder_a;
      }
      ord[ord_size-1] = ringorder_lp;
      ord[ord_size] = ringorder_c;
      return ord;
   }

   int** get_wvhdl() const
   {
      int ord_size = this->get_ord_size();
      int nvars = this->n_vars;
      int** wvhdl=(int**)omalloc0((ord_size+2)*sizeof(int*));
      for(int i =0; i<ord_size-1; i++){
         wvhdl[i] = (int*)omalloc0(nvars*sizeof(int));
         for(int j = 0; j<nvars; j++){
            wvhdl[i][j] = (int)this->orderData(i,j);
         }
      }
      wvhdl[ord_size-1] = nullptr;
      wvhdl[ord_size] = nullptr;
      wvhdl[ord_size+1] = nullptr;
      return wvhdl;
   }
};

template <typename Scalar>
class SingularTermOrderData<Vector<Scalar>> : public SingularTermOrderData_base<Vector<Scalar> > {
public:
   using SingularTermOrderData_base<Vector<Scalar>>::SingularTermOrderData_base;

   singular_order_type* get_ord() const
   {
      int ord_size = this->get_ord_size();
      singular_order_type* ord=(singular_order_type*)omalloc0((ord_size+1)*sizeof(singular_order_type));
      ord[1]=ringorder_c;
      ord[0] = ringorder_wp;
      return ord;
   }

   int** get_wvhdl() const
   {
      int ord_size = this->get_ord_size();
      int nvars = this->n_vars;
      int** wvhdl=(int**)omalloc0((ord_size+1)*sizeof(int*));
      wvhdl[0]=(int*)omalloc0(nvars*sizeof(int));
      for(int i =0; i<nvars; i++){
         wvhdl[0][i] = (int) this->orderData[i];
      }
      wvhdl[1] = nullptr;
      wvhdl[2] = nullptr;
      return wvhdl;
   }
};

template<> class SingularTermOrderData<std::string> : public SingularTermOrderData_base<std::string> {
public:
   using SingularTermOrderData_base<std::string>::SingularTermOrderData_base;

   singular_order_type* get_ord() const
   {
      int ord_size = this->get_ord_size();
      singular_order_type* ord=(singular_order_type*)omalloc0((ord_size+1)*sizeof(singular_order_type));
      ord[1]=ringorder_c;
      ord[0] = StringToSingularTermOrder(orderData);
      return ord;
   }

   int** get_wvhdl() const
   {
      int ord_size = this->get_ord_size();
      int** wvhdl=(int**)omalloc0((ord_size+1)*sizeof(int*));
      return wvhdl;
   }
};


} // end namespace singular
} // end namespace ideal
} // end namespace polymake

namespace pm {
namespace operations {

// for use in Maps
template <typename OrderType>
struct cmp_opaque<polymake::ideal::singular::SingularTermOrderData<OrderType>, void> {
  typedef polymake::ideal::singular::SingularTermOrderData<OrderType> first_argument_type;
  typedef first_argument_type second_argument_type;
  typedef cmp_value result_type;

  result_type operator() (const first_argument_type& l, const second_argument_type& r) const
  {
    return operations::cmp()(l.get_orderData(), r.get_orderData());
  }
};

} }