Skip to content

Commit c012915

Browse files
authored
Merge pull request linbox-team#288 from linbox-team/zeromatrixminpoly
problem with zero sequence for minpoly/charpoly
2 parents 9226c46 + 564544c commit c012915

File tree

6 files changed

+50
-26
lines changed

6 files changed

+50
-26
lines changed

linbox/algorithms/bbcharpoly.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ namespace LinBox
204204
FM* depend = NULL;
205205
for (size_t j = 1; j <= exp[i]; ++j){
206206
IntPoly * tmp2 = new IntPoly(*tmp);
207-
// FieldPoly *tmp2p = new FieldPoly(tmp2->size());
208-
// typename IntPoly::template rebind<Field>() (*tmp2p, *tmp2, F);
207+
// FieldPoly *tmp2p = new FieldPoly(tmp2->size());
208+
// typename IntPoly::template rebind<Field>() (*tmp2p, *tmp2, F);
209209
FieldPoly *tmp2p = new FieldPoly(*tmp2, F);
210210

211211
FFM = new FM (tmp2p, tmp2, 0, depend);
@@ -223,8 +223,8 @@ namespace LinBox
223223
leadingBlocks.insert (std::pair<FM*,bool>(FFM,false));
224224
}
225225
else {
226-
// FieldPoly* fp=new FieldPoly(intFactors[i].size());
227-
// typename IntPoly::template rebind<Field>() (*fp, (intFactors[i]), F);
226+
// FieldPoly* fp=new FieldPoly(intFactors[i].size());
227+
// typename IntPoly::template rebind<Field>() (*fp, (intFactors[i]), F);
228228
IntPoly * ip=new IntPoly(intFactors[i]);
229229
FieldPoly* fp=new FieldPoly(intFactors[i], F);
230230

@@ -286,14 +286,14 @@ namespace LinBox
286286
/* Computation of the minimal polynomial */
287287
Polynomial minPoly(F);
288288
minpoly (minPoly, A, M);
289-
// PD.write(std::cerr<<"Minpoly = ",minPoly) << std::endl;
289+
//PD.write(std::cerr<<"Minpoly = ",minPoly) << std::endl;
290290

291291
if (minPoly.size() == n+1){
292292
commentator().stop ("done", NULL, "MbbCharpoly");
293293
return P = minPoly;
294294
}
295295

296-
296+
297297

298298
Polynomial charPoly (F);
299299

linbox/algorithms/blackbox-container-base.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// - wait : waits for the end of the current computation
3333
// ================================================================
3434

35-
35+
#include "linbox/solutions/constants.h"
3636
#include "linbox/vector/vector-domain.h"
3737

3838
namespace LinBox
@@ -157,11 +157,20 @@ namespace LinBox
157157
{
158158
casenumber = 1;
159159
u.resize (_BB->coldim ());
160-
for (long i = (long)u.size (); i--;)
161-
g.random (u[(size_t)i]);
162-
v.resize (_BB->rowdim ());
163-
return _VD.dot (_value, u, u);
164-
}
160+
v.resize (_BB->rowdim ());
161+
162+
size_t trials=0;
163+
do {
164+
for (long i = (long)this->u.size (); i--;)
165+
g.random (this->u[(size_t)i]);
166+
this->_VD.dot (this->_value, this->u, this->u);
167+
} while(_field->isZero(this->_value) && ++trials<= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE);
168+
169+
if (trials >= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE)
170+
std::cerr<<"ERROR in "<<__FILE__<<" at line "<<__LINE__<<" -> projection always auto-orthogonal after "<<LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE<<" attempts\n";;
171+
172+
return _value;
173+
}
165174

166175
/// User Left vectors, Zero Right vector
167176
template<class Vector>

linbox/algorithms/blackbox-container.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "linbox/randiter/archetype.h"
3434
#include "linbox/algorithms/blackbox-container-base.h"
3535
#include "linbox/util/timer.h"
36+
#include "linbox/solutions/constants.h"
3637

