package be.iminds.iot.dianne.tensor;

/**
 * Provides all supported Tensor operations. Each operation where a tensor is returned,
 * also has the argument res, in which one could provide a tensor in which the result
 * will be put and returned. This in order to save memory allocations. When res is null 
 * a new Tensor object will be created.
 * 
 * @author tverbele
 *
 */
public interface TensorMath<T extends Tensor<T>> {

	/**
	 * Add the given value to all elements in the T.
	 */
	public T add(T res, final T T, final float value);
	
	/**
	 * Add T1 to T2 and put result into res. 
	 * The number of elements must match, but sizes do not matter.
	 */
	public T add(T res, final T T1, final T T2);

	/**
	 * Multiply elements of T2 by the scalar value and add it to T1. 
	 * The number of elements must match, but sizes do not matter.
	 */
	public T add(T res, final T T1, final float value, final T T2);
	
	/**
	 * Multiply all elements in the T by the given value.
	 */
	public T mul(T res, final T T1, final float value);
	
	/**
	 * Element-wise multiplication of T1 by T2. 
	 * The number of elements must match, but sizes do not matter.
	 */
	public T cmul(T res, final T T1, final T T2);
	
	/**
	 * Divide all elements in the T by the given value.
	 */
	public T div(T res, final T T1, final float value);
	
	/**
	 * Element-wise division of T1 by T2. 
	 * The number of elements must match, but sizes do not matter.
	 */
	public T cdiv(T res, final T T1, final T T2);
	
	/**
	 * Performs the dot product between vec1 and vec2. 
	 * The number of elements must match: both Ts are seen as a 1D vector.
	 */
	public float dot(final T vec1, final T vec2);
	
	/**
	 * Matrix vector product of mat and vec. 
	 * Sizes must respect the matrix-multiplication operation: 
	 * if mat is a n x m matrix, vec must be vector of size m and res must be a vector of size n.
	 */
	public T mv(T res, final T mat, final T vec);
	
	/**
	 * Matrix matrix product of mat1 and mat2. If mat1 is a n x m matrix, mat2 a m x p matrix, 
	 * res must be a n x p matrix.
	 */
	public T mm(T res, final T mat1, final T mat2);
	
	/**
	 * Performs a matrix-vector multiplication between mat (2D tensor) and vec (1D tensor) 
	 * and add it to vec1. In other words, res = vec1 + mat*vec2
	 */
	public T addmv(T res, final T vec1, final T mat, final T vec2);

	/**
	 * Performs a matrix-vector multiplication between mat1 (2D tensor) and mat2 (2D tensor) 
	 * and add it to mat. In other words, res = mat + mat1*mat2
	 */
	public T addmm(T res, final T mat, final T mat1, final T mat2);

	/**
	 * Put the tanh of each element into res
	 */
	public T tanh(T res, final T tensor);
	
	/**
	 * Put the sigmoid of each element into res
	 */
	public T sigmoid(T res, final T tensor);
}

@@ -510,17 +510,22 @@
 final T 
-T
+tensor
 , final 
@@ -557,15 +557,25 @@
 Add 
-T1 to T
+tensor1 to tensor
 2 an
@@ -688,33 +688,38 @@
 (T res, final T 
-T
+tensor
 1, final T T2);%0A
@@ -709,25 +709,30 @@
 r1, final T 
-T
+tensor
 2);%0A%0A%09/**%0A%09 
@@ -754,17 +754,22 @@
 ents of 
-T
+tensor
 2 by the
@@ -796,17 +796,22 @@
 d it to 
-T
+tensor
 1. %0A%09 * 
@@ -896,33 +896,38 @@
 (T res, final T 
-T
+tensor
 1, final float v
@@ -932,33 +932,38 @@
  value, final T 
-T
+tensor
 2);%0A%09%0A%09/**%0A%09 * M
@@ -1038,33 +1038,38 @@
 (T res, final T 
-T
+tensor
 1, final float v
@@ -1113,31 +1113,41 @@
 lication of 
-T1 by T
+tensor1 by tensor
 2. %0A%09 * The 
@@ -1229,33 +1229,38 @@
 (T res, final T 
-T
+tensor
 1, final T T2);%0A
@@ -1246,33 +1246,38 @@
 ensor1, final T 
-T
+tensor
 2);%0A%09%0A%09/**%0A%09 * D
@@ -1350,33 +1350,38 @@
 (T res, final T 
-T
+tensor
 1, final float v
@@ -1427,15 +1427,25 @@
  of 
-T1 by T
+tensor1 by tensor
 2. %0A
@@ -1543,17 +1543,22 @@
 final T 
-T
+tensor
 1, final
@@ -1560,17 +1560,22 @@
 final T 
-T
+tensor
 2);%0A%09%0A%09/
@@ -2051,16 +2051,21 @@
 t of mat
+ensor
 1 and ma
@@ -2065,16 +2065,21 @@
  and mat
+ensor
 2. If ma
@@ -2079,16 +2079,21 @@
 . If mat
+ensor
 1 is a n
@@ -2108,16 +2108,21 @@
 rix, mat
+ensor
 2 a m x 
@@ -2507,16 +2507,21 @@
 ween mat
+ensor
 1 (2D te
@@ -2533,16 +2533,21 @@
  and mat
+ensor
 2 (2D te
@@ -2611,13 +2611,23 @@
  mat
-1*mat
+ensor1*matensor
 2%0A%09 

fix API parameter names