Changeset 0612fd in git
- Timestamp:
- Jul 13, 2018, 11:59:46 AM (5 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- 7ddfab7159ae462f7e1d3d1c849fa46af8548999
- Parents:
- eb1f43df0bb54ca9ba07b328904464a259c147fa
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/GBEngine/syz4.cc
reb1f43 r0612fd 25 25 const int l = L->ncols-1; 26 26 int k; 27 for (int j = R->N; j > 0; j--) { 28 if (variables[j-1]) { 29 for (k = l; k >= 0; k--) { 30 if (p_GetExp(L->m[k], j, R) > 0) { 27 for (int j = R->N; j > 0; j--) 28 { 29 if (variables[j-1]) 30 { 31 for (k = l; k >= 0; k--) 32 { 33 if (p_GetExp(L->m[k], j, R) > 0) 34 { 31 35 break; 32 36 } 33 37 } 34 if (k < 0) { // no break 38 if (k < 0) 39 { // no break 35 40 variables[j-1] = false; 36 41 } … … 49 54 // variables[R->N] is true iff index == 1, that is, for the first step in 50 55 // the resolution 51 if (unlikely(variables[R->N])) { 56 if (UNLIKELY(variables[R->N])) 57 { 52 58 return true; 53 59 } 54 for (int j = R->N; j > 0; j--) { 55 if (unlikely(variables[j-1] && p_GetExp(m, j, R) > 0)) { 60 for (int j = R->N; j > 0; j--) 61 { 62 if (UNLIKELY(variables[j-1] && p_GetExp(m, j, R) > 0)) 63 { 56 64 return true; 57 65 } … … 78 86 = (unsigned int *)omAlloc0((L->rank+1)*sizeof(unsigned int)); 79 87 unsigned long k = 0; 80 while (k < n_elems) { 88 while (k < n_elems) 89 { 81 90 count[__p_GetComp(L->m[k], R)]++; 82 91 k++; 83 92 } 84 for (int i = 0; i <= L->rank; i++) { 93 for (int i = 0; i <= L->rank; i++) 94 { 85 95 // do ++count[i] and use C[i][0].comp to save count[i] 86 96 C[i] = (lt_struct *)omalloc0((++count[i])*sizeof(lt_struct)); … … 90 100 // the order of the elements in each C[i] matters if check_variables() is 91 101 // to be used 92 while (k > 0) { 102 while (k > 0) 103 { 93 104 const poly a = L->m[k-1]; 94 105 const unsigned long comp = __p_GetComp(a, R); … … 112 123 const lt_struct *v = hash_previous_module[__p_GetComp(t, r)]; 113 124 unsigned long count = v[0].comp; 114 if (unlikely(count == 1)) { 125 if (UNLIKELY(count == 1)) 126 { 115 127 return NULL; 116 128 } … … 119 131 p_MemSum_LengthGeneral(q->exp, multiplier->exp, t->exp, r->ExpL_Size); 120 132 const unsigned long q_not_sev = ~p_GetShortExpVector(q, r); 121 for(unsigned long i = 1; i < count; i++) { 122 if (likely(v[i].sev & q_not_sev) 123 || unlikely(!(_p_LmDivisibleByNoComp(v[i].lt, q, r)))) { 133 for(unsigned long i = 1; i < count; i++) 134 { 135 if (LIKELY(v[i].sev & q_not_sev) 136 || UNLIKELY(!(_p_LmDivisibleByNoComp(v[i].lt, q, r)))) 137 { 124 138 continue; 125 139 } … … 155 169 { 156 170 poly s = find_reducer(multiplier, term, hash_previous_module); 157 if (s == NULL) { 171 if (s == NULL) 172 { 158 173 return NULL; 159 174 } … … 161 176 const int c = __p_GetComp(s, r) - 1; 162 177 poly t; 163 if (use_cache) { 178 if (use_cache) 179 { 164 180 t = traverse_tail(s, c, previous_module, variables, 165 181 hash_previous_module); … … 181 197 { 182 198 const poly tail = previous_module->m[comp]->next; 183 if (unlikely(tail == NULL) || !check_variables(variables, multiplier)) { 199 if (UNLIKELY(tail == NULL) || !check_variables(variables, multiplier)) 200 { 184 201 return NULL; 185 202 } 186 203 sBucket_pt sum = sBucketCreate(currRing); 187 for (poly p = tail; p != NULL; p = pNext(p)) { 204 for (poly p = tail; p != NULL; p = pNext(p)) 205 { 188 206 const poly rt = reduce_term(multiplier, p, previous_module, variables, 189 207 hash_previous_module, use_cache); … … 221 239 { 222 240 const ring r = currRing; 223 for (int i = 0; i < size; i++) { 241 for (int i = 0; i < size; i++) 242 { 224 243 cache_term *T = &(Cache[i]); 225 for (cache_term::iterator itr = T->begin(); itr != T->end(); ++itr) { 244 for (cache_term::iterator itr = T->begin(); itr != T->end(); ++itr) 245 { 226 246 p_Delete(&(itr->second), r); 227 247 p_Delete(const_cast<poly*>(&(itr->first)), r); … … 242 262 const poly multiplier) 243 263 { 244 if (likely(itr->second == NULL)) { 264 if (LIKELY(itr->second == NULL)) 265 { 245 266 return NULL; 246 267 } 247 268 const ring r = currRing; 248 269 poly p = p_Copy(itr->second, r); 249 if (likely(!n_Equal(pGetCoeff(multiplier), pGetCoeff(itr->first), r))) { 270 if (LIKELY(!n_Equal(pGetCoeff(multiplier), pGetCoeff(itr->first), r))) 271 { 250 272 number n = n_Div(pGetCoeff(multiplier), pGetCoeff(itr->first), r); 251 273 p = p_Mult_nn(p, n, r); … … 261 283 cache_term *T = &(Cache[comp]); 262 284 cache_term::const_iterator itr = T->find(multiplier); 263 if (likely(itr != T->end())) { 285 if (LIKELY(itr != T->end())) 286 { 264 287 return get_from_cache_term(itr, multiplier); 265 288 } … … 283 306 hash_previous_module, use_cache); 284 307 poly t2; 285 if (use_cache) { 308 if (use_cache) 309 { 286 310 t2 = traverse_tail(a->next, __p_GetComp(a->next, R)-1, 287 311 previous_module, variables, hash_previous_module); … … 306 330 int i, j; 307 331 int k = id->ncols-1; 308 for (i = k; i >= 0; i--) { 309 for (j = k; j > i; j--) { 310 if (id->m[j] != NULL) { 311 if (p_DivisibleBy(id->m[i], id->m[j], r)) { 332 for (i = k; i >= 0; i--) 333 { 334 for (j = k; j > i; j--) 335 { 336 if (id->m[j] != NULL) 337 { 338 if (p_DivisibleBy(id->m[i], id->m[j], r)) 339 { 312 340 p_Delete(&id->m[j], r); 313 341 } 314 else if (p_DivisibleBy(id->m[j], id->m[i], r)) { 342 else if (p_DivisibleBy(id->m[j], id->m[i], r)) 343 { 315 344 p_Delete(&id->m[i], r); 316 345 break; … … 334 363 pSetCoeff0(head, n_Init(1, r->cf)); 335 364 long exp_i, exp_j, lcm; 336 for (int k = (int)r->N; k > 0; k--) { 365 for (int k = (int)r->N; k > 0; k--) 366 { 337 367 exp_i = p_GetExp(f_i, k, r); 338 368 exp_j = p_GetExp(f_j, k, r); … … 360 390 r->cf)); 361 391 long exp_i, exp_j, lcm; 362 for (int k = (int)r->N; k > 0; k--) { 392 for (int k = (int)r->N; k > 0; k--) 393 { 363 394 exp_i = p_GetExp(f_i, k, r); 364 395 exp_j = p_GetExp(f_j, k, r); … … 389 420 unsigned long comp = __p_GetComp(G->m[i], r); 390 421 int ncols = 0; 391 for (int j = i-1; j >= 0; j--) { 422 for (int j = i-1; j >= 0; j--) 423 { 392 424 if (__p_GetComp(G->m[j], r) == comp) ncols++; 393 425 } 394 if (ncols > 0) { 426 if (ncols > 0) 427 { 395 428 M_i = idInit(ncols, G->ncols); 396 429 int k = ncols-1; 397 for (int j = i-1; j >= 0; j--) { 398 if (__p_GetComp(G->m[j], r) == comp) { 430 for (int j = i-1; j >= 0; j--) 431 { 432 if (__p_GetComp(G->m[j], r) == comp) 433 { 399 434 M_i->m[k] = syzHead(G, i, j); 400 435 k--; … … 422 457 index++; 423 458 int ncols = i-index; 424 if (ncols > 0) { 459 if (ncols > 0) 460 { 425 461 M_i = idInit(ncols, G->ncols); 426 for (int j = ncols-1; j >= 0; j--) { 462 for (int j = ncols-1; j >= 0; j--) 463 { 427 464 M_i->m[j] = syzHead(G, i, j+index); 428 465 } … … 439 476 { 440 477 int ncols = 0; 441 for (int i = size-1; i >= 0; i--) { 442 if (M[i] != NULL) { 478 for (int i = size-1; i >= 0; i--) 479 { 480 if (M[i] != NULL) 481 { 443 482 ncols += M[i]->ncols; 444 483 } … … 447 486 ideal result = idInit(ncols, rank); 448 487 int k = ncols-1; 449 for (int i = size-1; i >= 0; i--) { 450 if (M[i] != NULL) { 451 for (int j = M[i]->ncols-1; j >= 0; j--) { 488 for (int i = size-1; i >= 0; i--) 489 { 490 if (M[i] != NULL) 491 { 492 for (int j = M[i]->ncols-1; j >= 0; j--) 493 { 452 494 result->m[k] = M[i]->m[j]; 453 495 k--; … … 482 524 p_GetExpV(p_a, exp_a, r); 483 525 p_GetExpV(p_b, exp_b, r); 484 for (int i = r->N; i > 0; i--) { 526 for (int i = r->N; i > 0; i--) 527 { 485 528 cmp = (exp_a[i] > exp_b[i]) - (exp_a[i] < exp_b[i]); 486 if (cmp != 0) { 529 if (cmp != 0) 530 { 487 531 return cmp; 488 532 } … … 498 542 if ((cmp = compare_comp(p_a, p_b)) 499 543 || (cmp = compare_deg(p_a, p_b)) 500 || (cmp = compare_lex(p_a, p_b))) { 544 || (cmp = compare_lex(p_a, p_b))) 545 { 501 546 return cmp; 502 547 } … … 512 557 { 513 558 ideal *M = (ideal *)omalloc((G->ncols-1)*sizeof(ideal)); 514 for (int i = G->ncols-2; i >= 0; i--) { 559 for (int i = G->ncols-2; i >= 0; i--) 560 { 515 561 M[i] = syzM_i(G, i+1, syzHead); 516 562 } 517 563 ideal frame = idConcat(M, G->ncols-1, G->ncols); 518 for (int i = G->ncols-2; i >= 0; i--) { 519 if (M[i] != NULL) { 564 for (int i = G->ncols-2; i >= 0; i--) 565 { 566 if (M[i] != NULL) 567 { 520 568 omFreeSize(M[i]->m, M[i]->ncols*sizeof(poly)); 521 569 omFreeBin(M[i], sip_sideal_bin); … … 533 581 const std::vector<bool> &variables, const bool use_cache) 534 582 { 535 if (use_cache) { 583 if (use_cache) 584 { 536 585 initialize_cache(res[index-1]->ncols); 537 586 } … … 539 588 = (lt_struct **)omAlloc((res[index-1]->rank+1)*sizeof(lt_struct *)); 540 589 initialize_hash(hash_previous_module, res[index-1]); 541 for (int j = res[index]->ncols-1; j >= 0; j--) { 590 for (int j = res[index]->ncols-1; j >= 0; j--) 591 { 542 592 res[index]->m[j]->next->next = lift_ext_LT(res[index]->m[j], 543 593 res[index-1], variables, hash_previous_module, use_cache); 544 594 } 545 for (int i = 0; i <= res[index-1]->rank; i++) { 595 for (int i = 0; i <= res[index-1]->rank; i++) 596 { 546 597 omfree(hash_previous_module[i]); 547 598 } 548 599 omFree(hash_previous_module); 549 if (use_cache) { 600 if (use_cache) 601 { 550 602 delete_cache(res[index-1]->ncols); 551 603 } … … 559 611 { 560 612 const ring R = currRing; 561 for (int j = R->N; j > 0; j--) { 562 if (!variables[j-1] && p_GetExp(m, j, R) > 0) { 613 for (int j = R->N; j > 0; j--) 614 { 615 if (!variables[j-1] && p_GetExp(m, j, R) > 0) 616 { 563 617 return true; 564 618 } … … 574 628 const std::vector<bool> &variables) 575 629 { 576 for (int i = 0; i < res[index]->ncols; i++) { 630 for (int i = 0; i < res[index]->ncols; i++) 631 { 577 632 poly p_iter = res[index]->m[i]->next; 578 if (p_iter != NULL) { 579 while (p_iter->next != NULL) { 580 if (contains_unused_variable(p_iter->next, variables)) { 633 if (p_iter != NULL) 634 { 635 while (p_iter->next != NULL) 636 { 637 if (contains_unused_variable(p_iter->next, variables)) 638 { 581 639 pLmDelete(&p_iter->next); 582 640 } else { … … 591 649 { 592 650 const ring r = currRing; 593 for (int i = 0; i < res[index]->ncols; i++) { 594 if (res[index]->m[i] != NULL) { 651 for (int i = 0; i < res[index]->ncols; i++) 652 { 653 if (res[index]->m[i] != NULL) 654 { 595 655 p_Delete(&(res[index]->m[i]->next), r); 596 656 } … … 608 668 { 609 669 int index = 1; 610 while (!idIs0(res[index])) { 611 if (do_lifting) { 670 while (!idIs0(res[index])) 671 { 672 if (do_lifting) 673 { 612 674 computeLiftings(res, index, variables, use_cache); 613 if (single_module) { 675 if (single_module) 676 { 614 677 delete_tails(res, index-1); 615 678 } 616 679 // we don't know if the input is a reduced SB: 617 if (index == 1) { 680 if (index == 1) 681 { 618 682 variables[currRing->N] = false; 619 683 } 620 684 update_variables(variables, res[index]); 621 if (use_tensor_trick) { 685 if (use_tensor_trick) 686 { 622 687 delete_variables(res, index, variables); 623 688 } … … 639 704 const bool use_tensor_trick) 640 705 { 641 if (idIs0(res[0])) { 706 if (idIs0(res[0])) 707 { 642 708 return 1; 643 709 } 644 710 std::vector<bool> variables; 645 711 variables.resize(currRing->N+1, true); 646 if (do_lifting) { 712 if (do_lifting) 713 { 647 714 update_variables(variables, res[0]); 648 if (use_tensor_trick) { 715 if (use_tensor_trick) 716 { 649 717 delete_variables(res, 0, variables); 650 718 } 651 719 } 652 720 int index = 0; 653 if (max_index > 0) { 721 if (max_index > 0) 722 { 654 723 res[1] = computeFrame(res[0], syzM_i_unsorted, syzHead); 655 724 index = computeResolution_iteration(res, max_index, syzHead, … … 664 733 bool *single_module_ptr, const char *method) 665 734 { 666 if (strcmp(method, "complete") == 0) { // default 735 if (strcmp(method, "complete") == 0) 736 { // default 667 737 *syzHead_ptr = syzHeadExtFrame; 668 738 *do_lifting_ptr = true; 669 739 *single_module_ptr = false; 670 740 } 671 else if (strcmp(method, "frame") == 0) { 741 else if (strcmp(method, "frame") == 0) 742 { 672 743 *syzHead_ptr = syzHeadFrame; 673 744 *do_lifting_ptr = false; 674 745 *single_module_ptr = false; 675 746 } 676 else if (strcmp(method, "extended frame") == 0) { 747 else if (strcmp(method, "extended frame") == 0) 748 { 677 749 *syzHead_ptr = syzHeadExtFrame; 678 750 *do_lifting_ptr = false; 679 751 *single_module_ptr = false; 680 752 } 681 else if (strcmp(method, "single module") == 0) { 753 else if (strcmp(method, "single module") == 0) 754 { 682 755 *syzHead_ptr = syzHeadExtFrame; 683 756 *do_lifting_ptr = true; … … 720 793 poly p, q; 721 794 int index = (single_module ? length-1 : 1); 722 while (index < length && !idIs0(res[index])) { 723 for (int j = res[index]->ncols-1; j >= 0; j--) { 795 while (index < length && !idIs0(res[index])) 796 { 797 for (int j = res[index]->ncols-1; j >= 0; j--) 798 { 724 799 insert_first_term(res[index]->m[j]->next, p, q, R); 725 800 insert_first_term(res[index]->m[j], p, q, R); … … 751 826 syStrategy result = (syStrategy)omAlloc0(sizeof(ssyStrategy)); 752 827 resolvente res = (resolvente)omAlloc0((length+1)*sizeof(ideal)); 753 if (strcmp(method, "frame") != 0) { 828 if (strcmp(method, "frame") != 0) 829 { 754 830 res[0] = id_Copy(arg, currRing); 755 } else { 831 } 832 else 833 { 756 834 res[0] = id_Head(arg, currRing); 757 835 } … … 762 840 int new_length = computeResolution(res, length-1, syzHead, do_lifting, 763 841 single_module, use_cache, use_tensor_trick); 764 if (new_length < length) { 842 if (new_length < length) 843 { 765 844 res = (resolvente)omReallocSize(res, (length+1)*sizeof(ideal), 766 845 (new_length+1)*sizeof(ideal)); 767 846 } 768 if (strcmp(method, "frame") != 0) { 847 if (strcmp(method, "frame") != 0) 848 { 769 849 insert_ext_induced_LTs(res, new_length, single_module); 770 850 } -
libpolys/misc/auxiliary.h
reb1f43 r0612fd 412 412 413 413 #ifdef __GNUC__ 414 #define likely(X) (__builtin_expect(!!(X), 1)) 415 #define unlikely(X) (__builtin_expect(!!(X), 0)) 416 #else 417 #define likely(X) (X) 418 #define unlikely(X) (X) 419 #endif 420 421 #define LIKELY likely 422 #define UNLIKELY unlikely 423 414 #define LIKELY(X) (__builtin_expect(!!(X), 1)) 415 #define UNLIKELY(X) (__builtin_expect(!!(X), 0)) 416 #else 417 #define LIKELY(X) (X) 418 #define UNLIKELY(X) (X) 419 #endif 424 420 425 421 #endif
Note: See TracChangeset
for help on using the changeset viewer.