Example #1
0
        public static Matf operator -(Matf left, float value)
        {
            Matf result = new Matf(left.rows, left.cols);

            for (int i = 0; i < result.size; i++)
            {
                result.elements[i] = left.elements[i] - value;
            }
            return(result);
        }
Example #2
0
        public static Matf Mul(Vecf vertical, Vecf horizontal)
        {
            Matf result = new Matf(vertical.size, horizontal.size);

            for (int row = 0; row < result.rows; row++)
            {
                for (int col = 0, index = row * result.cols; col < result.cols; col++, index++)
                {
                    result.elements[index] = vertical.elements[row] * horizontal.elements[col];
                }
            }
            return(result);
        }
Example #3
0
        public static Matf FromArray(float[,] arr)
        {
            Matf result = new Matf(arr.GetLength(0), arr.GetLength(1));

            for (int i = 0, e = 0; i < result.rows; i++)
            {
                for (int j = 0; j < result.cols; j++)
                {
                    result.elements[e++] = arr[i, j];
                }
            }
            return(result);
        }
Example #4
0
        public static Matf FromArray(float[] arr, int n, int m)
        {
            if (n * m != arr.Length)
            {
                throw new ArgumentException();
            }

            Matf result = new Matf(n, m);

            for (int i = 0; i < result.size; i++)
            {
                result.elements[i] = arr[i];
            }
            return(result);
        }
Example #5
0
        public static Matf Scale(Matf m1, Matf m2)
        {
            if (m1.rows != m2.rows ||
                m1.cols != m2.cols)
            {
                throw new ArgumentException();
            }

            Matf m = new Matf(m1.rows, m2.cols);

            for (int i = 0; i < m.size; i++)
            {
                m.elements[i] = m1.elements[i] * m2.elements[i];
            }
            return(m);
        }
Example #6
0
        public static Matf ParallelMul(Vecf vertical, Vecf horizontal)
        {
            Matf result = new Matf(vertical.size, horizontal.size);

            Parallel.For(0, result.rows, new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }, (row) =>
            {
                for (int col = 0, index = row * result.cols; col < result.cols; col++, index++)
                {
                    result.elements[index] = vertical.elements[row] * horizontal.elements[col];
                }
            });
            return(result);
        }
Example #7
0
        public static Matf operator -(Matf left, Matf right)
        {
            if (left.rows != right.rows ||
                left.cols != right.cols)
            {
                throw new ArgumentException();
            }

            Matf result = new Matf(left.rows, left.cols);

            for (int i = 0; i < result.size; i++)
            {
                result.elements[i] = left.elements[i] - right.elements[i];
            }
            return(result);
        }
Example #8
0
        public static Matf Mul(Matf m, Vecf v)
        {
            if (m.cols != 1)
            {
                throw new ArgumentException();
            }

            Matf result = new Matf(m.rows, v.size);

            for (int row = 0; row < result.rows; row++)
            {
                for (int col = 0, index = row * result.cols; col < result.cols; col++, index++)
                {
                    result.elements[index] = m.elements[row] * v.elements[col];
                }
            }
            return(result);
        }
Example #9
0
        public static Matf Mul(Vecf v, Matf m)
        {
            if (v.size != m.rows)
            {
                throw new ArgumentException();
            }

            Matf result = new Matf(1, m.cols);

            for (int x = 0; x < m.cols; x++)
            {
                float sum = 0;
                for (int i = 0; i < v.size; i++)
                {
                    sum += v.elements[i] * m.elements[i * m.cols + x];
                }
                result.elements[x] = sum;
            }
            return(result);
        }
Example #10
0
        public static Matf Mul(Matf left, Matf right)
        {
            if (left.cols != right.rows)
            {
                throw new ArgumentException();
            }

            Matf result = new Matf(left.rows, right.cols);

            for (int y = 0; y < left.rows; y++)
            {
                for (int x = 0; x < right.cols; x++)
                {
                    float sum = 0;
                    for (int i = 0, left_index = y * left.cols; i < left.cols; i++, left_index++)
                    {
                        sum += left.elements[left_index] * right.elements[i * right.cols + x];
                    }
                    result.elements[y * right.cols + x] = sum;
                }
            }
            return(result);
        }