Exemplo n.º 1
0
        private NdArray[] ForwardCpu(NdArray x)
        {
            NdArray[] resultArays = NdArray.Split(x, Indices, Axis);

            foreach (var resultArray in resultArays)
            {
                resultArray.ParentFunc = this;
            }

            return(resultArays);
        }
Exemplo n.º 2
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];
                }
            }
        }
Exemplo n.º 3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Backward CPU. </summary>
        ///
        /// <param name="y">    A NdArray to process. </param>
        /// <param name="xs">   The xs. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void BackwardCpu([NotNull] NdArray y, [NotNull] NdArray[] xs)
        {
            int[] prevInputShapes = _prevInputSections[_prevInputSections.Count - 1];
            _prevInputSections.RemoveAt(_prevInputSections.Count - 1);

            NdArray[] 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];
                }
            }
        }