Added some utility functions (not yet needed)
This commit is contained in:
parent
7e80e5bc94
commit
7738781bb5
2 changed files with 34 additions and 0 deletions
|
@ -11,6 +11,7 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation 'org.ejml:ejml-all:0.41'
|
||||
implementation 'com.opencsv:opencsv:5.6'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||
}
|
||||
|
|
33
src/main/java/Utilities.java
Normal file
33
src/main/java/Utilities.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
import com.opencsv.CSVReader;
|
||||
import com.opencsv.exceptions.CsvValidationException;
|
||||
import org.ejml.simple.SimpleMatrix;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Utilities {
|
||||
public static SimpleMatrix ones(int rows, int columns) {
|
||||
SimpleMatrix mat = new SimpleMatrix(rows, columns);
|
||||
Arrays.fill(mat.getDDRM().data, 1);
|
||||
return mat;
|
||||
}
|
||||
|
||||
public static List<List<String>> readCSV(String filename) {
|
||||
List<List<String>> entries = new ArrayList<>();
|
||||
try (CSVReader csvReader = new CSVReader(new FileReader(filename))) {
|
||||
String[] values;
|
||||
while ((values = csvReader.readNext()) != null) {
|
||||
entries.add(Arrays.asList(values));
|
||||
}
|
||||
return entries;
|
||||
} catch (IOException e) {
|
||||
System.out.println(filename + " does not exist");
|
||||
} catch (CsvValidationException e) {
|
||||
System.out.println("Invalid line in " + filename);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue