Macaulay2 Engine
Loading...
Searching...
No Matches

◆ monomialOrderMake()

MonomialOrder * monomialOrderMake ( const MonomialOrdering * mo)

Definition at line 171 of file imonorder.cpp.

172{
173 MonomialOrder *result;
174 int i, j, nv, this_block;
175 deg_t *wts = nullptr;
176 /* Determine the number of variables, the number of blocks, and the location
177 of the component */
178 int nblocks = 0;
179 int nvars = 0;
180 int hascomponent = 0;
181 for (i = 0; i < mo->len; i++)
182 {
183 struct mon_part_rec_ *t = mo->array[i];
184 nblocks++;
185 if (t->type == MO_POSITION_DOWN || t->type == MO_POSITION_UP)
186 hascomponent++;
187 else if (t->type == MO_NC_LEX)
188 {
189 // Currently, do nothing.
190 }
191 if (t->type != MO_WEIGHTS) nvars += t->nvars;
192 }
193 nblocks -= hascomponent;
194
195 /* Now create the blocks, and fill them in. Also fill in the deg vector */
196 result = getmemstructtype(MonomialOrder *);
197 result->nvars = nvars;
198 result->nslots = 0;
199 result->nblocks = nblocks;
200 result->blocks =
201 (struct mo_block *)getmem(nblocks * sizeof(result->blocks[0]));
202 result->degs = (deg_t *)getmem_atomic(nvars * sizeof(result->degs[0]));
203 if (hascomponent == 0) result->nblocks_before_component = nblocks;
204
205 this_block = 0;
206 nvars = 0;
207 for (i = 0; i < mo->len; i++)
208 {
209 struct mon_part_rec_ *t = mo->array[i];
210 if (t->type != MO_WEIGHTS)
211 {
212 if (t->wts == nullptr)
213 for (j = 0; j < t->nvars; j++) result->degs[nvars++] = 1;
214 else
215 for (j = 0; j < t->nvars; j++) result->degs[nvars++] = t->wts[j];
216 }
217 else
218 {
219 wts = (deg_t *)getmem_atomic(t->nvars * sizeof(wts[0]));
220 for (j = 0; j < t->nvars; j++) wts[j] = t->wts[j];
221 }
222 switch (t->type)
223 {
224 case MO_REVLEX:
225 mo_block_revlex(result->blocks + this_block++, t->nvars);
226 break;
227 case MO_GREVLEX:
228 mo_block_grevlex(result->blocks + this_block++, t->nvars);
229 break;
230 case MO_GREVLEX2:
231 mo_block_grevlex2(result->blocks + this_block++, t->nvars);
232 break;
233 case MO_GREVLEX4:
234 mo_block_grevlex4(result->blocks + this_block++, t->nvars);
235 break;
236 case MO_GREVLEX_WTS:
237 mo_block_grevlex_wts(result->blocks + this_block++, t->nvars);
238 break;
239 case MO_GREVLEX2_WTS:
240 mo_block_grevlex2_wts(result->blocks + this_block++, t->nvars);
241 break;
242 case MO_GREVLEX4_WTS:
243 mo_block_grevlex4_wts(result->blocks + this_block++, t->nvars);
244 break;
245 case MO_LEX:
246 mo_block_lex(result->blocks + this_block++, t->nvars);
247 break;
248 case MO_LEX2:
249 mo_block_lex2(result->blocks + this_block++, t->nvars);
250 break;
251 case MO_LEX4:
252 mo_block_lex4(result->blocks + this_block++, t->nvars);
253 break;
254 case MO_WEIGHTS:
255 // if extra weight values are given (more than "nvars", ignore the
256 // rest.
258 result->blocks + this_block++,
259 (t->nvars <= result->nvars ? t->nvars : result->nvars),
260 wts);
261 break;
262 case MO_LAURENT:
263 mo_block_group_lex(result->blocks + this_block++, t->nvars);
264 break;
266 mo_block_group_revlex(result->blocks + this_block++, t->nvars);
267 break;
268 case MO_NC_LEX:
269 /* MES */
270 break;
271 case MO_POSITION_UP:
272 if (--hascomponent == 0)
273 {
274 // Set the information about the component
275 result->component_up = 1;
276 result->nblocks_before_component = this_block;
277 }
278 // mo_block_position_up(result->blocks + this_block);
279 break;
280 case MO_POSITION_DOWN:
281 if (--hascomponent == 0)
282 {
283 // Set the information about the component
284 result->component_up = 0;
285 result->nblocks_before_component = this_block;
286 }
287 // mo_block_position_down(result->blocks + this_block);
288 break;
289 }
290 }
291
292 /* Go back and fill in the 'slots' information */
293 /* Now fix the first_exp, first_slot values, and also result->{nslots,nvars};
294 */
295 nv = 0;
296 result->nslots = 0;
297 result->nslots_before_component = 0;
298 for (i = 0; i < nblocks; i++)
299 {
300 enum MonomialOrdering_type typ = result->blocks[i].typ;
301
302 result->blocks[i].first_exp = nv;
303 result->blocks[i].first_slot = result->nslots;
304 nv += result->blocks[i].nvars;
305 result->nslots += result->blocks[i].nslots;
306
307 if (typ == MO_WEIGHTS)
308 {
309 result->blocks[i].first_exp = 0;
310
311 /* divide the wt vector by the degree vector */
312 for (j = 0; j < result->blocks[i].nvars; j++)
313 safe::div_by(result->blocks[i].weights[j], result->degs[j]);
314 ;
315 }
316 else if (typ == MO_GREVLEX_WTS || typ == MO_GREVLEX2_WTS ||
317 typ == MO_GREVLEX4_WTS)
318 {
319 result->blocks[i].weights =
320 result->degs + result->blocks[i].first_exp;
321 }
322
323 if (i == result->nblocks_before_component - 1)
324 {
325 result->nslots_before_component = result->nslots;
326 }
327 }
328
329 /* Set is_laurent */
330 result->is_laurent = (int *)getmem_atomic(result->nvars * sizeof(int));
331 for (i = 0; i < result->nvars; i++) result->is_laurent[i] = 0;
332
333 for (i = 0; i < result->nblocks; i++)
334 if (result->blocks[i].typ == MO_LAURENT ||
335 result->blocks[i].typ == MO_LAURENT_REVLEX)
336 {
337 for (j = 0; j < result->blocks[i].nvars; j++)
338 result->is_laurent[result->blocks[i].first_exp + j] = 1;
339 }
340
341 return result;
342}
static void mo_block_grevlex4(struct mo_block *b, int nvars)
Definition imonorder.cpp:61
static void mo_block_grevlex2_wts(struct mo_block *b, int nvars)
Definition imonorder.cpp:83
static void mo_block_group_lex(struct mo_block *b, int nvars)
static void mo_block_group_revlex(struct mo_block *b, int nvars)
static void mo_block_grevlex4_wts(struct mo_block *b, int nvars)
Definition imonorder.cpp:94
static void mo_block_grevlex2(struct mo_block *b, int nvars)
Definition imonorder.cpp:50
static void mo_block_grevlex_wts(struct mo_block *b, int nvars)
Definition imonorder.cpp:72
static void mo_block_grevlex(struct mo_block *b, int nvars)
Definition imonorder.cpp:39
static void mo_block_revlex(struct mo_block *b, int nvars)
Definition imonorder.cpp:28
static void mo_block_lex4(struct mo_block *b, int nvars)
static void mo_block_wt_function(struct mo_block *b, int nvars, deg_t *wts)
static void mo_block_lex2(struct mo_block *b, int nvars)
static void mo_block_lex(struct mo_block *b, int nvars)
int32_t deg_t
Definition imonorder.hpp:43
char * getmem(size_t n)
Definition m2-mem.cpp:74
char * getmem_atomic(size_t n)
Definition m2-mem.cpp:135
VALGRIND_MAKE_MEM_DEFINED & result(result)
#define getmemstructtype(S)
Definition m2-mem.h:143
MonomialOrdering_type
@ MO_GREVLEX4_WTS
@ MO_LAURENT_REVLEX
@ MO_NC_LEX
@ MO_LEX4
@ MO_REVLEX
@ MO_POSITION_UP
@ MO_LEX
@ MO_GREVLEX
@ MO_LEX2
@ MO_GREVLEX4
@ MO_LAURENT
@ MO_GREVLEX2_WTS
@ MO_WEIGHTS
@ MO_POSITION_DOWN
@ MO_GREVLEX2
@ MO_GREVLEX_WTS
static int32_t div_by(int32_t &x, int32_t y, const char *msg)
Definition overflow.hpp:274
enum MonomialOrdering_type type

References MonomialOrdering::array, safe::div_by(), getmem(), getmem_atomic(), getmemstructtype, MonomialOrdering::len, mo_block_grevlex(), mo_block_grevlex2(), mo_block_grevlex2_wts(), mo_block_grevlex4(), mo_block_grevlex4_wts(), mo_block_grevlex_wts(), mo_block_group_lex(), mo_block_group_revlex(), mo_block_lex(), mo_block_lex2(), mo_block_lex4(), mo_block_revlex(), mo_block_wt_function(), MO_GREVLEX, MO_GREVLEX2, MO_GREVLEX2_WTS, MO_GREVLEX4, MO_GREVLEX4_WTS, MO_GREVLEX_WTS, MO_LAURENT, MO_LAURENT_REVLEX, MO_LEX, MO_LEX2, MO_LEX4, MO_NC_LEX, MO_POSITION_DOWN, MO_POSITION_UP, MO_REVLEX, MO_WEIGHTS, mo_block::nvars, mon_part::nvars, result(), mon_part::type, and mon_part::wts.