@@ -12,7 +12,7 @@ public static class CpuBlas
12
12
/// </summary>
13
13
/// <param name="x">The <see cref="Tensor"/> to transpose</param>
14
14
/// <param name="y">The output <see cref="Tensor"/></param>
15
- public static unsafe void Transpose ( in this Tensor x , in Tensor y )
15
+ public static unsafe void Transpose ( in Tensor x , in Tensor y )
16
16
{
17
17
// Setup
18
18
if ( ! y . MatchShape ( x . Length , x . Entities ) ) throw new ArgumentException ( "The output tensor doesn't have the right shape" ) ;
@@ -32,10 +32,10 @@ void Kernel(int i)
32
32
/// <summary>
33
33
/// Performs the multiplication between two matrices
34
34
/// </summary>
35
- /// <param name="m1 ">The first matrix to multiply</param>
36
- /// <param name="m2 ">The second matrix to multiply</param>
37
- /// <param name="result ">The resulting matrix</param>
38
- public static unsafe void Multiply ( in this Tensor x1 , in Tensor x2 , in Tensor y )
35
+ /// <param name="x1 ">The first matrix to multiply</param>
36
+ /// <param name="x2 ">The second matrix to multiply</param>
37
+ /// <param name="y ">The resulting matrix</param>
38
+ public static unsafe void Multiply ( in Tensor x1 , in Tensor x2 , in Tensor y )
39
39
{
40
40
// Initialize the parameters and the result matrix
41
41
if ( x1 . Length != x2 . Entities ) throw new ArgumentOutOfRangeException ( "Invalid matrices sizes" ) ;
@@ -64,5 +64,30 @@ void Kernel(int i)
64
64
}
65
65
Parallel . For ( 0 , n , Kernel ) . AssertCompleted ( ) ;
66
66
}
67
+
68
+ /// <summary>
69
+ /// Compresses a <see cref="Tensor"/> into a row by summing the components column by column
70
+ /// </summary>
71
+ /// <param name="x">The <see cref="Tensor"/> to compress</param>
72
+ /// <param name="y">The resulting <see cref="Tensor"/></param>
73
+ public static unsafe void CompressVertically ( in Tensor x , in Tensor y )
74
+ {
75
+ // Preliminary checks and declarations
76
+ int
77
+ n = x . Entities ,
78
+ l = x . Length ;
79
+ if ( ! y . MatchShape ( 1 , x . Length ) ) throw new ArgumentException ( "The output tensor doesn't have the right shape" , nameof ( y ) ) ;
80
+ float * px = x , py = y ;
81
+
82
+ // Compress the tensor
83
+ void Kernel ( int j )
84
+ {
85
+ float sum = 0 ;
86
+ for ( int i = 0 ; i < n ; i ++ )
87
+ sum += px [ i * l + j ] ;
88
+ py [ j ] = sum ;
89
+ }
90
+ Parallel . For ( 0 , l , Kernel ) . AssertCompleted ( ) ;
91
+ }
67
92
}
68
93
}
0 commit comments