Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Baunsgaard committed Aug 15, 2023
1 parent f5af021 commit f15f596
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ public IDictionary binOpRightWithReference(BinaryOperator op, double[] v, IColIn

/**
* Returns a deep clone of the dictionary.
*
* @return A deep clone
*/
public IDictionary clone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,44 @@ public ICLAScheme update(MatrixBlock data) {
return update(data, getColIndices());
}


@Override
public ICLAScheme updateSparse(MatrixBlock data) {
// fallback to default
return updateSparse(data, getColIndices());
}

@Override
public ICLAScheme updateDense(MatrixBlock data) {
// fallback to default
return updateDense(data, getColIndices());
}

@Override
public ICLAScheme updateGeneric(MatrixBlock data) {
// fallback to default
return updateGeneric(data, getColIndices());
}


@Override
public ICLAScheme updateSparse(MatrixBlock data, IColIndex columns) {
// fallback to default
return update(data, columns);
}

@Override
public ICLAScheme updateDense(MatrixBlock data, IColIndex columns) {
// fallback to default
return update(data, columns);
}

@Override
public ICLAScheme updateGeneric(MatrixBlock data, IColIndex columns) {
// fallback to default
return update(data, columns);
}

protected final void validate(MatrixBlock data, IColIndex columns) throws IllegalArgumentException {
if(columns.size() != cols.size())
throw new IllegalArgumentException(
Expand All @@ -54,4 +92,6 @@ protected final void validate(MatrixBlock data, IColIndex columns) throws Illega
throw new IllegalArgumentException("Invalid columns to encode with max col:" + nCol+ " list of columns: "+ columns);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public ICLAScheme get(int i) {
*/
public CompressedMatrixBlock encode(MatrixBlock mb) {
if(mb instanceof CompressedMatrixBlock)
throw new NotImplementedException("Not implemented schema encode/apply on an already compressed MatrixBlock");
throw new NotImplementedException(
"Not implemented schema encode/apply on an already compressed MatrixBlock");

List<AColGroup> ret = new ArrayList<>(encodings.length);

Expand Down Expand Up @@ -116,7 +117,8 @@ public CompressedMatrixBlock encode(MatrixBlock mb, int k) {
*/
public CompressionScheme update(MatrixBlock mb) {
if(mb instanceof CompressedMatrixBlock)
throw new NotImplementedException("Not implemented schema encode/apply on an already compressed MatrixBlock");
throw new NotImplementedException(
"Not implemented schema encode/apply on an already compressed MatrixBlock");

for(int i = 0; i < encodings.length; i++)
encodings[i] = encodings[i].update(mb);
Expand Down Expand Up @@ -182,18 +184,22 @@ public static CompressionScheme getScheme(CompressedMatrixBlock cmb) {
public CompressedMatrixBlock updateAndEncode(MatrixBlock mb, int k) {
if(k == 1)
return updateAndEncode(mb);

final ExecutorService pool = CommonThreadPool.get(k);
try {

final int nCol = mb.getNumColumns();
AColGroup[] ret = new AColGroup[encodings.length];
List<UpdateAndEncodeTask> tasks = new ArrayList<>();
for(int i = 0; i < encodings.length; i++)
tasks.add(new UpdateAndEncodeTask(i, encodings[i], mb));
// int taskSize = Math.max(1, encodings.length / (4 * k));
int taskSize = 1;
for(int i = 0; i < encodings.length; i += taskSize)
tasks.add(new UpdateAndEncodeTask(i, Math.min(encodings.length, i + taskSize), ret, mb));

List<AColGroup> ret = new ArrayList<>(encodings.length);
for(Future<AColGroup> t : pool.invokeAll(tasks))
ret.add(t.get());
for(Future<Object> t : pool.invokeAll(tasks))
t.get();

return new CompressedMatrixBlock(mb.getNumRows(), mb.getNumColumns(), mb.getNonZeros(), false, ret);
List<AColGroup> retA = new ArrayList<>(Arrays.asList(ret));
return new CompressedMatrixBlock(mb.getNumRows(), nCol, mb.getNonZeros(), false, retA);

}
catch(Exception e) {
Expand All @@ -206,7 +212,8 @@ public CompressedMatrixBlock updateAndEncode(MatrixBlock mb, int k) {

public CompressedMatrixBlock updateAndEncode(MatrixBlock mb) {
if(mb instanceof CompressedMatrixBlock)
throw new NotImplementedException("Not implemented schema encode/apply on an already compressed MatrixBlock");
throw new NotImplementedException(
"Not implemented schema encode/apply on an already compressed MatrixBlock");

List<AColGroup> ret = new ArrayList<>(encodings.length);

Expand Down Expand Up @@ -258,21 +265,31 @@ public ICLAScheme call() throws Exception {
}
}

protected class UpdateAndEncodeTask implements Callable<AColGroup> {
protected class UpdateAndEncodeTask implements Callable<Object> {
final int i;
final ICLAScheme enc;
final int e;
final MatrixBlock mb;
final AColGroup[] ret;

protected UpdateAndEncodeTask(int i, ICLAScheme enc, MatrixBlock mb) {
protected UpdateAndEncodeTask(int i, int e, AColGroup[] ret, MatrixBlock mb) {
this.i = i;
this.enc = enc;
this.e = e;
this.mb = mb;
this.ret = ret;
}

@Override
public AColGroup call() throws Exception {
encodings[i] = enc.update(mb);
return enc.encode(mb);
public Object call() throws Exception {
final boolean dense = mb.getDenseBlock().isContiguous();

for(int j = i; j < e; j++) {
if(dense)
encodings[j] = encodings[j].updateDense(mb);
else
encodings[j] = encodings[j].update(mb);
ret[j] = encodings[j].encode(mb);
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,51 @@ protected final Object getMap() {
@Override
public ICLAScheme update(MatrixBlock data, IColIndex columns) {
validate(data, columns);
final int col = columns.get(0);
if(data.isEmpty())
map.increment(0.0, data.getNumRows());
else if(data.isInSparseFormat())
updateSparse(data, col);
updateSparse(data, columns);
else if(data.getDenseBlock().isContiguous())
updateDense(data, col);
updateDense(data, columns);
else
updateGeneric(data, col);
updateGeneric(data, columns);

return this;
}

private void updateSparse(MatrixBlock data, int col) {
@Override
public ICLAScheme updateSparse(MatrixBlock data, IColIndex columns) {
final int col = columns.get(0);
final int nRow = data.getNumRows();
final SparseBlock sb = data.getSparseBlock();
for(int i = 0; i < nRow; i++)
map.increment(sb.get(i, col));
return this;
}

private void updateDense(MatrixBlock data, int col) {
@Override
public ICLAScheme updateDense(MatrixBlock data, IColIndex columns) {
final int col = columns.get(0);
final int nRow = data.getNumRows();
final double[] vals = data.getDenseBlockValues();
final int nCol = data.getNumColumns();
final int max = nRow * nCol; // guaranteed lower than intmax.
for(int off = col; off < max; off += nCol)
map.increment(vals[off]);

return this;
}

private void updateGeneric(MatrixBlock data, int col) {
@Override
public ICLAScheme updateGeneric(MatrixBlock data, IColIndex columns) {
final int col = columns.get(0);
final int nRow = data.getNumRows();
final DenseBlock db = data.getDenseBlock();
for(int i = 0; i < nRow; i++) {
final double[] c = db.values(i);
final int off = db.pos(i) + col;
map.increment(c[off]);
}
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public interface ICLAScheme {

/**
* Encode the given matrix block into the scheme provided in the instance.
*
*
* The method is unsafe in the sense that if the encoding scheme does not fit, there is no guarantee that an error is
* thrown. To guarantee the encoding scheme, first use update on the matrix block and used the returned scheme to
*
* The method is unsafe in the sense that if the encoding scheme does not fit, there is no guarantee that an error
* is thrown. To guarantee the encoding scheme, first use update on the matrix block and used the returned scheme to
* ensure consistency.
*
* @param data The data to encode
Expand All @@ -59,8 +59,8 @@ public interface ICLAScheme {
/**
* Encode a given matrix block into the scheme provided in the instance but overwrite what columns to use.
*
* The method is unsafe in the sense that if the encoding scheme does not fit, there is no guarantee that an error is
* thrown. To guarantee the encoding scheme, first use update on the matrix block and used the returned scheme to
* The method is unsafe in the sense that if the encoding scheme does not fit, there is no guarantee that an error
* is thrown. To guarantee the encoding scheme, first use update on the matrix block and used the returned scheme to
* ensure consistency.
*
* @param data The data to encode
Expand All @@ -75,7 +75,7 @@ public interface ICLAScheme {
* Update the encoding scheme to enable compression of the given data.
*
* @param data The data to update into the scheme
* @return A updated scheme
* @return A updated scheme
*/
public ICLAScheme update(MatrixBlock data);

Expand All @@ -84,8 +84,20 @@ public interface ICLAScheme {
*
* @param data The data to update into the scheme
* @param columns The columns to extract the data from
* @return A updated scheme
* @return A updated scheme
*/
public ICLAScheme update(MatrixBlock data, IColIndex columns);

public ICLAScheme updateSparse(MatrixBlock sparseBlock);

public ICLAScheme updateDense(MatrixBlock denseBlock);

public ICLAScheme updateGeneric(MatrixBlock largeDenseBlock);

public ICLAScheme updateSparse(MatrixBlock sparseBlock, IColIndex columns);

public ICLAScheme updateDense(MatrixBlock denseBlock, IColIndex columns);

public ICLAScheme updateGeneric(MatrixBlock largeDenseBlock, IColIndex columns);

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ else if(!(src instanceof CompressedMatrixBlock))
private void writeSingleBlock(MatrixBlock b, int k) throws IOException {
Writer w = getWriter(fname);
MatrixIndexes idx = new MatrixIndexes(1, 1);
MatrixBlock mc = CompressedMatrixBlockFactory.compress(b, k).getLeft();
w.append(idx, new CompressedWriteBlock(mc));
if(!(b instanceof CompressedMatrixBlock))
b = CompressedMatrixBlockFactory.compress(b, k).getLeft();
w.append(idx, new CompressedWriteBlock(b));
IOUtilFunctions.closeSilently(w);
cleanup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static SeparatedGroups split(List<AColGroup> gs) {
* Combine a set of separated groups back together.
*
* @param s A Separated group of indexStructures
* @return
* @return A combined list of columngroups.
*/
public static List<AColGroup> combine(SeparatedGroups s) {
throw new NotImplementedException();
Expand Down

0 comments on commit f15f596

Please sign in to comment.