multi-array klasse
-
hi,
bitte um feedback zu meiner kleinen multi-array klasse (muss noch verbessert werden...). in strides speichere ich die row,col,depth groesse?
kann mir jemand sagen wo der fehler in hist_3d liegt?
der output liefert:6 7 8 10 11 12 14 15 16 38 39 40 42 43 44 46 47 48
anstatt:
10 11 12 14 15 16 38 39 40 46 47 48 54 55 56 62 63 64
#include <iostream> #include <vector> #include <algorithm> using namespace std; class array { private: std::vector<uint32_t> data; std::vector<size_t> sizes; std::vector<size_t> strides; size_t dim; public: array(size_t L1): sizes{L1}, dim(1), data(L1, 0) {} array(size_t L1, size_t L2): sizes{L1, L2}, dim(2), data(L1*L2, 0) {} array(size_t L1, size_t L2, size_t L3): sizes{L1, L2, L3}, dim(3), data(L1*L2*L3, 0) {} // can be stored as a variable size_t get_total_size() { size_t total = 1; for (size_t i = 0; i < sizes.size(); i++) { total *= sizes[i]; } return total; } void insert(uint32_t *in) { size_t len = get_total_size(); for (size_t i = 0; i < len; i++) { data[i] = in[i]; } } void hist_1d(size_t start_row, size_t start_col, size_t cols, uint32_t hist[256]) { cout << '\n'; for (size_t j = 0; j < cols; j++) { uint32_t value = data[start_row + (j + start_col)]; cout << value << ' '; hist[value]++; } cout << '\n'; } void hist_2d(size_t start_row, size_t start_col, size_t rows, size_t cols, uint32_t hist[256]) { for (size_t i = 0; i < rows; i++) { hist_1d((start_row + i) * sizes[0], start_col, cols, hist); } } void hist_3d(size_t start_row, size_t start_col, size_t start_depth, size_t rows, size_t cols, size_t depths, uint32_t hist[256]) { for (size_t k = 0; k < depths; k++) { hist_2d((start_depth + k) * sizes[1], start_col, rows, cols, hist); } } uint32_t get_mode_of_block_1d(size_t start_row, size_t start_col, size_t cols) { uint32_t hist[256] = {0}; hist_1d(start_row, start_col, cols, hist); return get_most_common_value(hist); } uint32_t get_mode_of_block_2d(size_t start_row, size_t start_col, size_t rows, size_t cols) { uint32_t hist[256] = {0}; hist_2d(start_row, start_col, rows, cols, hist); return get_most_common_value(hist); } uint32_t get_mode_of_block_3d(size_t start_row, size_t start_col, size_t start_depth, size_t rows, size_t cols, size_t depths) { uint32_t hist[256] = {0}; hist_3d(start_row, start_col, start_depth, rows, cols, depths, hist); return get_most_common_value(hist); } int get_most_common_value(const uint32_t *hist) { return std::max_element(hist, hist+256) - hist; } }; int main() { // your code goes here array arr0(8); uint32_t data0[] = { 1,2,3,4,5,6,7,8 }; arr0.insert(data0); cout << "mode: " << arr0.get_mode_of_block_1d(0, 1, 3) << endl; array arr(4,8); uint32_t data[] = { 1,2,3,4,5,6,7,8, 9,10,11,12,13,14,15,16, 17,18,19,20,21,22,23,24, 25,26,27,28,29,30,31,32 }; arr.insert(data); cout << "\nmode: " << arr.get_mode_of_block_2d(1, 5, 3, 3) << endl; array arr2(4,8,2); uint32_t data2[] = { 1,2,3,4,5,6,7,8, 9,10,11,12,13,14,15,16, 17,18,19,20,21,22,23,24, 25,26,27,28,29,30,31,32, 33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48, 49,50,51,52,53,54,55,56, 57,58,59,60,61,62,63,64 }; arr2.insert(data2); cout << "\nmode: " << arr2.get_mode_of_block_3d(1, 5, 0, 3, 3, 2) << endl; return 0; }
-
Mitm Debugger durchsteppen?
-
fehler gefunden.
in strides speichere ich die row,col,depth groesse...sehe ich das richtig so?
kann ich dann den sizes vector loeschen?