示例#1
0
        public void Run(MyStackingOperation operation, MyMemoryBlock<float> output, IEnumerable<MyMemoryBlock<float>> inputs)
        {
            if (inputs == null || !inputs.Any())
            {
                MyLog.WARNING.WriteLine("No inputs for stacking operation to run on. Owner: " + m_caller.Name);
                return;
            }

            inputs = inputs.Where(a => a != null);

            if (m_forceInputChecking && !ValidateAtRun(operation, inputs, output))
                return;

            switch (operation)
            {
                case MyStackingOperation.Concatenate:
                    {
                        int resPtr = 0;

                        foreach (MyMemoryBlock<float> input in inputs)
                        {
                            output.CopyFromMemoryBlock(input, 0, resPtr, input.Count);
                            resPtr += input.Count;
                        }
                    }
                    break;

                case MyStackingOperation.Interweave:
                    {
                        int i = 0;
                        int resPtr = 0;
                        MyMemoryBlock<float> first = inputs.First();
                        int rows = first.Count / first.ColumnHint;

                        // Alter between copying the inputs, up to the last row
                        for (; i < rows - 1; i++)
                        {
                            foreach (MyMemoryBlock<float> input in inputs)
                            {
                                output.CopyFromMemoryBlock(input, i * input.ColumnHint, resPtr, input.ColumnHint);
                                resPtr += input.ColumnHint;
                            }
                        }

                        // Copy the last rows - they are not guaranteed to be input.ColumnHint wide!
                        foreach (MyMemoryBlock<float> input in inputs)
                        {
                            int lastRowIdx = i * input.ColumnHint;
                            int lastRowSize = input.Count - lastRowIdx;

                            if (lastRowSize > 0)
                            {
                                output.CopyFromMemoryBlock(input, lastRowIdx, resPtr, lastRowSize);
                                resPtr += lastRowSize;
                            }
                        }
                    }
                    break;
            }
        }
示例#2
0
        public void Run(MyStackingOperation operation, MyMemoryBlock <float> output, IEnumerable <MyMemoryBlock <float> > inputs)
        {
            if (inputs == null || !inputs.Any())
            {
                MyLog.WARNING.WriteLine("No inputs for stacking operation to run on. Owner: " + m_caller.Name);
                return;
            }

            inputs = inputs.Where(a => a != null);

            if (m_forceInputChecking && !ValidateAtRun(operation, inputs, output))
            {
                return;
            }

            switch (operation)
            {
            case MyStackingOperation.Concatenate:
            {
                int resPtr = 0;

                foreach (MyMemoryBlock <float> input in inputs)
                {
                    output.CopyFromMemoryBlock(input, 0, resPtr, input.Count);
                    resPtr += input.Count;
                }
            }
            break;

            case MyStackingOperation.Interweave:
            {
                int i      = 0;
                int resPtr = 0;
                MyMemoryBlock <float> first = inputs.First();
                int rows = first.Count / first.ColumnHint;

                // Alter between copying the inputs, up to the last row
                for (; i < rows - 1; i++)
                {
                    foreach (MyMemoryBlock <float> input in inputs)
                    {
                        output.CopyFromMemoryBlock(input, i * input.ColumnHint, resPtr, input.ColumnHint);
                        resPtr += input.ColumnHint;
                    }
                }

                // Copy the last rows - they are not guaranteed to be input.ColumnHint wide!
                foreach (MyMemoryBlock <float> input in inputs)
                {
                    int lastRowIdx  = i * input.ColumnHint;
                    int lastRowSize = input.Count - lastRowIdx;

                    if (lastRowSize > 0)
                    {
                        output.CopyFromMemoryBlock(input, lastRowIdx, resPtr, lastRowSize);
                        resPtr += lastRowSize;
                    }
                }
            }
            break;
            }
        }