Beispiel #1
0
        protected override NdArray[] SingleInputForward(NdArray x)
        {
            NdArray[] resultArrays = NdArray.Split(x, Indices, Axis);

            for (int i = 0; i < resultArrays.Length; i++)
            {
                resultArrays[i].ParentFunc = this;
            }

            return(resultArrays);
        }
Beispiel #2
0
        protected NdArray <T>[] SplitAxisForward(NdArray <T> x)
        {
            NdArray <T>[] resultArrays = NdArray.Split(x, Indices, Axis);

            for (int i = 0; i < resultArrays.Length; i++)
            {
                resultArrays[i].ParentFunc = this;
            }

            return(resultArrays);
        }
Beispiel #3
0
        private NdArray[] ForwardCpu(NdArray x)
        {
            NdArray[] resultArrays = NdArray.Split(x, Indices, Axis);

            for (int i = 0; i < resultArrays.Length; i++)
            {
                resultArrays[i].ParentFunc = this;
            }

            return(resultArrays);
        }
Beispiel #4
0
        private void BackwardCpu(NdArray y, NdArray[] xs)
        {
            int[] prevInputShapes = this._prevInputSections[this._prevInputSections.Count - 1];
            this._prevInputSections.RemoveAt(this._prevInputSections.Count - 1);

            NdArray[] result = NdArray.Split(y, prevInputShapes, this.Axis);

            for (int i = 0; i < xs.Length; i++)
            {
                for (int j = 0; j < xs[i].Grad.Length; j++)
                {
                    xs[i].Grad[j] += result[i].Grad[j];
                }
            }
        }
Beispiel #5
0
        public static void MultiOutputBackward(NdArray <Real> y, NdArray <Real>[] xs, int axis, List <int[]> prevInputSections)
        {
            int[] prevInputShapes = prevInputSections[prevInputSections.Count - 1];
            prevInputSections.RemoveAt(prevInputSections.Count - 1);

            NdArray <Real>[] result = NdArray.Split(y, prevInputShapes, axis);

            for (int i = 0; i < xs.Length; i++)
            {
                for (int j = 0; j < xs[i].Grad.Length; j++)
                {
                    xs[i].Grad[j] += result[i].Grad[j];
                }
            }
        }