Skip to content

Commit

Permalink
Addinf code for matrix plus and minus.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmtiwari committed Feb 13, 2017
1 parent ad9ebf7 commit 315acd7
Showing 1 changed file with 157 additions and 0 deletions.
157 changes: 157 additions & 0 deletions src/java/boa/functions/BoaMatrixIntrinsics.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,163 @@ public static BoaTup[][] matrix(final BoaTup[] a, final long colsize) {
return result;
}

/**
* Returns the matrix version of an array. Only scalar values can be sorted.
* Values will be arranged in increasing order. (An optional comparison
* function, which takes two elements and returns int {-,0,+}, is accepted
* as a second argument, but it is curently ignored.)
*
* @param a
* An array of long
*
* @return A sorted copy of <em>a</em>
*/
@FunctionSpec(name = "multiply", returnType = "array of array of int", formalParameters = { "array of array of int", "array of array of int" })
public static long[][] multiply(final long[][] a, final long[][] b) {
double[][] a_double = new double[a.length][];
double[][] b_double = new double[b.length][];

for(int i = 0; i< a.length; i++){
a_double[i] = Doubles.toArray(Longs.asList(a[i]));
}

for(int i = 0; i< b.length; i++){
b_double[i] = Doubles.toArray(Longs.asList(b[i]));
}
Matrix a_matrix = new Matrix(a_double);
Matrix b_matrix = new Matrix(b_double);
double[][] result = a_matrix.times(b_matrix).getArray();
long[][]result_long = new long[result.length][];
for(int i = 0; i< result.length; i++){
result_long[i] = Longs.toArray(Doubles.asList(result[i]));
}
return result_long;
}



/**
* Returns the matrix version of an array. Only scalar values can be sorted.
* Values will be arranged in increasing order. (An optional comparison
* function, which takes two elements and returns int {-,0,+}, is accepted
* as a second argument, but it is curently ignored.)
*
* @param a
* An array of long
*
* @return A sorted copy of <em>a</em>
*/
@FunctionSpec(name = "matrixsum", returnType = "array of array of int", formalParameters = { "array of array of int", "array of array of int" })
public static long[][] matrixsum(final long[][] a, final long[][] b) {
double[][] a_double = new double[a.length][];
double[][] b_double = new double[b.length][];

for(int i = 0; i< a.length; i++){
a_double[i] = Doubles.toArray(Longs.asList(a[i]));
}

for(int i = 0; i< b.length; i++){
b_double[i] = Doubles.toArray(Longs.asList(b[i]));
}
Matrix a_matrix = new Matrix(a_double);
Matrix b_matrix = new Matrix(b_double);
double[][] result = a_matrix.plus(b_matrix).getArray();
long[][]result_long = new long[result.length][];
for(int i = 0; i< result.length; i++){
result_long[i] = Longs.toArray(Doubles.asList(result[i]));
}
return result_long;
}

/**
* Returns the matrix version of an array. Only scalar values can be sorted.
* Values will be arranged in increasing order. (An optional comparison
* function, which takes two elements and returns int {-,0,+}, is accepted
* as a second argument, but it is curently ignored.)
*
* @param a
* An array of long
*
* @return A sorted copy of <em>a</em>
*/
@FunctionSpec(name = "matrixsubstract", returnType = "array of array of int", formalParameters = { "array of array of int", "array of array of int" })
public static long[][] matrixsubstract(final long[][] a, final long[][] b) {
double[][] a_double = new double[a.length][];
double[][] b_double = new double[b.length][];

for(int i = 0; i< a.length; i++){
a_double[i] = Doubles.toArray(Longs.asList(a[i]));
}

for(int i = 0; i< b.length; i++){
b_double[i] = Doubles.toArray(Longs.asList(b[i]));
}
Matrix a_matrix = new Matrix(a_double);
Matrix b_matrix = new Matrix(b_double);
double[][] result = a_matrix.minus(b_matrix).getArray();
long[][]result_long = new long[result.length][];
for(int i = 0; i< result.length; i++){
result_long[i] = Longs.toArray(Doubles.asList(result[i]));
}
return result_long;
}

/**
* Returns the matrix version of an array. Only scalar values can be sorted.
* Values will be arranged in increasing order. (An optional comparison
* function, which takes two elements and returns int {-,0,+}, is accepted
* as a second argument, but it is curently ignored.)
*
* @param a
* An array of long
*
* @return A sorted copy of <em>a</em>
*/
@FunctionSpec(name = "multiply", returnType = "array of array of int", formalParameters = { "array of array of int", "array of array of int" })
public static double[][] multiply(final double[][] a, final double[][] b) {
Matrix a_matrix = new Matrix(a);
Matrix b_matrix = new Matrix(b);
return a_matrix.times(b_matrix).getArray();
}

/**
* Returns the matrix version of an array. Only scalar values can be sorted.
* Values will be arranged in increasing order. (An optional comparison
* function, which takes two elements and returns int {-,0,+}, is accepted
* as a second argument, but it is curently ignored.)
*
* @param a
* An array of long
*
* @return A sorted copy of <em>a</em>
*/
@FunctionSpec(name = "matrixsum", returnType = "array of array of int", formalParameters = { "array of array of int", "array of array of int" })
public static double[][] matrixsum(final double[][] a, final double[][] b) {
Matrix a_matrix = new Matrix(a);
Matrix b_matrix = new Matrix(b);
return a_matrix.plus(b_matrix).getArray();
}

/**
* Returns the matrix version of an array. Only scalar values can be sorted.
* Values will be arranged in increasing order. (An optional comparison
* function, which takes two elements and returns int {-,0,+}, is accepted
* as a second argument, but it is curently ignored.)
*
* @param a
* An array of long
*
* @return A sorted copy of <em>a</em>
*/
@FunctionSpec(name = "matrixsubstract", returnType = "array of array of int", formalParameters = { "array of array of int", "array of array of int" })
public static double[][] matrixsubstract(final double[][] a, final double[][] b) {
Matrix a_matrix = new Matrix(a);
Matrix b_matrix = new Matrix(b);
return a_matrix.minus(b_matrix).getArray();
}



/**
* Returns the matrix version of an array. Only scalar values can be sorted.
* Values will be arranged in increasing order. (An optional comparison
Expand Down

0 comments on commit 315acd7

Please sign in to comment.