Skip to content

Commit

Permalink
* Don't try to get an argument for boolean args
Browse files Browse the repository at this point in the history
* Add RING_GUESS to ring-types
* Add logic to guess ring-type based on file-format
  • Loading branch information
hovinen committed Jun 22, 2011
1 parent b08dad9 commit 7e45439
Showing 4 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion util/equal.C
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ int check_equal (const Ring &R, const char *input1, FileFormatTag input1_format,
int main (int argc, char **argv)
{
static const char *ringString = "modular";
static integer p = 101;
static integer p = 65521;
static bool floatingPoint = false;
static const char *input1FileFormat = "guess";
static const char *input2FileFormat = "guess";
38 changes: 22 additions & 16 deletions util/row-echelon-form.C
Original file line number Diff line number Diff line change
@@ -32,18 +32,6 @@ int row_echelon_form (const Ring &R, const char *input, FileFormatTag input_form

commentator.start ("Converting matrix to row-echelon-form", __FUNCTION__);

if (output_format == FORMAT_DETECT) {
output_format = guess_format_tag (output);

if (output_format == FORMAT_UNKNOWN) {
commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR)
<< "Could not guess output file-format" << std::endl;
commentator.stop ("error");
} else
commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_DESCRIPTION)
<< "Writing output in " << format_names[output_format] << " format" << std::endl;
}

Matrix A;

commentator.start ("Reading input-matrix");
@@ -88,7 +76,9 @@ int row_echelon_form (const Ring &R, const char *input, FileFormatTag input_form

EF.RowEchelonForm (A, reduced, method);

commentator.start ("Writing output-matrix");
std::ostringstream str;
str << "Writing output-matrix (format " << format_names[output_format] << ")" << std::ends;
commentator.start (str.str ().c_str ());

std::ofstream ofile (output);

@@ -208,8 +198,8 @@ int run_row_echelon_form (const Ring &R, const char *method_string, const char *
int main (int argc, char **argv)
{
static bool reduced = false;
static const char *ringString = "modular";
static integer p = 101;
static const char *ringString = "guess";
static integer p = 65521;
static bool floatingPoint = false;
static const char *methodString = "f4";
static const char *inputFileFormat = "guess";
@@ -220,7 +210,7 @@ int main (int argc, char **argv)

static Argument args[] = {
{ 'r', "-r", "Compute the reduced row-echelon form", TYPE_NONE, &reduced },
{ 'k', "-k", "Ring over which to compute ('gf2', 'modular')", TYPE_STRING, &ringString },
{ 'k', "-k", "Ring over which to compute ('guess', 'gf2', 'modular')", TYPE_STRING, &ringString },
{ 'p', "-p", "Modulus of ring, when ring is 'modular'", TYPE_INT, &p },
{ 'f', "-f", "Compute using floating point, when ring is 'modular'", TYPE_NONE, &floatingPoint },
{ 'm', "-m", "Method to be used ('standard', 'afast', 'm4ri', or 'f4')", TYPE_STRING, &methodString },
@@ -252,8 +242,24 @@ int main (int argc, char **argv)
return -1;
}

if (output_format == FORMAT_DETECT) {
output_format = guess_format_tag (output);

if (output_format == FORMAT_UNKNOWN) {
std::cerr << "Could not guess output file-format" << std::endl;
return -1;
}
}

RingType ring_type = get_ring_type (ringString);

if (ring_type == RING_GUESS) {
if (input_format == FORMAT_PNG || output_format == FORMAT_PNG)
ring_type = RING_GF2;
else
ring_type = RING_MODULAR;
}

if (ring_type == RING_GF2)
return run_row_echelon_form (GF2 (), methodString, matrixType, reduced, input, input_format, output, output_format);
else if (ring_type == RING_MODULAR) {
14 changes: 2 additions & 12 deletions util/support.C
Original file line number Diff line number Diff line change
@@ -133,18 +133,8 @@ void parseArguments (int argc, char **argv, Argument *args, const char *freeArgs
else if ((current = findArgument (args, argv[i][1])) != (Argument *) 0) {
switch (current->type) {
case TYPE_NONE:
if (argc == i+1 || (argv[i+1][0] == '-' && argv[i+1][1] != '\0')) {
// if at last argument, or next argument is a switch, set to true
*(bool *) current->data = true;
break;
}
*(bool *) current->data =
(argv[i+1][0] == '+'
|| argv[i+1][0] == 'Y'
|| argv[i+1][0] == 'y'
|| argv[i+1][0] == 'T'
|| argv[i+1][0] == 't') ;
i++;
// if at last argument, or next argument is a switch, set to true
*(bool *) current->data = true;
break;

case TYPE_INT:
4 changes: 3 additions & 1 deletion util/support.h
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ struct Argument

enum RingType
{
RING_UNKNOWN, RING_GF2, RING_MODULAR
RING_UNKNOWN, RING_GUESS, RING_GF2, RING_MODULAR
};

enum MatrixType
@@ -45,6 +45,8 @@ enum MatrixType

RingType get_ring_type (const char *str)
{
if (!strcmp (str, "guess"))
return RING_GUESS;
if (!strcmp (str, "gf2"))
return RING_GF2;
if (!strcmp (str, "modular"))

0 comments on commit 7e45439

Please sign in to comment.