1 | /****************************************************************** |
---|
2 | * |
---|
3 | * File: MP_PutGP.h |
---|
4 | * Purpose: Puts an GP Object to an MP link |
---|
5 | * Author: Olaf Bachmann (obachman@mathematik.uni-kl.de) |
---|
6 | * Created: 11/98 |
---|
7 | * |
---|
8 | ******************************************************************/ |
---|
9 | |
---|
10 | #include "GP.h" |
---|
11 | #include "MP.h" |
---|
12 | |
---|
13 | |
---|
14 | MP_Status_t MP_PutGP_Object(MP_Link_pt link, GP_Object_t gp) |
---|
15 | { |
---|
16 | switch(gp->Type()) |
---|
17 | { |
---|
18 | case GP_AtomType: |
---|
19 | return MP_PutGP_AtomPacket(link, gp->Atom(), data); |
---|
20 | |
---|
21 | case GP_PolyType: |
---|
22 | return MP_PutGP_PolySpec(link, gp->Poly(), meta, data); |
---|
23 | |
---|
24 | case GP_CompType: |
---|
25 | return MP_PutGP_CompSpec(link, gp->Comp(), meta, data); |
---|
26 | |
---|
27 | default: |
---|
28 | return MP_SetError(link, MP_ExternalError); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | MP_Status_t MP_PutGP_Data(MP_Link_pt link, GP_pt gp, void* data) |
---|
33 | { |
---|
34 | switch(gp->Type()) |
---|
35 | { |
---|
36 | case GP_AtomType: |
---|
37 | return MP_PutGP_AtomData(link, gp->Atom(), data); |
---|
38 | |
---|
39 | case GP_PolyType: |
---|
40 | return MP_PutGP_PolyData(link, gp->Poly(), data); |
---|
41 | |
---|
42 | case GP_CompType: |
---|
43 | return MP_PutGP_CompData(link, gp->Comp(), data); |
---|
44 | |
---|
45 | default: |
---|
46 | return MP_SetError(link, MP_ExternalError); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | ///////////////////////////////////////////////////////////////////// |
---|
52 | /// |
---|
53 | /// Atoms |
---|
54 | /// |
---|
55 | ///////////////////////////////////////////////////////////////////// |
---|
56 | MP_Status_t MP_PutGP_AtomSpec(MP_Link_pt link, GP_Atom_pt gp, |
---|
57 | bool meta = TRUE, void* data = NULL) |
---|
58 | { |
---|
59 | GP_AtomEncoding aencoding = gp->AtomEncoding(); |
---|
60 | GP_AtomType_t atype = AtomType(); |
---|
61 | MP_Common_t mtype; |
---|
62 | MP_DictType_t dict = MP_ProtoDict; |
---|
63 | MP_NumAnnot_t numannots = 0; |
---|
64 | |
---|
65 | if (aencoding == GP_DynamicAtomEncoding && meta == FALSE) |
---|
66 | aencoding = gp->DynamicAtomEncoding(data); |
---|
67 | |
---|
68 | switch(aencoding) |
---|
69 | { |
---|
70 | case GP_SlongAtomEncoding: |
---|
71 | mtype = MP_CmtProtoIMP_Sint32; |
---|
72 | break; |
---|
73 | |
---|
74 | case GP_UlongAtomEncoding: |
---|
75 | mtype = MP_CmtProtoIMP_Uint32; |
---|
76 | break; |
---|
77 | |
---|
78 | case GP_FloatAtomEncoding: |
---|
79 | mtype = MP_CmtProtoIMP_Real32; break; |
---|
80 | |
---|
81 | case GP_DoubleAtomEncoding: |
---|
82 | mtype = MP_CmtProtoIMP_Real64; break; |
---|
83 | |
---|
84 | case GP_IncrApIntAtomEncoding: |
---|
85 | case GP_DecrApIntAtomEncoding: |
---|
86 | case GP_GmpApIntAtomEncoding: |
---|
87 | case GP_PariApIntAtomEncoding: |
---|
88 | mtype = MP_CmtProtoIMP_ApInt; break; |
---|
89 | |
---|
90 | case GP_DynamicAtomEncoding: |
---|
91 | { |
---|
92 | dict = MP_NumberDict; |
---|
93 | switch(atype) |
---|
94 | { |
---|
95 | case GP_IntegerAtomType: |
---|
96 | mtype = MP_CmtNumberInteger; break; |
---|
97 | |
---|
98 | case GP_RealAtomType: |
---|
99 | mtype = MP_CmtNumberReal; break; |
---|
100 | |
---|
101 | case GP_CharPAtomType: |
---|
102 | mtype = MP_CmtNumberCharP; break; |
---|
103 | |
---|
104 | case GP_ModuloAtomType: |
---|
105 | mtype = MP_CmtNumberModulo; break; |
---|
106 | |
---|
107 | default: |
---|
108 | return MP_SetError(link, MP_ExternalError); |
---|
109 | } |
---|
110 | break; |
---|
111 | } |
---|
112 | |
---|
113 | default: |
---|
114 | return MP_SetError(link, MP_ExternalError); |
---|
115 | } |
---|
116 | |
---|
117 | if (atype == GP_CharPAtomType || atype == GP_ModuloAtomType) |
---|
118 | numannots = 1; |
---|
119 | |
---|
120 | if (meta == TRUE) |
---|
121 | ERR_CHK(IMP_PutNodeHeader(link,MP_CommonMetaType,dict,mtype,numannots,0)); |
---|
122 | else |
---|
123 | ERR_CHK(IMP_PutNodeHeader(link, |
---|
124 | MP_CmtProt_2_MPType(mtype), 0, 0, numannots, 0)); |
---|
125 | |
---|
126 | if (numannots == 1) |
---|
127 | { |
---|
128 | MP_PutAnnotationPacket(link, |
---|
129 | MP_NumberDict, |
---|
130 | MP_AnnotNumberModulos, |
---|
131 | MP_AnnotValuated); |
---|
132 | if (atype == GP_ModuloAtomType) |
---|
133 | numannots = 0; |
---|
134 | |
---|
135 | if (mtype == MP_CmtProtoIMP_Sint32) |
---|
136 | ERR_CHK(MP_PutSint32Packet(link, |
---|
137 | (MP_Sint32_t) gp->AtomModulus(), numannots)); |
---|
138 | else if (mtype == MP_CmtProtoIMP_Uint32) |
---|
139 | ERR_CHK(MP_PutUint32Packet(link, |
---|
140 | (MP_Uint32_t) gp->AtomModulus(), numannots)); |
---|
141 | else if (mtype == MP_CmtProtoIMP_ApInt) |
---|
142 | ERR_CHK(MP_PutApIntPacket(link, |
---|
143 | (MP_ApInt_t) gp->AtomModulus(), numannots)); |
---|
144 | else |
---|
145 | return MPT_SetError(link, MPT_ExternalError); |
---|
146 | |
---|
147 | if (numannots == 1) |
---|
148 | ERRCHK(MP_PutAnnotationPacket(link, |
---|
149 | MP_NumberDict, |
---|
150 | MP_AnnotNumberIsPrime, |
---|
151 | 0)); |
---|
152 | } |
---|
153 | |
---|
154 | return MP_Success; |
---|
155 | } |
---|
156 | |
---|
157 | MP_Status_t MP_PutGP_AtomData(MP_Link_pt link, GP_Atom_pt gp, void* data) |
---|
158 | { |
---|
159 | GP_AtomEncoding aencoding = gp->AtomEncoding(); |
---|
160 | |
---|
161 | if (aencoding == GP_DynamicAtomEncoding) |
---|
162 | aencoding = gp->DynamicAtomEncoding(data); |
---|
163 | |
---|
164 | switch(aencoding) |
---|
165 | { |
---|
166 | case GP_UlongAtomEncoding: |
---|
167 | return IMP_PutUint32(link, (MP_Uint32_t) gp->AtomUlong(data)); |
---|
168 | |
---|
169 | case GP_SlongAtomEncoding: |
---|
170 | return IMP_PutSint32(link, (MP_Sint32_t) gp->AtomSlong(data)); |
---|
171 | |
---|
172 | case GP_FloatAtomEncoding: |
---|
173 | return IMP_PutReal32(link, (MP_Real32_t) gp->AtomFloat(data)); |
---|
174 | |
---|
175 | case GP_DoubleAtomEncoding: |
---|
176 | return IMP_PutReal64(link, (MP_Real64_t) gp->AtomDouble(data)); |
---|
177 | |
---|
178 | case GP_PariApIntAtomEncoding: |
---|
179 | // Hmm .. this should be implemented more carefully |
---|
180 | return IMP_PutApInt(link, (MP_ApInt_t) gp->AtomPariApInt(data)); |
---|
181 | |
---|
182 | case GP_GmpApIntAtomEncoding: |
---|
183 | return IMP_PutApInt(link, (MP_ApInt_t) gp->AtomGmpApInt(data)); |
---|
184 | |
---|
185 | case GP_GmpApRealAtomEncoding: |
---|
186 | return IMP_PutApReal(link, (MP_ApInt_t) gp->AtomGmpApReal(data)); |
---|
187 | |
---|
188 | default: |
---|
189 | return MP_SetError(link, MP_ExternalError); |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | ///////////////////////////////////////////////////////////////////// |
---|
194 | /// |
---|
195 | /// Composites |
---|
196 | /// |
---|
197 | ///////////////////////////////////////////////////////////////////// |
---|
198 | |
---|
199 | MP_Status_t MP_PutGP_CompSpec(MP_Link_pt link, GP_Comp_pt gp, |
---|
200 | bool meta = TRUE, void* data = NULL) |
---|
201 | { |
---|
202 | GP_CompType_t ctype = CompType(); |
---|
203 | MP_NodeType_t ntype = MP_CommonMetaOperatorType; |
---|
204 | MP_DictTag_t dict; |
---|
205 | MP_Common_t cval; |
---|
206 | MP_NumAnnot_t numannot = 1; |
---|
207 | MP_NumChild_t numchild = 0; |
---|
208 | |
---|
209 | if (ctype == GP_RationalCompType || |
---|
210 | ctype == GP_ComplexCompType) |
---|
211 | { |
---|
212 | if (meta == TRUE) |
---|
213 | ERR_CHK(MP_PutCommonMetaTypePacket(link, MP_NumberDict, |
---|
214 | (ctype == GP_RationalCompType ? |
---|
215 | MP_CmtNumberRational : |
---|
216 | MP_CmtNumberComplex), 0)); |
---|
217 | return MP_Success; |
---|
218 | } |
---|
219 | |
---|
220 | if (meta == FALSE) |
---|
221 | { |
---|
222 | numchild = gp->ElementIterator()->N(); |
---|
223 | ntype = MP_CommonOperatorType; |
---|
224 | } |
---|
225 | |
---|
226 | switch (ctype) |
---|
227 | { |
---|
228 | case GP_IdealCompType: |
---|
229 | dict = MP_PolyDict; |
---|
230 | cval = MP_CopPolyIdeal; |
---|
231 | break; |
---|
232 | |
---|
233 | case GP_ModuleCompType: |
---|
234 | dict = MP_PolyDict; |
---|
235 | cval = MP_CopPolyModule; |
---|
236 | break; |
---|
237 | |
---|
238 | case GP_QuotientCompType: |
---|
239 | dict = MP_BasicDict; |
---|
240 | cval = MP_CopBasicDiv; |
---|
241 | break; |
---|
242 | |
---|
243 | case GP_VectorCompType: |
---|
244 | dict = MP_MatrixDict; |
---|
245 | cval = MP_CopMatrixDenseVector; |
---|
246 | break; |
---|
247 | |
---|
248 | case GP_MatrixCompType: |
---|
249 | dict = MP_MatrixDict; |
---|
250 | cval = MP_CopMatrixDenseMatrix; |
---|
251 | numannot++; |
---|
252 | break; |
---|
253 | |
---|
254 | case GP_FreeModuleCompType: |
---|
255 | dict = MP_PolyDict; |
---|
256 | cval = MP_CopPolyFreeModule; |
---|
257 | break; |
---|
258 | |
---|
259 | default: |
---|
260 | return MP_SetError(link, MP_ExternalError); |
---|
261 | } |
---|
262 | ERR_CHK(IMP_PutNodeHeader(link, ntype, dict, cval, numannot, numchild)); |
---|
263 | ERR_CHK(MP_PutAnnotationPacket(link, MP_ProtoDict, MP_AnnotProtoProtoType, |
---|
264 | MP_AnnotReqValNode)); |
---|
265 | ERR_CHK(MP_PutGP_Spec(link, gp->Elements())); |
---|
266 | if (ctype == GP_MatrixCompType) |
---|
267 | { |
---|
268 | long dx, dy; |
---|
269 | gp->MatrixDimension(dx, dy); |
---|
270 | |
---|
271 | ERR_CHK(MP_PutAnnotationPacket(link, |
---|
272 | MP_MatrixDict, |
---|
273 | MP_AnnotMatrixDimension, |
---|
274 | MP_AnnotReqValNode)); |
---|
275 | ERR_CHK(MP_PutCommonOperatorPacket(link, |
---|
276 | MP_BasicDict, |
---|
277 | MP_CopBasicList, |
---|
278 | 0, 2)); |
---|
279 | |
---|
280 | ERR_CHK(MP_PutSint32Packet(link, (MP_Uint32_t) , dx)); |
---|
281 | ERR_CHK(MP_PutSint32Packet(link, (MP_Uint32_t) , dy)); |
---|
282 | } |
---|
283 | return MP_Success; |
---|
284 | } |
---|
285 | |
---|
286 | |
---|
287 | MP_Status_t MP_PutGP_CompData(MP_Link_pt link, GP_Atom_pt gp, void* data, |
---|
288 | bool meta) |
---|
289 | { |
---|
290 | |
---|
291 | |
---|
292 | bool GP_Comp_t::IsCompDataOk(const void* data) |
---|
293 | { |
---|
294 | GP_Iterator_pt it = ElementDataIterator(data); |
---|
295 | GP_pt elements = Elements(); |
---|
296 | GP_CompType_t ctype = CompType(); |
---|
297 | long i, n; |
---|
298 | |
---|
299 | |
---|
300 | if (it == NULL) return false; |
---|
301 | n = it->N(); |
---|
302 | if (n < 0) return false; |
---|
303 | |
---|
304 | switch (CompType()) |
---|
305 | { |
---|
306 | case GP_MatrixCompType: |
---|
307 | { |
---|
308 | long dx, dy; |
---|
309 | MatrixDimension(data, dx, dy); |
---|
310 | if (dx < 0 || dy < 0) return false; |
---|
311 | if (dx*dy != n) return false; |
---|
312 | break; |
---|
313 | } |
---|
314 | |
---|
315 | case GP_RationalCompType: |
---|
316 | case GP_QuotientCompType: |
---|
317 | case GP_ComplexCompType: |
---|
318 | if (n == 0 || n > 2) return false; |
---|
319 | break; |
---|
320 | |
---|
321 | case GP_UnknownCompType: |
---|
322 | return false; |
---|
323 | |
---|
324 | default: |
---|
325 | break; |
---|
326 | } |
---|
327 | |
---|
328 | for (i=0; i<n; i++) |
---|
329 | if (elements->IsDataOk(it->Next()) == false) return false; |
---|
330 | return true; |
---|
331 | } |
---|
332 | |
---|
333 | |
---|
334 | ///////////////////////////////////////////////////////////////////// |
---|
335 | /// |
---|
336 | /// Polys |
---|
337 | /// |
---|
338 | ///////////////////////////////////////////////////////////////////// |
---|
339 | bool GP_Poly_t::IsPolySpecOk() |
---|
340 | { |
---|
341 | void* mpoly; |
---|
342 | |
---|
343 | switch(PolyType()) |
---|
344 | { |
---|
345 | case GP_UvPolyType: |
---|
346 | if (UvPoly() != NULL && UvPoly()->IsUvPolySpecOk()) break; |
---|
347 | return false; |
---|
348 | |
---|
349 | case GP_MvPolyType: |
---|
350 | if (MvPoly() != NULL && MvPoly()->IsMvPolySpecOk()) break; |
---|
351 | return false; |
---|
352 | |
---|
353 | default: |
---|
354 | return false; |
---|
355 | } |
---|
356 | if (Coeffs()->IsSpecOk() == false) return false; |
---|
357 | |
---|
358 | mpoly = MinPoly(); |
---|
359 | if (mpoly != NULL) return IsPolyDataOk(mpoly); |
---|
360 | return true; |
---|
361 | } |
---|
362 | bool GP_Poly_t::IsPolyDataOk(const void* data) |
---|
363 | { |
---|
364 | |
---|
365 | switch(PolyType()) |
---|
366 | { |
---|
367 | case GP_UvPolyType: |
---|
368 | return UvPoly() != NULL && UvPoly()->IsUvPolyDataOk(data); |
---|
369 | |
---|
370 | case GP_MvPolyType: |
---|
371 | return MvPoly() != NULL && MvPoly()->IsMvPolyDataOk(data); |
---|
372 | |
---|
373 | default: |
---|
374 | return false; |
---|
375 | } |
---|
376 | } |
---|
377 | |
---|
378 | |
---|
379 | ///////////////////////////////////////////////////////////////////// |
---|
380 | /// |
---|
381 | /// Univariate Polys |
---|
382 | /// |
---|
383 | ///////////////////////////////////////////////////////////////////// |
---|
384 | bool GP_UvPoly_t::IsUvPolySpecOk() |
---|
385 | { |
---|
386 | if (UvPolyType() == GP_UnknownUvPolyType) return false; |
---|
387 | return true; |
---|
388 | } |
---|
389 | |
---|
390 | bool GP_UvPoly_t::IsUvPolyDataOk(const void* data) |
---|
391 | { |
---|
392 | GP_Iterator_pt it = TermIterator(data); |
---|
393 | bool isSparse = (UvPolyType() == GP_SparseUvPolyType); |
---|
394 | GP_pt coeff = Coeffs(); |
---|
395 | |
---|
396 | long i, n; |
---|
397 | void* term; |
---|
398 | |
---|
399 | |
---|
400 | if (it == NULL) return false; |
---|
401 | n = it->N(); |
---|
402 | |
---|
403 | if (n < 0) return false; |
---|
404 | |
---|
405 | for (i = 0; i<n; i++) |
---|
406 | { |
---|
407 | term = it->Next(); |
---|
408 | if (isSparse) |
---|
409 | { |
---|
410 | if (coeff->IsDataOk(ExpCoeff(term)) == false || |
---|
411 | ExpValue(term) < 0) return false; |
---|
412 | } |
---|
413 | else |
---|
414 | { |
---|
415 | if (coeff->IsDataOk(term) == false) return false; |
---|
416 | } |
---|
417 | } |
---|
418 | return true; |
---|
419 | } |
---|
420 | |
---|
421 | |
---|
422 | ///////////////////////////////////////////////////////////////////// |
---|
423 | /// |
---|
424 | /// Multivariate Polys |
---|
425 | /// |
---|
426 | ///////////////////////////////////////////////////////////////////// |
---|
427 | bool GP_MvPoly_t::IsMvPolySpecOk() |
---|
428 | { |
---|
429 | if (NumberOfVars() <= 0) |
---|
430 | return false; |
---|
431 | |
---|
432 | switch(MvPolyType()) |
---|
433 | { |
---|
434 | case GP_DistMvPolyType: |
---|
435 | return DistMvPoly() != NULL && DistMvPoly()->IsDistMvPolySpecOk(); |
---|
436 | |
---|
437 | case GP_RecMvPolyType: |
---|
438 | return RecMvPoly() != NULL && RecMvPoly()->IsRecMvPolySpecOk(); |
---|
439 | |
---|
440 | default: |
---|
441 | return false; |
---|
442 | } |
---|
443 | } |
---|
444 | bool GP_MvPoly_t::IsMvPolyDataOk(const void* data) |
---|
445 | { |
---|
446 | switch(MvPolyType()) |
---|
447 | { |
---|
448 | case GP_DistMvPolyType: |
---|
449 | return DistMvPoly() != NULL && DistMvPoly()->IsDistMvPolyDataOk(data); |
---|
450 | |
---|
451 | case GP_RecMvPolyType: |
---|
452 | return RecMvPoly() != NULL && RecMvPoly()->IsRecMvPolyDataOk(data); |
---|
453 | |
---|
454 | default: |
---|
455 | return false; |
---|
456 | } |
---|
457 | } |
---|
458 | |
---|
459 | |
---|
460 | ///////////////////////////////////////////////////////////////////// |
---|
461 | /// |
---|
462 | /// Distributed multivariate polys |
---|
463 | /// |
---|
464 | ///////////////////////////////////////////////////////////////////// |
---|
465 | bool GP_DistMvPoly_t::IsDistMvPolySpecOk() |
---|
466 | { |
---|
467 | |
---|
468 | if (DistMvPolyType() == GP_UnknownDistMvPolyType) return false; |
---|
469 | |
---|
470 | GP_Ordering_pt has_ordering = HasOrdering(); |
---|
471 | GP_Ordering_pt should_ordering = ShouldHaveOrdering(); |
---|
472 | |
---|
473 | return |
---|
474 | (has_ordering == NULL || (has_ordering->IsOk(NumberOfVars()))) && |
---|
475 | (should_ordering == NULL || (should_ordering->IsOk(NumberOfVars()))); |
---|
476 | } |
---|
477 | bool GP_DistMvPoly_t::IsDistMvPolyDataOk(const void* data) |
---|
478 | { |
---|
479 | GP_DistMvPolyType_t type = DistMvPolyType(); |
---|
480 | GP_Iterator_pt monoms = MonomIterator(data); |
---|
481 | GP_pt coeffs = Coeffs(); |
---|
482 | void* monom; |
---|
483 | long i, n,j, nvars = NumberOfVars(); |
---|
484 | GP_Iterator_pt expvector = NULL; |
---|
485 | |
---|
486 | if (type == GP_UnknownDistMvPolyType) return false; |
---|
487 | if (monoms == NULL) return false; |
---|
488 | if (nvars <= 0) return false; |
---|
489 | |
---|
490 | n = monoms->N(); |
---|
491 | |
---|
492 | if (n < 0) return false; |
---|
493 | |
---|
494 | for (i=0; i<n; i++) |
---|
495 | { |
---|
496 | monom = monoms->Next(); |
---|
497 | if (coeffs->IsDataOk(Coeff(monom)) == false) return false; |
---|
498 | |
---|
499 | if (type == GP_SparseDistMvPolyType) |
---|
500 | { |
---|
501 | long m; |
---|
502 | void* exp; |
---|
503 | |
---|
504 | if (expvector == NULL) |
---|
505 | { |
---|
506 | expvector = ExpVectorIterator(monom); |
---|
507 | if (expvector == NULL) return false; |
---|
508 | } |
---|
509 | else expvector->Reset(monom); |
---|
510 | |
---|
511 | m = expvector->N(); |
---|
512 | if (m < 0) return false; |
---|
513 | |
---|
514 | for (j = 0; j < m; j++) |
---|
515 | { |
---|
516 | exp = expvector->Next(); |
---|
517 | if (ExpValue(exp) < 0 || ExpNumber(exp) < 0 || ExpNumber(exp) >= nvars) |
---|
518 | return false; |
---|
519 | } |
---|
520 | } |
---|
521 | else |
---|
522 | { |
---|
523 | int* evector = NULL; |
---|
524 | ExpVector(monom, evector); |
---|
525 | |
---|
526 | if (evector == NULL) return NULL; |
---|
527 | for (j = 0; j<nvars; j++) |
---|
528 | { |
---|
529 | if (evector[j] < 0) return false; |
---|
530 | } |
---|
531 | } |
---|
532 | } |
---|
533 | return true; |
---|
534 | } |
---|
535 | |
---|
536 | |
---|
537 | ///////////////////////////////////////////////////////////////////// |
---|
538 | /// |
---|
539 | /// recursive multivariate polys |
---|
540 | /// |
---|
541 | ///////////////////////////////////////////////////////////////////// |
---|
542 | bool GP_RecMvPoly_t::IsRecMvPolySpecOk() |
---|
543 | { |
---|
544 | return true; |
---|
545 | } |
---|
546 | bool GP_RecMvPoly_t::IsRecMvPolyDataOk(const void* data) |
---|
547 | { |
---|
548 | if (IsNull(data)) return true; |
---|
549 | if (IsCoeff(data)) return Coeffs()->IsDataOk(data); |
---|
550 | |
---|
551 | return ( |
---|
552 | Variable(data) >= 0 && Variable(data) < NumberOfVars() && |
---|
553 | Exponent(data) > 0 && |
---|
554 | IsRecMvPolyDataOk(AddSubPoly(data)) && |
---|
555 | IsRecMvPolyDataOk(MultSubPoly(data)) |
---|
556 | ); |
---|
557 | } |
---|
558 | |
---|
559 | |
---|
560 | ///////////////////////////////////////////////////////////////////// |
---|
561 | /// |
---|
562 | /// Orderings |
---|
563 | /// |
---|
564 | ///////////////////////////////////////////////////////////////////// |
---|
565 | bool GP_Ordering_t::IsBlockOrderingOk(const void* block_ordering) |
---|
566 | { |
---|
567 | long low, high; |
---|
568 | |
---|
569 | BlockLimits(block_ordering, low, high); |
---|
570 | |
---|
571 | if (low < 0 || high < low) return false; |
---|
572 | |
---|
573 | switch (OrderingType(block_ordering)) |
---|
574 | { |
---|
575 | case GP_UnknownOrdering: |
---|
576 | case GP_ProductOrdering: |
---|
577 | return false; |
---|
578 | |
---|
579 | case GP_MatrixOrdering: |
---|
580 | { |
---|
581 | GP_Iterator_pt iter = WeightsIterator(); |
---|
582 | if (iter == NULL) return false; |
---|
583 | if (iter->N() != (high - low)*(high - low)) return false; |
---|
584 | return true; |
---|
585 | } |
---|
586 | |
---|
587 | default: |
---|
588 | return true; |
---|
589 | } |
---|
590 | } |
---|
591 | |
---|
592 | bool GP_Ordering_t::IsOk(const long nvars) |
---|
593 | { |
---|
594 | if (nvars <= 0) return false; |
---|
595 | |
---|
596 | switch(OrderingType()) |
---|
597 | { |
---|
598 | case GP_UnknownOrdering: |
---|
599 | return false; |
---|
600 | |
---|
601 | case GP_VectorOrdering: |
---|
602 | case GP_IncrCompOrdering: |
---|
603 | case GP_DecrCompOrdering: |
---|
604 | // incomplete orderings are no good |
---|
605 | return false; |
---|
606 | |
---|
607 | case GP_MatrixOrdering: |
---|
608 | { |
---|
609 | GP_Iterator_pt iter = WeightsIterator(); |
---|
610 | if (iter == NULL) return false; |
---|
611 | if (iter->N() != nvars*nvars) return false; |
---|
612 | return true; |
---|
613 | } |
---|
614 | |
---|
615 | case GP_ProductOrdering: |
---|
616 | { |
---|
617 | GP_Iterator_pt iter = BlockOrderingIterator(); |
---|
618 | long i, n = 0, low, high; |
---|
619 | bool found_zero=false, found_nvars=false; |
---|
620 | void* block_ordering; |
---|
621 | |
---|
622 | if (iter !=NULL) |
---|
623 | { |
---|
624 | for (i=0, n = iter->N(); i<n; i++) |
---|
625 | { |
---|
626 | block_ordering = iter->Next(); |
---|
627 | if (! IsBlockOrderingOk(block_ordering)) return false; |
---|
628 | BlockLimits(block_ordering, low, high); |
---|
629 | |
---|
630 | if (low < 0 || high >= nvars) return false; |
---|
631 | |
---|
632 | // Hmm.. we should check fo complete coverage of all |
---|
633 | // variables However, we would need to allocate memory to do |
---|
634 | // so, and I'd like to avoid this here |
---|
635 | if (low == 0) found_zero = true; |
---|
636 | if (high == nvars -1) found_nvars = true; |
---|
637 | } |
---|
638 | } |
---|
639 | return (found_zero && found_nvars); |
---|
640 | } |
---|
641 | |
---|
642 | default: |
---|
643 | return true; |
---|
644 | } |
---|
645 | } |
---|
646 | |
---|
647 | |
---|