source: git/MP/MPT/MPT_GP.cc @ bcc0f6

spielwiese
Last change on this file since bcc0f6 was bcc0f6, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: AIX port git-svn-id: file:///usr/local/Singular/svn/trunk@9968 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.4 KB
Line 
1/******************************************************************
2 *
3 * File:    MP_GP.h
4 * Purpose: Implementation for MP realization of GP classes
5 * Author:  Olaf Bachmann (obachman@mathematik.uni-kl.de)
6 * Created: 11/98
7 *
8 ******************************************************************/
9
10#include "MPT_GP.h"
11/////////////////////////////////////////////////////////////////////
12///
13/// Iterator:
14//  BUG: Iterator does not work for array of Real64, or Uint8
15///
16/////////////////////////////////////////////////////////////////////
17MPT_GP_Iterator_t::MPT_GP_Iterator_t(MPT_Node_pt tnode)
18{
19  MPT_Assume(tnode != NULL &&
20             (tnode->type == MP_CommonOperatorType || 
21              tnode->type == MP_CommonMetaOperatorType));
22
23  if (tnode->type == MP_CommonMetaOperatorType &&
24      tnode->numchild == 0)
25  {
26    _n = -1;
27    _dynamic = true;
28  }
29  else
30  {
31    _n = tnode->numchild;
32    _dynamic = false;
33  }
34
35  _i = _n+1;
36  _args = NULL;
37}
38
39MPT_GP_Iterator_t::MPT_GP_Iterator_t()
40{
41  _n = -1;
42  _dynamic = false;
43  _i = -2;
44  _args = NULL;
45}
46
47void MPT_GP_Iterator_t::Reset(const void* data)
48{
49  MPT_Assume(data != NULL);
50  if (_dynamic)
51  {
52    MPT_DynArgs_pt dynargs = MPT_DYNARGS_PT(data);
53    _n = dynargs->length;
54    _args = dynargs->args;
55  }
56  else
57    _args = MPT_ARG_PT(data);
58
59  _i = 0;
60}
61
62void* MPT_GP_Iterator_t::Next()
63{
64  if (_i < _n) 
65    return _args[_i++];
66  return NULL;
67}
68
69bool MPT_GP_IsValueIterator(MPT_Tree_pt tree, long vtype)
70{
71  if (tree == NULL || tree->node->type != MP_CommonOperatorType)
72    return false;
73  MPT_Tree_pt proto = MPT_TrueProtoAnnotValue(tree->node);
74
75  if (proto != NULL)
76  {
77    if (vtype < 0 || 
78        (proto->node->type == MP_CommonMetaType && 
79         proto->node->dict == MP_ProtoDict && 
80         vtype == MP_CmtProto_2_MPType(MP_COMMON_T(proto->node->nvalue))))
81      return true;
82    else 
83      return false;
84  }
85  if (vtype >= 0)
86  {
87    long nc = tree->node->numchild, i;
88    MPT_Arg_pt args;
89 
90    for (i=0; i<nc; i++)
91    {
92      if (vtype != MP_COMMON_T(MPT_TREE_PT(tree->args[i])->node->type))
93        return false;
94    }
95  }
96  return true;
97}
98
99MPT_GP_ValueIterator_t::MPT_GP_ValueIterator_t(MPT_Tree_pt tree, long vtype) 
100    : MPT_GP_Iterator_t(tree->node)
101{
102  MPT_Assume(MPT_GP_IsValueIterator(tree, vtype));
103  _prototype = MPT_TrueProtoAnnotValue(tree->node);
104  _vtype = vtype;
105}
106
107MPT_GP_ValueIterator_t::MPT_GP_ValueIterator_t() 
108    : MPT_GP_Iterator_t()
109{
110  _vtype = -1;
111  _prototype = NULL;
112}
113
114void* MPT_GP_ValueIterator_t::Next()
115{
116  void* arg = MPT_GP_Iterator_t::Next();
117 
118  if (_prototype == NULL) arg = MPT_TREE_PT(arg)->node->nvalue;
119  return arg;
120}
121
122
123/////////////////////////////////////////////////////////////////////
124///
125/// Top - level GP
126///
127/////////////////////////////////////////////////////////////////////
128
129MPT_GP_pt MPT_GetGP(MPT_Node_pt tnode)
130{
131  MPT_Assume(tnode != NULL);
132  MPT_GP_pt gp;
133  if ((gp = MPT_GetGP_Atom(tnode)) != NULL) return gp;
134  if ((gp = MPT_GetGP_Comp(tnode)) != NULL) return gp;
135  if ((gp = MPT_GetGP_Poly(tnode)) != NULL) return gp;
136  return NULL;
137}
138
139MPT_GP_pt MPT_GetGP(MPT_Tree_pt tree)
140{
141  if (tree == NULL) return NULL;
142  return MPT_GetGP(tree->node);
143}
144
145/////////////////////////////////////////////////////////////////////
146///
147/// Atoms
148///
149/////////////////////////////////////////////////////////////////////
150static GP_AtomEncoding_t MP_Type_2_GP_AtomEncoding(MP_Common_t mptype)
151{
152  if (MP_IsIntegerType(mptype))
153  {
154    if (MP_IsFixedIntegerType(mptype))
155    {
156      if (mptype == MP_Sint32Type)
157        return GP_SlongAtomEncoding;
158      if (mptype == MP_Uint32Type)
159        return GP_UlongAtomEncoding;
160      if (mptype == MP_Sint8Type)
161        return GP_SlongAtomEncoding;
162      MPT_Assume(mptype == MP_Uint8Type);
163      return GP_UlongAtomEncoding;
164    }
165    else
166    {
167      long format = MPT_GetApIntFormat();
168      if (format == MP_GMP) return GP_GmpApIntAtomEncoding;
169      if (format == MP_PARI) return GP_PariApIntAtomEncoding;
170    }
171  }
172  else if (MP_IsRealType(mptype))
173  {
174    if (mptype == MP_Real32Type) return GP_FloatAtomEncoding;
175    if (mptype == MP_Real64Type) return GP_DoubleAtomEncoding;
176    if (mptype == MP_ApRealType) return GP_ApRealAtomEncoding;
177  }
178  return GP_UnknownAtomEncoding;
179}
180
181MPT_GP_Atom_pt MPT_GetGP_Atom(MPT_Node_pt tnode)
182{
183  if (tnode == NULL) return NULL;
184 
185  MP_NodeType_t ntype = tnode->type;
186  GP_AtomType_t atype;
187  MPT_Arg_t modulus = NULL;
188  MPT_Node_pt _tnode = NULL;
189 
190  if (ntype == MP_CommonMetaType && tnode->dict == MP_ProtoDict)
191  {
192    _tnode = tnode;
193    ntype = MP_CmtProto_2_MPType(MP_COMMON_T(tnode->nvalue));
194  }
195 
196  if (MP_IsRealType(ntype)) atype = GP_RealAtomType;
197  else if (MP_IsIntegerType(ntype))
198  {
199    atype = GP_IntegerAtomType;
200
201    MPT_Tree_pt mtree = MPT_AnnotValue(tnode,
202                                       MP_NumberDict, MP_AnnotNumberModulos);
203    if (mtree != NULL && ntype == mtree->node->type)
204    {
205      modulus = mtree->node->nvalue;
206      if (MPT_Annot(mtree->node,MP_NumberDict,MP_AnnotNumberIsPrime) != NULL)
207        atype = GP_CharPAtomType;
208      else
209        atype = GP_ModuloAtomType;
210    }
211  }
212  else 
213    return NULL;
214 
215  return new MPT_GP_Atom_t(_tnode, atype, 
216                           MP_Type_2_GP_AtomEncoding(ntype), 
217                           modulus);
218}
219 
220GP_AtomEncoding_t MPT_GP_Atom_t::AtomEncoding(const void* data)
221{
222  if (_aencoding != GP_DynamicAtomEncoding) return _aencoding;
223  MPT_Assume(_tnode == NULL && data != NULL);
224  return MP_Type_2_GP_AtomEncoding(((MPT_Tree_pt) data)->node->type);
225}
226
227unsigned long MPT_GP_Atom_t::AtomUlong(const void* data) 
228{
229  MPT_Assume(AtomEncoding(data) == GP_UlongAtomEncoding);
230
231  return (unsigned long) 
232    (_tnode != NULL ? data : ((MPT_Tree_pt) data)->node->nvalue);
233}
234signed long MPT_GP_Atom_t::AtomSlong(const void* data) 
235{
236  MPT_Assume(AtomEncoding(data) == GP_SlongAtomEncoding);
237
238  return (long) 
239    (_tnode != NULL ? data : ((MPT_Tree_pt) data)->node->nvalue);
240}
241float MPT_GP_Atom_t::AtomFloat(const void* data)
242{
243  MPT_Assume(AtomEncoding(data) == GP_FloatAtomEncoding);
244  if (_tnode != NULL)
245    return *((float*) &data);
246  return *((float*) &(((MPT_Tree_pt) data)->node->nvalue));
247}
248double MPT_GP_Atom_t::AtomDouble(const void* data)
249{
250  MPT_Assume(AtomEncoding(data) == GP_DoubleAtomEncoding);
251
252  return (double) 
253    MP_REAL64_T((_tnode!=NULL ? data : ((MPT_Tree_pt) data)->node->nvalue));
254}
255const void* MPT_GP_Atom_t::AtomGmpApInt(const void* data)
256{
257  MPT_Assume(AtomEncoding(data) == GP_GmpApIntAtomEncoding);
258
259  return (_tnode != NULL ? data : ((MPT_Tree_pt) data)->node->nvalue);
260}
261const void* MPT_GP_Atom_t::AtomPariApInt(const void* data)
262{
263  MPT_Assume(AtomEncoding(data) == GP_PariApIntAtomEncoding);
264
265  return (_tnode != NULL ? data : ((MPT_Tree_pt) data)->node->nvalue);
266}
267
268
269/////////////////////////////////////////////////////////////////////
270///
271/// Composite Types
272///
273/////////////////////////////////////////////////////////////////////
274static GP_CompType_t
275MP_TypeDictOp_2_GP_CompType(long type,
276                            MP_DictTag_t dict, MP_Common_t cvalue) 
277{
278  if (type == MP_CommonOperatorType || type == MP_CommonMetaOperatorType)
279  {
280    if (dict == MP_PolyDict)
281    {
282      if (cvalue == MP_CopPolyIdeal)
283        return GP_IdealCompType;
284      if (cvalue == MP_CopPolyModule)
285        return GP_ModuleCompType;
286    }
287    else if (dict == MP_MatrixDict)
288    {
289      if (cvalue == MP_CopMatrixDenseMatrix) return GP_MatrixCompType;
290      if (cvalue == MP_CopMatrixDenseVector) return GP_VectorCompType;
291    }
292    else if (dict == MP_ProtoDict && cvalue == MP_CopProtoArray)
293    {
294      return GP_VectorCompType;
295    }
296    else if (dict == MP_BasicDict)
297    {
298      if (cvalue == MP_CopBasicDiv) return GP_QuotientCompType;
299      if (cvalue == MP_CopBasicComplex) return GP_ComplexCompType;
300    }
301  }
302  else if (dict == MP_NumberDict && type == MP_CommonMetaType)
303  {
304    if (cvalue == MP_CmtNumberRational) return GP_RationalCompType;
305    if (cvalue == MP_CmtNumberComplex) return GP_ComplexCompType;
306  }
307  return GP_UnknownCompType;
308}
309
310MPT_GP_Comp_pt MPT_GetGP_Comp(MPT_Node_pt tnode)
311{
312  if (tnode == NULL) return NULL;
313  GP_CompType_t comptype
314    =   MP_TypeDictOp_2_GP_CompType(tnode->type, tnode->dict,
315                                    MP_COMMON_T(tnode->nvalue));
316 
317  if (comptype == GP_UnknownCompType) return NULL;
318 
319  MPT_GP_pt elements = MPT_GetGP(MPT_ProtoAnnotValue(tnode));
320 
321  if (elements == NULL)
322  {
323    if (comptype == GP_RationalCompType)
324      elements = new MPT_GP_Atom_t(NULL, 
325                                   GP_IntegerAtomType, GP_DynamicAtomEncoding);
326    else if (comptype == GP_ComplexCompType)
327     elements = new MPT_GP_Atom_t(NULL, 
328                                  GP_RealAtomType, GP_DynamicAtomEncoding);
329    else
330      return NULL;
331  }
332 
333  if (comptype == GP_RationalCompType) 
334  {
335    if (elements->Type() != GP_AtomType ||
336        ((MPT_GP_Atom_pt) elements)->AtomType() != GP_IntegerAtomType)
337      goto null_return;
338  }
339  else if (comptype == GP_ComplexCompType)
340  {
341    if (elements->Type() != GP_AtomType ||
342        ((MPT_GP_Atom_pt) elements)->AtomType() != GP_RealAtomType)
343      goto null_return;
344  }
345  else if (comptype == GP_IdealCompType)
346  {
347    if (elements->Type() != GP_PolyType ||
348        ((MPT_GP_Poly_pt) elements)->IsFreeModuleVector())
349      goto null_return;
350  }
351  else if (comptype == GP_ModuleCompType)
352  {
353    if (elements->Type() != GP_PolyType ||
354        ! ((MPT_GP_Poly_pt) elements)->IsFreeModuleVector())
355      goto null_return;
356  }
357  else if (comptype == GP_MatrixCompType)
358  {
359    MPT_Tree_pt tree = MPT_AnnotValue(tnode, 
360                                      MP_MatrixDict,
361                                      MP_AnnotMatrixDimension);
362    MPT_Tree_pt ctree;
363    long dx, dy;
364   
365    if (tree == NULL || tree->node->type != MP_CommonOperatorType ||
366        tree->node->numchild != 2) 
367      goto null_return;
368    ctree = MPT_TREE_PT(tree->args[0]);
369    if (ctree == NULL) goto null_return;
370    if (ctree->node->type != MP_Sint32Type) 
371      dx = MP_SINT32_T(ctree->node->nvalue);
372    else if  (ctree->node->type != MP_Uint32Type) 
373      dx = MP_UINT32_T(ctree->node->nvalue);
374    else goto null_return;
375
376    ctree  = MPT_TREE_PT(tree->args[1]);
377    if (ctree->node->type != MP_Sint32Type) 
378      dy = MP_SINT32_T(ctree->node->nvalue);
379    else if  (ctree->node->type != MP_Uint32Type) 
380      dy = MP_UINT32_T(ctree->node->nvalue);
381    else goto null_return;
382    return new MPT_GP_MatrixComp_t(tnode, elements, dx, dy);
383  }
384  return new MPT_GP_Comp_t(tnode, comptype, elements);
385 
386  null_return:
387  delete elements;
388  return NULL;
389}
390
391/////////////////////////////////////////////////////////////////////
392///
393/// Polys
394///
395/////////////////////////////////////////////////////////////////////
396MPT_GP_Poly_pt MPT_GetGP_Poly(MPT_Node_pt tnode)
397{
398  return MPT_GetGP_MvPoly(tnode);
399}
400
401bool MPT_GP_Poly_t::IsFreeModuleVector()
402{
403  if (MPT_Annot(_tnode,
404                MP_PolyDict,
405                MP_AnnotPolyModuleVector) != NULL)
406    return true;
407  return false;
408}
409
410MPT_GP_MvPoly_pt MPT_GetGP_MvPoly(MPT_Node_pt tnode)
411{
412  return MPT_GetGP_DistMvPoly(tnode);
413}
414
415MPT_GP_MvPoly_t::MPT_GP_MvPoly_t(MPT_Node_pt tnode, 
416                                 MPT_GP_pt coeffs, 
417                                 long nvars)
418    : MPT_GP_Poly_t(tnode, coeffs)
419{
420  _nvars = nvars;
421  MPT_Tree_pt vtree = MPT_AnnotValue(tnode,
422                                     MP_PolyDict,
423                                     MP_AnnotPolyVarNames);
424
425  if (vtree != NULL && MPT_GP_IsValueIterator(vtree, MP_StringType))
426  {
427    _vname_iterator = new MPT_GP_ValueIterator_t(vtree, MP_StringType);
428    _vname_iterator->Reset(vtree->args);
429  }
430  else
431    _vname_iterator = NULL;
432}
433
434static GP_DistMvPolyType_t
435MPT_GetGP_DistMvPolyType(MPT_Node_pt tnode,
436                         MPT_GP_pt &coeffs,
437                         long &nvars)
438{
439  MPT_Assume(tnode != NULL);
440  MPT_Node_pt node;
441  MPT_Tree_pt val;
442  MPT_Arg_pt  ta;
443 
444  // a DDP consists of monoms
445  if ((val =  MPT_ProtoAnnotValue(tnode)) == NULL)
446    return GP_UnknownDistMvPolyType;
447 
448  node = val->node;
449  // a Monom is a tuple of (coeff, expvector)
450  if (! (MPT_IsNode(node, MP_CommonOperatorType, MP_ProtoDict,
451                    MP_CopProtoStruct, 2)))
452    return GP_UnknownDistMvPolyType;
453 
454  // an expvector is a fixed-length array
455  ta = val->args;
456  node = MPT_TREE_PT(ta[1])->node;
457  if (!MPT_IsNode(node, MP_CommonMetaOperatorType, MP_ProtoDict,
458                  MP_CopProtoArray) 
459      || node->numchild <= 0)
460    return GP_UnknownDistMvPolyType;
461  else
462    nvars = node->numchild;
463  // of ints
464  if ((val = MPT_ProtoAnnotValue(node)) == NULL)
465    return GP_UnknownDistMvPolyType;
466  node = val->node;
467  if (!MPT_IsNode(node,  MP_CommonMetaType, MP_ProtoDict, 
468                  MP_CmtProtoIMP_Sint32))
469    return GP_UnknownDistMvPolyType;
470
471  // Look for coeffs
472  coeffs = MPT_GetGP( MPT_TREE_PT(ta[0]));
473  if (coeffs == NULL) return GP_UnknownDistMvPolyType;
474  // Hmm should check that coeffs are Poly or Atom or Rational/Complex
475  else  return  GP_DenseDistMvPolyType;
476}
477 
478MPT_GP_DistMvPoly_pt MPT_GetGP_DistMvPoly(MPT_Node_pt tnode)
479{
480  if (tnode == NULL) return NULL;
481
482  MPT_GP_pt coeffs;
483  long nvars;
484 
485  if (MPT_GetGP_DistMvPolyType(tnode, coeffs, nvars) 
486      != GP_DenseDistMvPolyType)
487    return NULL;
488
489  return new 
490    MPT_GP_DistMvPoly_t(tnode, coeffs, nvars,
491                        MPT_GetGP_Ordering(
492                          (MPT_Tree_pt)MPT_AnnotValue(tnode,
493                                         MP_PolyDict,
494                                         MP_AnnotPolyOrdering), 
495                          nvars), 
496                        MPT_GetGP_Ordering(
497                          (MPT_Tree_pt)MPT_AnnotValue(tnode,
498                                         MP_PolyDict,
499                                         MP_AnnotShouldHavePolyOrdering),
500                          nvars));
501 
502}
503
504MPT_GP_DistMvPoly_t::MPT_GP_DistMvPoly_t(MPT_Node_pt tnode,
505                                         MPT_GP_pt coeffs, long nvars,
506                                         MPT_GP_Ordering_pt has_ordering,
507                                         MPT_GP_Ordering_pt should_ordering)
508    : MPT_GP_MvPoly_t(tnode, coeffs, nvars), _monom_iterator(tnode)
509{
510  _has_ordering = has_ordering;
511  _should_have_ordering = should_ordering;
512}
513
514
515void* MPT_GP_DistMvPoly_t::Coeff(const void* monom)
516{
517  return (MPT_ARG_PT(monom))[0];
518}
519
520void MPT_GP_DistMvPoly_t::ExpVector(const void* monom, long* &expvector)
521{
522  MP_Sint32_t* ev = MP_SINT32_PT((MPT_ARG_PT(monom))[1]);
523 
524  if (expvector != NULL)
525  {
526    long i;
527    for (i=0; i < _nvars; i++) 
528      expvector[i] = ev[i];
529  }
530  else
531    expvector = (long*) ev;
532}
533
534/////////////////////////////////////////////////////////////////////
535///
536/// Ordering
537///
538/////////////////////////////////////////////////////////////////////
539MPT_GP_Ordering_t::MPT_GP_Ordering_t(MPT_Tree_pt otree) 
540{
541  _otree = otree;
542}
543
544MPT_GP_Ordering_pt   MPT_GetGP_Ordering(MPT_Tree_pt o_tree, long nvars) 
545{
546  if (o_tree != NULL)
547  {
548    MPT_GP_Ordering_pt ordering = new MPT_GP_Ordering_t(o_tree);
549    if (ordering->IsOk(nvars)) 
550      return ordering;
551    delete ordering;
552  }
553  return NULL;
554}
555
556GP_OrderingType_t MP_CcPolyOrdering_2_GP_OrderingType(MP_Common_t cc)
557{
558  switch(cc)
559  {
560      case  MP_CcPolyOrdering_Lex           : return GP_LexOrdering;
561      case  MP_CcPolyOrdering_RevLex        : return GP_RevLexOrdering;
562      case  MP_CcPolyOrdering_DegRevLex     : return GP_DegRevLexOrdering;
563      case  MP_CcPolyOrdering_DegLex        : return GP_DegLexOrdering;
564      case  MP_CcPolyOrdering_NegLex        : return GP_NegLexOrdering;
565      case  MP_CcPolyOrdering_NegRevLex     : return GP_NegRevLexOrdering;
566      case  MP_CcPolyOrdering_NegDegRevLex  : return GP_NegDegRevLexOrdering; 
567      case  MP_CcPolyOrdering_NegDegLex     : return GP_NegDegLexOrdering;
568      case  MP_CcPolyOrdering_Matrix        : return GP_MatrixOrdering;
569      case  MP_CcPolyOrdering_IncComp       : return GP_IncrCompOrdering;
570      case  MP_CcPolyOrdering_DecComp       : return GP_DecrCompOrdering;
571
572      default : return GP_UnknownOrdering;
573  }
574}
575
576GP_OrderingType_t MPT_GP_Ordering_t::OrderingType()
577{
578  if (MPT_IsNode(_otree->node, MP_CommonConstantType, MP_PolyDict))
579    return 
580      MP_CcPolyOrdering_2_GP_OrderingType(MP_COMMON_T(_otree->node->nvalue));
581  else  if (MPT_IsNode(_otree->node, MP_CommonOperatorType, MP_BasicDict,
582                       MP_CopBasicList))
583    return GP_ProductOrdering;
584  else
585    return GP_UnknownOrdering;
586}
587
588GP_OrderingType_t MPT_GP_Ordering_t::OrderingType(const void* block)
589{
590  if (block == NULL) return GP_UnknownOrdering;
591  MPT_Tree_pt  btree = ((MPT_Tree_pt) block);
592 
593  if (MPT_IsNode(btree->node, MP_CommonOperatorType, MP_BasicDict,
594                 MP_CopBasicList, 3)) 
595  {
596    btree = MPT_TREE_PT(btree->args[0]);
597    if (btree != NULL && 
598        MPT_IsNode(btree->node, MP_CommonConstantType, MP_PolyDict))
599      return 
600        MP_CcPolyOrdering_2_GP_OrderingType(MP_COMMON_T(btree->node->nvalue));
601  }
602  return GP_UnknownOrdering;
603}
604
605GP_Iterator_pt MPT_GP_Ordering_t::WeightsIterator()
606{
607  GP_OrderingType_t otype = OrderingType();
608 
609  if (otype == GP_UnknownOrdering ||
610      otype == GP_IncrCompOrdering ||
611      otype == GP_DecrCompOrdering ||
612      otype == GP_ProductOrdering)
613    return NULL;
614 
615  MPT_Tree_pt wtree = MPT_AnnotValue(_otree->node,
616                                     MP_PolyDict,
617                                     MP_AnnotPolyWeights);
618  if (wtree == NULL || ! MPT_GP_IsValueIterator(wtree, MP_Sint32Type))
619    return NULL;
620  _weights_iterator = MPT_GP_ValueIterator_t(wtree, MP_Sint32Type);
621  return &(_weights_iterator);
622}
623
624GP_Iterator_pt MPT_GP_Ordering_t::WeightsIterator(const void* block)
625{
626  if (block == NULL) return NULL;
627
628  GP_OrderingType_t otype = OrderingType(block);
629  if (otype == GP_UnknownOrdering ||
630      otype == GP_IncrCompOrdering ||
631      otype == GP_DecrCompOrdering ||
632      otype == GP_ProductOrdering)
633    return NULL;
634
635  MPT_Tree_pt btree = MPT_AnnotValue(_otree->node,
636                                     MP_PolyDict,
637                                     MP_AnnotPolyWeights);
638
639  if (btree == NULL || ! MPT_GP_IsValueIterator(btree, MP_Sint32Type)) 
640    return NULL;
641  _block_weights_iterator = MPT_GP_ValueIterator_t(btree, MP_Sint32Type);
642 
643  return &(_block_weights_iterator);
644}
645
646GP_Iterator_pt MPT_GP_Ordering_t::BlockOrderingIterator()
647{
648  GP_OrderingType_t otype = OrderingType();
649 
650  if (otype != GP_ProductOrdering) return NULL;
651 
652  _block_iterator =  MPT_GP_Iterator_t(_otree->node);
653  _block_iterator.Reset(_otree->args);
654  return &(_block_iterator);
655}
656
657long MPT_GP_Ordering_t::BlockLength(const void* block)
658{
659  long low = -1;
660  long high = -2;
661
662  if (block == NULL) return -1;
663 
664  GP_OrderingType_t otype = OrderingType(block);
665  if (otype == GP_UnknownOrdering ||
666      otype == GP_ProductOrdering) 
667    return -1;
668 
669  MPT_Tree_pt btree = MPT_TREE_PT(block);
670
671  if (btree != NULL &&
672      MPT_IsNode(btree->node, MP_CommonOperatorType, MP_BasicDict,
673                 MP_CopBasicList, 3))
674  {
675    MPT_Tree_pt ctree = MPT_TREE_PT(btree->args[1]);
676    if (ctree == NULL) return -1;
677    if (ctree->node->type != MP_Sint32Type) 
678      low = MP_SINT32_T(ctree->node->nvalue);
679    else if  (ctree->node->type != MP_Uint32Type) 
680      low = MP_UINT32_T(ctree->node->nvalue);
681    else return -1;
682
683    ctree  = MPT_TREE_PT(btree->args[2]);
684    if (ctree == NULL) return -1;
685    if (ctree->node->type != MP_Sint32Type) 
686      high = MP_SINT32_T(ctree->node->nvalue);
687    else if  (ctree->node->type != MP_Uint32Type) 
688      high = MP_UINT32_T(ctree->node->nvalue);
689    else return -1;
690  }
691
692  return high - low;
693}
694
695   
696                                   
697   
698     
699 
700
701
702 
703 
704 
705   
706
707
708
709
710
711
712
713
714
715
Note: See TracBrowser for help on using the repository browser.