virtual NDArray GetLabel(void) { const int* indices = random->data(); mx_float *label = new mx_float[sequence_length * batch], *plabel = label; for (int i = current * batch, end = i + batch; i < end; i++) { memcpy(plabel, sequences[indices[i]].data() + 1, (sequences[indices[i]].size() - 1) * sizeof(mx_float)); memset(plabel + sequences[indices[i]].size() - 1, 0, (sequence_length - sequences[indices[i]].size() + 1) * sizeof(mx_float)); plabel += sequence_length; } NDArray array(Shape(batch, sequence_length), device, false); array.SyncCopyFromCPU(label, batch * sequence_length); return array; }
virtual NDArray GetData(void) { const int* indices = random->data(); mx_float *data = new mx_float[sequence_length * batch], *pdata = data; for (int i = current * batch, end = i + batch; i < end; i++) { memcpy(pdata, sequences[indices[i]].data(), sequences[indices[i]].size() * sizeof(mx_float)); if (sequences[indices[i]].size() < sequence_length) memset(pdata + sequences[indices[i]].size(), 0, (sequence_length - sequences[indices[i]].size()) * sizeof(mx_float)); pdata += sequence_length; } NDArray array(Shape(batch, sequence_length), device, false); array.SyncCopyFromCPU(data, batch * sequence_length); return array; }
virtual std::vector<int> GetIndex(void) { const int* indices = random->data(); vector<int> list(indices + current * batch, indices + current * batch + batch); return list; }
virtual int GetPadNum(void) { return sequence_length - sequences[random->data()[current * batch]].size(); }