$R$-Module

Doing $R$-module (equipped with Hadamard operators) algebraic operations; addition, multiplication, and element-wise Hadamard operations

Certainly, we'd want to ensure, or at least evince, through examples that we can do the same algebraic operations, addition, multiplication, and some element-wise Hadamard operations (element-wise addition and multiplication).


In [1]:
import numpy 
import numpy as np

In [4]:
m=6
n=4
k=5

In [10]:
a = np.array(range(11,41)).reshape((k,m)).T

In [11]:
print(a)


[[11 17 23 29 35]
 [12 18 24 30 36]
 [13 19 25 31 37]
 [14 20 26 32 38]
 [15 21 27 33 39]
 [16 22 28 34 40]]

In [12]:
b = np.array(range(11,31)).reshape((n,k)).T

In [13]:
print(b)


[[11 16 21 26]
 [12 17 22 27]
 [13 18 23 28]
 [14 19 24 29]
 [15 20 25 30]]

In [14]:
c = np.array(range(11,35)).reshape((n,m)).T

In [15]:
print(c)


[[11 17 23 29]
 [12 18 24 30]
 [13 19 25 31]
 [14 20 26 32]
 [15 21 27 33]
 [16 22 28 34]]

In [16]:
np.matmul(a,b)


Out[16]:
array([[1555, 2130, 2705, 3280],
       [1620, 2220, 2820, 3420],
       [1685, 2310, 2935, 3560],
       [1750, 2400, 3050, 3700],
       [1815, 2490, 3165, 3840],
       [1880, 2580, 3280, 3980]])

In [21]:
np.diag(range(11,15))


Out[21]:
array([[11,  0,  0,  0],
       [ 0, 12,  0,  0],
       [ 0,  0, 13,  0],
       [ 0,  0,  0, 14]])

In [18]:
np.ones(m*n)


Out[18]:
array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])

In [26]:
# bias_broadcasted
np.matmul( np.ones(m*n).reshape((m,n)) , np.diag(range(11,15))  )


Out[26]:
array([[ 11.,  12.,  13.,  14.],
       [ 11.,  12.,  13.,  14.],
       [ 11.,  12.,  13.,  14.],
       [ 11.,  12.,  13.,  14.],
       [ 11.,  12.,  13.,  14.],
       [ 11.,  12.,  13.,  14.]])

In [27]:
# a*b + bias_broadcasted
np.matmul(a,b) + np.matmul( np.ones(m*n).reshape((m,n)) , np.diag(range(11,15))  )


Out[27]:
array([[ 1566.,  2142.,  2718.,  3294.],
       [ 1631.,  2232.,  2833.,  3434.],
       [ 1696.,  2322.,  2948.,  3574.],
       [ 1761.,  2412.,  3063.,  3714.],
       [ 1826.,  2502.,  3178.,  3854.],
       [ 1891.,  2592.,  3293.,  3994.]])

Now compare these results with running cuBlackDream/examples/RModule.cu; here is a tip for compilation:

nvcc -std=c++14 -arch='sm_52' -lcublas ../src/Axon/Axon.cu ../src/Axon/activationf.cu RModule.cu -o RModule.exe


In [ ]: