-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcut_module.cpp
More file actions
62 lines (54 loc) · 2.21 KB
/
cut_module.cpp
File metadata and controls
62 lines (54 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <grlina/graded_linalg.hpp>
#include <iostream>
#include <filesystem>
using namespace graded_linalg;
void cut_presentation(std::filesystem::path input_path, std::filesystem::path output_path, double x_cutoff = 1.0, double y_cutoff = 1.0) {
R2GradedSparseMatrix<int> presentation = R2GradedSparseMatrix<int>(input_path.string());
presentation.bound_support(std::make_pair(x_cutoff, y_cutoff));
std::ofstream output_file(output_path);
if (!output_file.is_open()) {
std::cerr << "Error: Unable to open output file " << output_path << std::endl;
return;
} else {
presentation.to_stream(output_file);
output_file.close();
std::cout << "Restricted module with cutoffs " << x_cutoff << " and " << y_cutoff << " and saved to: " << output_path << std::endl;
}
}
int main(int argc, char** argv) {
std::string filepath;
double x_cutoff = 1.0; // default value
double y_cutoff = 1.0; // default value
std::filesystem::path output_path;
std::string suffix;
std::filesystem::path input_path;
if (argc < 4 || argc > 5) {
std::cerr << "Usage: " << argv[0] << " <file_path> [x cutoff] [y cutoff] [output_path] \n";
std::cerr << " output_path = optional output file path." << std::endl;
return 1;
} else {
filepath = argv[1];
input_path = std::filesystem::path(filepath);
try {
x_cutoff = std::stod(argv[2]);
y_cutoff = std::stod(argv[3]);
} catch (const std::exception& e) {
std::cerr << "Error: Invalid double argument" << std::endl;
return 1;
}
}
if(argc >= 5) {
try {
output_path = std::filesystem::path(argv[4]);
} catch (const std::exception& e) {
std::cerr << "Error: Invalid output path argument" << std::endl;
return 1;
}
} else {
std::string suffix = "_cut_after_" + std::to_string(x_cutoff) + "_" + std::to_string(y_cutoff);
std::string modified_path = insert_suffix_before_extension(filepath, suffix);
output_path = std::filesystem::path(modified_path);
}
cut_presentation(input_path, output_path, x_cutoff, y_cutoff);
return 0;
}