<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[multi-array klasse]]></title><description><![CDATA[<p>hi,</p>
<p>bitte um feedback zu meiner kleinen multi-array klasse (muss noch verbessert werden...). in strides speichere ich die row,col,depth groesse?</p>
<p>kann mir jemand sagen wo der fehler in hist_3d liegt?<br />
der output liefert:</p>
<pre><code>6 7 8 
10 11 12 
14 15 16 
38 39 40 
42 43 44 
46 47 48
</code></pre>
<p>anstatt:</p>
<pre><code>10 11 12 
14 15 16 
38 39 40
46 47 48 
54 55 56
62 63 64
</code></pre>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
using namespace std;

class array {
private:
	std::vector&lt;uint32_t&gt; data;
	std::vector&lt;size_t&gt; sizes;
	std::vector&lt;size_t&gt; 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 &lt; 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 &lt; 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 &lt;&lt; '\n';

		for (size_t j = 0; j &lt; cols; j++) {
			uint32_t value = data[start_row + (j + start_col)];

			cout &lt;&lt; value &lt;&lt; ' ';

	        hist[value]++;
		}

		cout &lt;&lt; '\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 &lt; 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 &lt; 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 &lt;&lt; &quot;mode: &quot; &lt;&lt; arr0.get_mode_of_block_1d(0, 1, 3) &lt;&lt; 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 &lt;&lt; &quot;\nmode: &quot; &lt;&lt; arr.get_mode_of_block_2d(1, 5, 3, 3) &lt;&lt; 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 &lt;&lt; &quot;\nmode: &quot; &lt;&lt; arr2.get_mode_of_block_3d(1, 5, 0, 3, 3, 2) &lt;&lt; endl;

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/331459/multi-array-klasse</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 15:51:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331459.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Mar 2015 05:48:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to multi-array klasse on Mon, 02 Mar 2015 05:48:10 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>bitte um feedback zu meiner kleinen multi-array klasse (muss noch verbessert werden...). in strides speichere ich die row,col,depth groesse?</p>
<p>kann mir jemand sagen wo der fehler in hist_3d liegt?<br />
der output liefert:</p>
<pre><code>6 7 8 
10 11 12 
14 15 16 
38 39 40 
42 43 44 
46 47 48
</code></pre>
<p>anstatt:</p>
<pre><code>10 11 12 
14 15 16 
38 39 40
46 47 48 
54 55 56
62 63 64
</code></pre>
<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
using namespace std;

class array {
private:
	std::vector&lt;uint32_t&gt; data;
	std::vector&lt;size_t&gt; sizes;
	std::vector&lt;size_t&gt; 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 &lt; 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 &lt; 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 &lt;&lt; '\n';

		for (size_t j = 0; j &lt; cols; j++) {
			uint32_t value = data[start_row + (j + start_col)];

			cout &lt;&lt; value &lt;&lt; ' ';

	        hist[value]++;
		}

		cout &lt;&lt; '\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 &lt; 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 &lt; 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 &lt;&lt; &quot;mode: &quot; &lt;&lt; arr0.get_mode_of_block_1d(0, 1, 3) &lt;&lt; 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 &lt;&lt; &quot;\nmode: &quot; &lt;&lt; arr.get_mode_of_block_2d(1, 5, 3, 3) &lt;&lt; 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 &lt;&lt; &quot;\nmode: &quot; &lt;&lt; arr2.get_mode_of_block_3d(1, 5, 0, 3, 3, 2) &lt;&lt; endl;

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2444879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444879</guid><dc:creator><![CDATA[frankip]]></dc:creator><pubDate>Mon, 02 Mar 2015 05:48:10 GMT</pubDate></item><item><title><![CDATA[Reply to multi-array klasse on Mon, 02 Mar 2015 06:31:08 GMT]]></title><description><![CDATA[<p>Mitm Debugger durchsteppen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444880</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 02 Mar 2015 06:31:08 GMT</pubDate></item><item><title><![CDATA[Reply to multi-array klasse on Mon, 02 Mar 2015 08:46:27 GMT]]></title><description><![CDATA[<p>fehler gefunden.</p>
<p>in strides speichere ich die row,col,depth groesse...sehe ich das richtig so?</p>
<p>kann ich dann den sizes vector loeschen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2444892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2444892</guid><dc:creator><![CDATA[frankip]]></dc:creator><pubDate>Mon, 02 Mar 2015 08:46:27 GMT</pubDate></item></channel></rss>