Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] MatrixVectorFloat4 set/get accesses fixed #325

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class VectorFloat4 implements TornadoCollectionInterface<FloatBuffe
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;
/**
* number of elements in the storage.
*/
Expand All @@ -44,7 +44,7 @@ public final class VectorFloat4 implements TornadoCollectionInterface<FloatBuffe
* @param array
* Array to be stored
*/
protected VectorFloat4(int numElements, FloatArray array) {
private VectorFloat4(int numElements, FloatArray array) {
this.numElements = numElements;
this.storage = array;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public final class ImageByte3 implements TornadoImagesInterface<ByteBuffer> {
/**
* backing array.
*/
protected final ByteArray storage;
private final ByteArray storage;
/**
* Number of rows.
*/
protected final int Y;
private final int Y;
/**
* Number of columns.
*/
protected final int X;
private final int X;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public final class ImageByte4 implements TornadoImagesInterface<ByteBuffer> {
/**
* backing array.
*/
protected final ByteArray storage;
private final ByteArray storage;
/**
* Number of rows.
*/
protected final int Y;
private final int Y;
/**
* Number of columns.
*/
protected final int X;
private final int X;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public final class ImageFloat implements TornadoImagesInterface<FloatBuffer> {
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;
/**
* Number of rows.
*/
protected final int Y;
private final int Y;
/**
* Number of columns.
*/
protected final int X;
private final int X;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public final class ImageFloat3 implements TornadoImagesInterface<FloatBuffer> {
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;
/**
* Number of rows.
*/
protected final int Y;
private final int Y;
/**
* Number of columns.
*/
protected final int X;
private final int X;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public final class ImageFloat4 implements TornadoImagesInterface<FloatBuffer> {
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;
/**
* Number of rows.
*/
protected final int Y;
private final int Y;
/**
* Number of columns.
*/
protected final int X;
private final int X;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public final class ImageFloat8 implements TornadoImagesInterface<FloatBuffer> {
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;
/**
* Number of rows.
*/
protected final int Y;
private final int Y;
/**
* Number of columns.
*/
protected final int X;
private final int X;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class Matrix2DDouble extends Matrix2DType implements TornadoMatrixI
/**
* backing array.
*/
protected final DoubleArray storage;
private final DoubleArray storage;

/**
* number of elements in the storage.
Expand Down Expand Up @@ -103,23 +103,22 @@ public void set(int i, int j, double value) {
}

public VectorDouble row(int row) {
int index = toRowMajor(row, 0, COLUMNS);
int from = index;
int to = getFinalIndexOfRange(index);
int size = to - from;
int baseIndex = toRowMajor(row, 0, COLUMNS);
int to = getFinalIndexOfRange(baseIndex);
int size = to - baseIndex;
DoubleArray f = new DoubleArray(size);
int j = 0;
for (int i = from; i < to; i++, j++) {
for (int i = baseIndex; i < to; i++, j++) {
f.set(j, storage.get(i));
}
return new VectorDouble(COLUMNS, f);
}

public VectorDouble column(int col) {
int index = StorageFormats.toRowMajor(0, col, COLUMNS);
int baseIndex = StorageFormats.toRowMajor(0, col, COLUMNS);
final VectorDouble v = new VectorDouble(ROWS);
for (int i = 0; i < ROWS; i++) {
v.set(i, storage.get(index + (i * COLUMNS)));
v.set(i, storage.get(baseIndex + (i * COLUMNS)));
}
return v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class Matrix2DFloat extends Matrix2DType implements TornadoMatrixIn
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;

/**
* number of elements in the storage.
Expand Down Expand Up @@ -110,13 +110,12 @@ public void set(int i, int j, float value) {
}

public VectorFloat row(int row) {
int index = toRowMajor(row, 0, COLUMNS);
int from = index;
int to = getFinalIndexOfRange(index);
int size = to - from;
int baseIndex = toRowMajor(row, 0, COLUMNS);
int to = getFinalIndexOfRange(baseIndex);
int size = to - baseIndex;
FloatArray f = new FloatArray(size);
int j = 0;
for (int i = from; i < to; i++) {
for (int i = baseIndex; i < to; i++) {
f.set(j, storage.get(i));
j++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class Matrix2DFloat4 extends Matrix2DType implements TornadoMatrixI
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
import uk.ac.manchester.tornado.api.types.utils.StorageFormats;

public final class Matrix2DInt extends Matrix2DType implements TornadoMatrixInterface<IntBuffer> {

/**
* backing array.
*/
protected final IntArray storage;
private final IntArray storage;

/**
* number of elements in the storage.
Expand Down Expand Up @@ -109,13 +110,12 @@ public void set(int i, int j, int value) {
}

public VectorInt row(int row) {
int index = toRowMajor(row, 0, COLUMNS);
int from = index;
int to = getFinalIndexOfRange(index);
int size = to - from;
int baseIndex = toRowMajor(row, 0, COLUMNS);
int to = getFinalIndexOfRange(baseIndex);
int size = to - baseIndex;
IntArray f = new IntArray(size);
int j = 0;
for (int i = from; i < to; i++) {
for (int i = baseIndex; i < to; i++) {
f.set(j, storage.get(i));
j++;
}
Expand Down Expand Up @@ -157,20 +157,6 @@ public void multiply(Matrix2DInt a, Matrix2DInt b) {
}
}

public void tmultiply(Matrix2DInt a, Matrix2DInt b) {
System.out.printf("tmult: M=%d (expect %d)\n", getNumRows(), a.getNumRows());
System.out.printf("tmult: N=%d (expect %d)\n", getNumColumns(), b.getNumRows());
for (int row = 0; row < getNumRows(); row++) {
for (int col = 0; col < b.getNumRows(); col++) {
int sum = 0;
for (int k = 0; k < b.getNumColumns(); k++) {
sum += a.get(row, k) * b.get(col, k);
}
set(row, col, sum);
}
}
}

public Matrix2DInt duplicate() {
Matrix2DInt matrix = new Matrix2DInt(ROWS, COLUMNS);
matrix.set(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class Matrix3DFloat extends Matrix3DType implements TornadoMatrixIn
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;

/**
* number of elements in the storage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public final class Matrix4x4Float implements TornadoMatrixInterface<FloatBuffer>
/**
* Number of rows.
*/
protected static final int ROWS = 4;
private static final int ROWS = 4;
/**
* Number of columns.
*/
protected static final int COLUMNS = 4;
private static final int COLUMNS = 4;
/**
* number of elements in the storage.
*/
private static final int NUM_ELEMENTS = 16;
/**
* backing array.
*/
protected final FloatArray storage;
private final FloatArray storage;

public Matrix4x4Float() {
this(new FloatArray(NUM_ELEMENTS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private StorageFormats() {
* length of a column
* @return int
*/
@Deprecated
public static int toColumnMajor(int i, int j, int ld) {
return (j * ld) + i;
}
Expand All @@ -49,16 +50,16 @@ public static int toColumnMajor(int i, int j, int ld) {
* row index
* @param j
* column index
* @param yMax
* @param numColumns
* length of a row
* @return int
*/
public static int toRowMajor(int i, int j, int yMax) {
return (i * yMax) + j;
public static int toRowMajor(int i, int j, int numColumns) {
return (i * numColumns) + j;
}

public static int toRowMajorVector(int i, int j, int numColumns, int vectorElements) {
return (i * numColumns * vectorElements) + j;
return ((i * numColumns) + j) * vectorElements;
}

public static int toRowMajor3D(int i, int j, int k, int zMax, int yMax) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ public final class VolumeShort2 implements TornadoVolumesInterface<ShortBuffer>
/**
* backing array.
*/
protected final ShortArray storage;
private final ShortArray storage;
/**
* Size in Y dimension.
*/
protected final int Y;
private final int Y;
/**
* Size in X dimension.
*/
protected final int X;
private final int X;
/**
* Size in Y dimension.
*/
protected final int Z;
private final int Z;
/**
* number of elements in the storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
return true;
}
});

}

static void registerParameterPlugins(Plugins plugins) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public class MatrixVector {
public static final int MAX_ITERATIONS = 100;

private static void computeMatrixVector(Matrix2DFloat matrix, VectorFloat vector, VectorFloat output) {
for (@Parallel int i = 0; i < vector.size(); i++) {
for (@Parallel int i = 0; i < matrix.getNumRows(); i++) {
float sum = 0.0f;
for (int j = 0; j < matrix.getNumColumns(); j++) {
sum += vector.get(i) * matrix.get(i, i);
sum += matrix.get(i, j) * vector.get(j);
}
output.set(i, sum);
}
Expand All @@ -77,7 +77,8 @@ public static void main(String[] args) {
try {
size = Integer.parseInt(args[0]);
} catch (NumberFormatException numberFormatException) {
size = 8192;
numberFormatException.printStackTrace();
throw new NullPointerException();
}
}

Expand Down
Loading