public NDArrayList Next() { PushNext(); if (_rcvd_idx == _sent_idx) { if (_data_buffer != null) { throw new Exception("Data buffer should be empty at this moment"); } throw new Exception("Stop Iteration"); } if (_rcvd_idx >= _sent_idx) { throw new Exception("rcvd_idx must be smaller than sent_idx"); } if (!_data_buffer.ContainsKey(_rcvd_idx)) { throw new Exception("fatal error with _push_next, rcvd_idx missing"); } var batch = _data_buffer[_rcvd_idx]; if (_pin_memory) { batch = DataLoader.AsInContext(batch, Context.CpuPinned(_pin_device_id)); } _rcvd_idx += 1; return(batch); }
public IEnumerator GetEnumerator() { if (_num_workers == 0) { foreach (var batch in _batch_sampler) { var ret = _batchify_fn(batch.Select(x => _dataset[x]).ToArray()); if (_pin_memory) { ret = DataLoader.AsInContext(ret, Context.CpuPinned(_pin_device_id)); } yield return(ret); } } yield return(new _MultiWorkerIterV1(_num_workers, _dataset, _batchify_fn, _batch_sampler, _pin_memory, _pin_device_id).Next()); }