Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
WeightedAddition.cs
1using System;
2
4{
8 public static partial class ArithmeticsOperations
9 {
17 public static void WeightedAddition(this Matrix<float> M, Matrix<float> Matrix, float Scalar)
18 {
19 int y, h = M.Height;
20 if (h != Matrix.Height)
21 throw new ArgumentOutOfRangeException(nameof(Matrix), "Heights to do not match.");
22
23 int x, w = M.Width;
24 if (w != Matrix.Width)
25 throw new ArgumentOutOfRangeException(nameof(Matrix), "Widths to do not match.");
26
27 int DestOffset = M.Start;
28 int SrcOffset = Matrix.Start;
29 int DestSkip = M.Skip;
30 int SrcSkip = Matrix.Skip;
31 float[] Dest = M.Data;
32 float[] Src = Matrix.Data;
33
34 for (y = 0; y < h; y++, DestOffset += DestSkip, SrcOffset += SrcSkip)
35 {
36 for (x = 0; x < w; x++)
37 Dest[DestOffset++] += Src[SrcOffset++] * Scalar;
38 }
39 }
40
48 public static void WeightedAddition(this Matrix<float> M, Matrix<int> Matrix, float Scalar)
49 {
50 int y, h = M.Height;
51 if (h != Matrix.Height)
52 throw new ArgumentOutOfRangeException(nameof(Matrix), "Heights to do not match.");
53
54 int x, w = M.Width;
55 if (w != Matrix.Width)
56 throw new ArgumentOutOfRangeException(nameof(Matrix), "Widths to do not match.");
57
58 int DestOffset = M.Start;
59 int SrcOffset = Matrix.Start;
60 int DestSkip = M.Skip;
61 int SrcSkip = Matrix.Skip;
62 float[] Dest = M.Data;
63 int[] Src = Matrix.Data;
64
65 for (y = 0; y < h; y++, DestOffset += DestSkip, SrcOffset += SrcSkip)
66 {
67 for (x = 0; x < w; x++)
68 Dest[DestOffset++] += Src[SrcOffset++] * Scalar;
69 }
70 }
71
79 public static void WeightedAddition(this Matrix<int> M, Matrix<int> Matrix, int Scalar)
80 {
81 int y, h = M.Height;
82 if (h != Matrix.Height)
83 throw new ArgumentOutOfRangeException(nameof(Matrix), "Heights to do not match.");
84
85 int x, w = M.Width;
86 if (w != Matrix.Width)
87 throw new ArgumentOutOfRangeException(nameof(Matrix), "Widths to do not match.");
88
89 int DestOffset = M.Start;
90 int SrcOffset = Matrix.Start;
91 int DestSkip = M.Skip;
92 int SrcSkip = Matrix.Skip;
93 int[] Dest = M.Data;
94 int[] Src = Matrix.Data;
95
96 for (y = 0; y < h; y++, DestOffset += DestSkip, SrcOffset += SrcSkip)
97 {
98 for (x = 0; x < w; x++)
99 Dest[DestOffset++] += Src[SrcOffset++] * Scalar;
100 }
101 }
102 }
103}
static void WeightedAddition(this Matrix< int > M, Matrix< int > Matrix, int Scalar)
Performs a weighted addition of a matrix to the current matrix, including a scalar multiplication on ...
static void WeightedAddition(this Matrix< float > M, Matrix< int > Matrix, float Scalar)
Performs a weighted addition of a matrix to the current matrix, including a scalar multiplication on ...
static void WeightedAddition(this Matrix< float > M, Matrix< float > Matrix, float Scalar)
Performs a weighted addition of a matrix to the current matrix, including a scalar multiplication on ...
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Definition: Matrix.cs:12
int Height
Height of matrix (number of rows)
Definition: Matrix.cs:136
T[] Data
Underlying data on which the matrix is defined.
Definition: Matrix.cs:114
int Width
Width of matrix (number of columns)
Definition: Matrix.cs:120
int Skip
Number of elements to skip from the right edge in the underlying data to the left edge of the new row...
Definition: Matrix.cs:233
int Start
Start offset of matrix in underlying data.
Definition: Matrix.cs:228