Exemplo n.º 1
0
        public IWeightMatrix Add(IWeightMatrix w1, IWeightMatrix w2, IWeightMatrix w3)
        {
            var m1  = w1 as WeightTensor;
            var m2  = w2 as WeightTensor;
            var m3  = w3 as WeightTensor;
            var res = weightTensorFactory.CreateWeightTensor(m1.Rows, m1.Columns, deviceId);

            Ops.Add3(res.TWeight, m1.TWeight, m2.TWeight, m3.TWeight);

            if (this.needs_backprop)
            {
                Action backward = () =>
                {
                    Ops.Add(m1.TGradient, m1.TGradient, res.TGradient);
                    Ops.Add(m2.TGradient, m2.TGradient, res.TGradient);
                    Ops.Add(m3.TGradient, m3.TGradient, res.TGradient);
                };
                this.backprop.Add(backward);
            }

            return(res);
        }