Skip to content
Snippets Groups Projects
Commit 95244e73 authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Improvements in QCMPCache report.

parent 54a9e991
No related branches found
No related tags found
No related merge requests found
...@@ -11,4 +11,6 @@ public interface ICacheFile { ...@@ -11,4 +11,6 @@ public interface ICacheFile {
void readFromStream(DataInputStream inputStream) throws IOException; void readFromStream(DataInputStream inputStream) throws IOException;
CacheFileHeader getHeader(); CacheFileHeader getHeader();
void report(StringBuilder builder);
} }
...@@ -268,12 +268,22 @@ public class QuantizationCacheManager { ...@@ -268,12 +268,22 @@ public class QuantizationCacheManager {
} }
private static ICacheFile getCacheFile(final QuantizationType qt) {
if (qt.isOneOf(QuantizationType.Vector1D, QuantizationType.Vector2D, QuantizationType.Vector3D))
return new VQCacheFile();
else if (qt == QuantizationType.Scalar)
return new SQCacheFile();
assert (false) : "Invalid quantization type.";
return null;
}
/** /**
* Inspect cache file specified by the path. * Inspect cache file specified by the path.
* *
* @param path Path to cache file. * @param path Path to cache file.
*/ */
public static void inspectCacheFile(final String path) { public static void inspectCacheFile(final String path, final boolean verbose) {
CacheFileHeader header = null; CacheFileHeader header = null;
long fileSize; long fileSize;
try (FileInputStream fis = new FileInputStream(path); try (FileInputStream fis = new FileInputStream(path);
...@@ -288,15 +298,29 @@ public class QuantizationCacheManager { ...@@ -288,15 +298,29 @@ public class QuantizationCacheManager {
StringBuilder reportBuilder = new StringBuilder(); StringBuilder reportBuilder = new StringBuilder();
final long expectedFileSize = header.getExpectedFileSize(); final long expectedFileSize = header.getExpectedFileSize();
if (expectedFileSize == fileSize) { if (expectedFileSize == fileSize) {
reportBuilder.append("\u001B[32mCache file is VALID. ").append(fileSize).append(" bytes\u001B[0m\n "); reportBuilder.append("\u001B[32mCache file is VALID ").append(fileSize).append(" bytes\u001B[0m\n");
} else { } else {
reportBuilder.append("\u001B[31mCache file is INVALID.\u001B[0m\n\t") reportBuilder.append("\u001B[31mCache file is INVALID.\u001B[0m\n\t")
.append(fileSize).append(" bytes instead of expected ") .append(fileSize).append(" bytes instead of expected ")
.append(expectedFileSize).append(" bytes.\n"); .append(expectedFileSize).append(" bytes.\n");
} }
header.report(reportBuilder); header.report(reportBuilder);
if (verbose) {
ICacheFile cacheFile = getCacheFile(header.getQuantizationType());
assert (cacheFile != null);
try (FileInputStream fis = new FileInputStream(path);
DataInputStream dis = new DataInputStream(fis)) {
cacheFile.readFromStream(dis);
} catch (Exception e) {
reportBuilder.append(e.getMessage());
}
cacheFile.report(reportBuilder);
}
System.out.println(reportBuilder); System.out.println(reportBuilder);
} }
} }
...@@ -5,6 +5,8 @@ import azgracompress.quantization.scalar.SQCodebook; ...@@ -5,6 +5,8 @@ import azgracompress.quantization.scalar.SQCodebook;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
public class SQCacheFile implements ICacheFile { public class SQCacheFile implements ICacheFile {
private CacheFileHeader header; private CacheFileHeader header;
...@@ -57,4 +59,17 @@ public class SQCacheFile implements ICacheFile { ...@@ -57,4 +59,17 @@ public class SQCacheFile implements ICacheFile {
public SQCodebook getCodebook() { public SQCodebook getCodebook() {
return codebook; return codebook;
} }
@Override
public void report(StringBuilder builder) {
final int[] centroids = codebook.getCentroids();
for (int i = 0; i < centroids.length; i++) {
if (i != centroids.length - 1) {
builder.append(centroids[i]).append(", ");
} else {
builder.append(centroids[i]).append('\n');
}
}
}
} }
...@@ -67,4 +67,13 @@ public class VQCacheFile implements ICacheFile { ...@@ -67,4 +67,13 @@ public class VQCacheFile implements ICacheFile {
public VQCodebook getCodebook() { public VQCodebook getCodebook() {
return codebook; return codebook;
} }
@Override
public void report(StringBuilder builder) {
final CodebookEntry[] vectors = codebook.getVectors();
for (int i = 0; i < vectors.length; i++) {
builder.append("- - - - - - - - - - - - - - - - - - - - - - - - -\n");
vectors[i].getVectorString(builder);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment