public IMiniBatch Get(IExecutionContext executionContext, IReadOnlyList <int> rows)
        {
            var data      = rows.Select(i => _data[i]).ToList();
            var inputData = new Dictionary <int, List <FloatVector> >();

            foreach (var item in data)
            {
                var input = item;
                for (int i = 0, len = input.RowCount; i < len; i++)
                {
                    if (!inputData.TryGetValue(i, out List <FloatVector> temp))
                    {
                        inputData.Add(i, temp = new List <FloatVector>());
                    }
                    temp.Add(input.Row[i]);
                }
            }

            var miniBatch = new MiniBatch(rows, this);

            foreach (var item in inputData.OrderBy(kv => kv.Key))
            {
                var input = _lap.CreateMatrixFromRows(item.Value);
                var type  = (item.Key == 0) ? MiniBatchSequenceType.SequenceStart :
                            item.Key == (inputData.Count - 1) ? MiniBatchSequenceType.SequenceEnd :
                            MiniBatchSequenceType.Standard;
                var inputList = new List <IGraphData> {
                    new MatrixGraphData(input)
                };
                miniBatch.Add(type, inputList, null);
            }

            return(miniBatch);
        }
示例#2
0
        public void TestMatrixCreationFromRows()
        {
            var values = new[] {
                Enumerable.Range(0, 10).Select(v => (float)v).ToArray(),
                Enumerable.Range(0, 10).Select(v => (float)v * 2).ToArray(),
                Enumerable.Range(0, 10).Select(v => (float)v * 3).ToArray(),
            };
            var cpuRowList = values.Select(v => _cpu.CreateVector(v)).ToList();
            var cpuMatrix  = _cpu.CreateMatrixFromRows(cpuRowList);

            var gpuRowList = values.Select(v => _cuda.CreateVector(v)).ToList();

            using (var gpuMatrix = _cuda.CreateMatrixFromRows(gpuRowList)) {
                FloatingPointHelper.AssertEqual(cpuMatrix.AsIndexable(), gpuMatrix.AsIndexable());
            }
            gpuRowList.ForEach(v => v.Dispose());
        }