示例#1
0
        public Matrix Conv(Tensor3 b)
        {
            if (deep != b.deep)
            {
                throw new Exception();
            }

            Matrix result = new Matrix(width - b.width + 1, height - b.height + 1);

            Parallel.For(0, result.height, y =>
                         //for (int y = 0; y < result.height; y++)
            {
                //Parallel.For(0, result.width, x =>
                for (int x = 0; x < result.width; x++)
                {
                    for (int dy = 0; dy < b.height; dy++)
                    {
                        for (int dx = 0; dx < b.width; dx++)
                        {
                            for (int dz = 0; dz < b.deep; dz++)
                            {
                                result[y, x] += elements[dz][y + dy, x + dx] * b[dz, dy, dx];
                            }
                        }
                    }
                }
                //});
            });

            return(result);
        }
示例#2
0
        public Tensor3 ToTensor3()
        {
            Tensor3 tensor3 = new Tensor3(Length, 1, 1);

            for (int i = 0; i < Length; i++)
            {
                tensor3[0, 0, i] = elements[i];
            }
            return(tensor3);
        }
示例#3
0
        public Tensor3 ToTensor3()
        {
            Tensor3 answ = new Tensor3(width, height, 1);

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    answ[0, i, j] = elements[getInd(i, j)];
                }
            }
            return(answ);
        }
示例#4
0
        public Tensor3 ToTensor3(int butch)
        {
            Tensor3 res = new Tensor3(width, height, deep);

            for (int z = 0; z < deep; z++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        res[z, y, x] = elements[butch * dhw + z * hw + y * width + x];
                    }
                }
            }
            return(res);
        }
示例#5
0
        static public Tensor3 operator /(Tensor3 tensor3, double a)
        {
            Tensor3 res = new Tensor3(tensor3.width, tensor3.height, tensor3.deep);

            for (int z = 0; z < tensor3.deep; z++)
            {
                for (int y = 0; y < tensor3.height; y++)
                {
                    for (int x = 0; x < tensor3.width; x++)
                    {
                        res[z, y, x] = tensor3[z, y, x] / a;
                    }
                }
            }
            return(res);
        }
示例#6
0
        static public Tensor3 operator -(Tensor3 a, double b)
        {
            Tensor3 res = new Tensor3(a.width, a.height, a.deep);

            for (int z = 0; z < a.deep; z++)
            {
                for (int y = 0; y < a.height; y++)
                {
                    for (int x = 0; x < a.width; x++)
                    {
                        res[z, y, x] = a[z, y, x] - b;
                    }
                }
            }
            return(res);
        }
示例#7
0
        public Tensor3 Abs()
        {
            Tensor3 res = new Tensor3(width, height, deep);

            for (int z = 0; z < deep; z++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        res[z, y, x] = Math.Abs(elements[z][y, x]);
                        //if (double.IsNaN(res[z, y, x])) res[z, y, x] = 0.0;
                    }
                }
            }
            return(res);
        }
示例#8
0
        static public Tensor3 operator +(Tensor3 a, Tensor3 b)
        {
            if (a.width != b.width || a.height != b.height || a.deep != b.deep)
            {
                throw new Exception();
            }
            Tensor3 res = new Tensor3(a.width, a.height, a.deep);

            for (int z = 0; z < a.deep; z++)
            {
                for (int y = 0; y < a.height; y++)
                {
                    for (int x = 0; x < a.width; x++)
                    {
                        res[z, y, x] = a[z, y, x] + b[z, y, x];
                    }
                }
            }
            return(res);
        }
示例#9
0
        public Tensor3 ElementsMultiply(Tensor3 b)
        {
            if (width != b.width || height != b.height || deep != b.deep)
            {
                throw new Exception();
            }
            Tensor3 res = new Tensor3(width, height, deep);

            for (int z = 0; z < deep; z++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        res[z, y, x] = elements[z][y, x] * b[z, y, x];
                    }
                }
            }
            return(res);
        }
示例#10
0
        public Tensor3(Tensor3 tensor3)
        {
            this.width  = tensor3.width;
            this.height = tensor3.height;
            this.deep   = tensor3.deep;

            elements = new Matrix[tensor3.deep];
            for (int i = 0; i < tensor3.deep; i++)
            {
                elements[i] = new Matrix(tensor3.width, tensor3.height);
            }

            Parallel.For(0, deep, z =>
            {//for (int z = 0; z < deep; z++)
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        elements[z][y, x] = tensor3[z, y, x];
                    }
                }
            });
        }