3738
namespace LinBox
3839
{
@@ -87,13 +88,23 @@ namespace LinBox
8788
{
8889
this->casenumber = 1;
8990
this->u.resize (this->_BB->coldim ());
90-
for (long i = (long)this->u.size (); i--;)
91-
g.random (this->u[(size_t)i]);
92-
this->w.resize (this->_BB->coldim ());
93-
for (long i = (long)this->w.size (); i--;)
94-
g.random (this->w[(size_t)i]);
95-
this->v.resize (this->_BB->rowdim ());
96-
this->_VD.dot (this->_value, this->u, this->w);
91+
this->w.resize (this->_BB->coldim ());
92+
this->v.resize (this->_BB->rowdim ());
93+
94+
size_t trials=0;
95+
do {
96+
for (long i = (long)this->u.size (); i--;)
97+
g.random (this->u[(size_t)i]);
98+
99+
for (long i = (long)this->w.size (); i--;)
100+
g.random (this->w[(size_t)i]);
101+
102+
this->_VD.dot (this->_value, this->u, this->w);
103+
} while(F.isZero(this->_value) && ++trials<= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE);
104+
105+
if (trials >= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE)
106+
std::cerr<<"ERROR in "<<__FILE__<<" at line "<<__LINE__<<" -> projection always orthogonal after "<<LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE<<" attempts\n";;
107+
97108
#ifdef INCLUDE_TIMING
98109
_applyTime = _dotTime = 0.0;
99110
#endif

linbox/algorithms/massey-domain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ namespace LinBox
348348

349349
commentator().stop ("done", NULL, "masseyd");
350350
// commentator().stop ("Done", "Done", "LinBox::MasseyDomain::massey");
351-
352351
return L;
353352
}
354353

@@ -398,7 +397,8 @@ namespace LinBox
398397
{
399398
long dp = massey (phi, full_poly);
400399
rank = (size_t) (v_degree(phi) - v_val (phi));
401-
400+
//std::cerr<<"dp="<<dp<<" rank="<<rank<<" -> "<<phi.size()<<" : "<<phi<<std::endl;
401+
402402
if (dp==0){// empty sequence, its minpoly is 1
403403
phi.resize(1);
404404
field().assign(phi[0],field().one);

linbox/algorithms/wiedemann.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace LinBox
129129
<< "Time required for LSR fix: " << WD.fixTime () << std::endl;
130130
#endif // INCLUDE_TIMING
131131
}
132-
132+
133133
commentator().stop ("done", NULL, "minpoly");
134134

135135
return P;

tests/test-regression.C

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ bool testDixonSmallFat() {
570570
return success = ZZ.areEqual(r[0], b[0]);
571571
}
572572

573-
bool testZeroMatrixCharPoly() {
573+
template<typename CMethod=Method::Blackbox>
574+
bool testZeroMatrixCharPoly(const CMethod& cMeth=CMethod()) {
574575
bool success;
575576
using Ring = Givaro::Modular<double>;
576577
using Matrix = SparseMatrix<Ring>;
@@ -581,7 +582,7 @@ bool testZeroMatrixCharPoly() {
581582

582583
PolynomialRing<Ring>::Element c_A, Ex;
583584

584-
charpoly(c_A, A);
585+
charpoly(c_A, A, RingCategories::ModularTag(), cMeth );
585586

586587
PolynomialRing<Ring> PZ(R,'X'); PZ.assign(Ex, Givaro::Degree(1), R.one);
587588

@@ -596,7 +597,7 @@ bool testZeroMatrixCharPoly() {
596597
}
597598
return false;
598599
} else
599-
if (writing) std::cout << "ZMCP: PASSED" << std::endl;
600+
if (writing) std::cout << "ZMCP" << cMeth.name() << cMeth.shapeFlags.flags << " : PASSED" << std::endl;
600601

601602
return success;
602603
}
@@ -675,7 +676,10 @@ int main (int argc, char **argv)
675676
pass &= testSparseDiagDet(46);
676677
pass &= testZeroDimensionalCharPoly ();
677678
pass &= testZeroDimensionalMinPoly ();
678-
pass &= testZeroMatrixCharPoly();
679+
pass &= testZeroMatrixCharPoly<>();
680+
pass &= testZeroMatrixCharPoly(Method::Blackbox(Shape::Symmetric));
681+
pass &= testZeroMatrixCharPoly(Method::DenseElimination());
682+
// pass &= testZeroMatrixCharPoly(Method::SparseElimination());
679683
pass &= testBigScalarCharPoly ();
680684
pass &= testLocalSmith ();
681685
pass &= testInconsistent<DenseMatrix<ZRingInts>> (Method::DenseElimination());

0 commit comments

Comments
 (0)