fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <cmath>
  6. #include <cfenv>
  7. #include <climits>
  8. #include <iostream>
  9. #include <vector>
  10. #include <numeric>
  11. #include <string>
  12. #include <functional>
  13.  
  14. using namespace std;
  15.  
  16. int main() {
  17. std::vector<float> data = {1, 4};
  18. size_t num_tokens = data.size();
  19. size_t num_frames = std::accumulate(data.begin(), data.end(), 0, [&](size_t a, float b){return a + lround(b);});
  20. cout<<num_tokens << " " << num_frames << endl;
  21. std::vector<float> upsampled_data(num_tokens * num_frames);
  22.  
  23. size_t begin = 0;
  24.  
  25. for(size_t row=0; row < data.size(); ++row) {
  26. std::fill(upsampled_data.begin() + row * num_frames + begin,
  27. upsampled_data.begin() + row * num_frames + begin + lround(data[row]), 1);
  28.  
  29. begin += lround(data[row]);
  30. }
  31. for (auto x : upsampled_data)
  32. {
  33. cout<<x<<" ";
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5520KB
stdin
Standard input is empty
stdout
2 5
1 0 0 0 0 0 1 1 1 1