<?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[boost multiarray und fill]]></title><description><![CDATA[<p>Hallo ihr Lieben,</p>
<p>ich habe mir einen <a href="http://www.boost.org/doc/libs/1_54_0/libs/multi_array/doc/user.html" rel="nofollow">Multi Array</a> mit drei Einträgen <code>A[i][j][k]</code> erstellt.</p>
<p>Ist es möglich, z.B. bezüglich des zweiten Eintrags den Algorithmus <a href="http://www.cplusplus.com/reference/algorithm/fill_n/" rel="nofollow">fill_n</a> anzuwenden?</p>
<p>Gruß,<br />
-- Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/321662/boost-multiarray-und-fill</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 19:18:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/321662.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Nov 2013 13:42:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost multiarray und fill on Wed, 04 Dec 2013 11:45:27 GMT]]></title><description><![CDATA[<p>Hallo ihr Lieben,</p>
<p>ich habe mir einen <a href="http://www.boost.org/doc/libs/1_54_0/libs/multi_array/doc/user.html" rel="nofollow">Multi Array</a> mit drei Einträgen <code>A[i][j][k]</code> erstellt.</p>
<p>Ist es möglich, z.B. bezüglich des zweiten Eintrags den Algorithmus <a href="http://www.cplusplus.com/reference/algorithm/fill_n/" rel="nofollow">fill_n</a> anzuwenden?</p>
<p>Gruß,<br />
-- Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2366543</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2366543</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Wed, 04 Dec 2013 11:45:27 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Wed, 20 Nov 2013 13:56:24 GMT]]></title><description><![CDATA[<p>Das sollte funktionieren (ungetestet), indem du dir einen passenden &quot;View&quot; erstellst:<br />
<a href="http://www.boost.org/doc/libs/1_54_0/libs/multi_array/doc/user.html#sec_views" rel="nofollow">http://www.boost.org/doc/libs/1_54_0/libs/multi_array/doc/user.html#sec_views</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2366547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2366547</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 20 Nov 2013 13:56:24 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Tue, 26 Nov 2013 08:11:50 GMT]]></title><description><![CDATA[<p>Okay,<br />
hat etwas länger gedauert, musste mich zunächst mit <code>boost</code> vertraut machen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Also ich habe ein Beispiel zusammengebastelt. Ich habe klein angefangen und für einen 2D das jeweils letzte Element einer Spalte für eine beliebige Zeile ausgeben wollen.</p>
<p>In Zeile 31 recht kompakt mit der Notation von <code>vector</code> . Allerdings will ich <code>multi_array</code> von <code>boost</code> verwenden, weil der schneller als verschachtelte Vektoren sein soll.</p>
<p>In Zeile 33 also ein <code>multi_array</code> und gelöst durch das Mitschleppen der Spaltenlänge.</p>
<p>In Zeile 35 durch das einmalige Programmieren eines Index. Funktioniert, hat aber keine Abfrage nach der gewünschten Zeile.</p>
<p>Und schließlich den von dir angesprochenen <code>viewer</code> in Zeile 37.</p>
<p>Sieht gut aus, oder?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;boost/multi_array.hpp&gt;

typedef boost::multi_array&lt;double,2&gt; two_D_array;
typedef boost::multi_array_types::index_range range;

int main()
{
	unsigned int const n = 2;
	unsigned int const m = 10;

	unsigned int const zeile = 1;

	std::vector&lt;std::vector&lt;double&gt;&gt; vec(n,std::vector&lt;double&gt;(m,0.0));

	two_D_array A(boost::extents[n][m]);
	boost::array&lt;two_D_array::index,2&gt; idx = {{1,9}};
	two_D_array::index_gen indices;
	two_D_array::array_view&lt;1&gt;::type my_view = A[ indices[range(0,n)][m-1] ];

	for(unsigned int i = 0; i &lt; vec.size(); ++i)
	{
		for(unsigned int j = 0; j &lt; vec[zeile].size(); ++j)
		{
			vec[i][j] = static_cast&lt;double&gt;(i+1) * static_cast&lt;double&gt;(j+1);
			A[i][j] = static_cast&lt;double&gt;(i+1) * static_cast&lt;double&gt;(j+1);
		}
	}

	std::cout &lt;&lt; &quot;Vektor: &quot; &lt;&lt; vec[zeile].back() &lt;&lt; std::endl;

	std::cout &lt;&lt; &quot;Boost Multi Array manuell: &quot; &lt;&lt; A[zeile][m-1] &lt;&lt; std::endl;

	std::cout &lt;&lt; &quot;Boost Multi Array idx: &quot; &lt;&lt; A(idx) &lt;&lt; std::endl;

	std::cout &lt;&lt; &quot;Boost Multi Array view: &quot; &lt;&lt; my_view[zeile] &lt;&lt; std::endl;

	return 0;
}
</code></pre>
<p>Gruß,<br />
-- Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2368035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2368035</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Tue, 26 Nov 2013 08:11:50 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Tue, 26 Nov 2013 11:08:25 GMT]]></title><description><![CDATA[<p>Es ist übrigens ein Trugschluss, dass verschachtelte Vectoren einem mehrdimensionalen Array entsprechen. Beim vector ist schließlich alles dynamisch, d.h. man hätte eine dynamische Liste von dynamischen Listen (die jeweils alle voneinander unabhängig sind, also auch nicht die gleiche Größe haben müssen). Einem mehrdimensionales Array entspricht in C++ eines der folgenden:<br />
1. alle Dimensionen statisch: std::array von std::arrays<br />
2. alle Dimensionen statisch bis auf eine: std::vector von std::arrays<br />
3. alle Dimensionen dynamisch: Einfacher Wrapper um std::vector oder aber boost::multiarray (letzteres dann nehmen, wenn man die Zusatzfeatures des multiarrays nutzt).</p>
<blockquote>
<p>Sieht gut aus, oder?</p>
</blockquote>
<p>Dein Beispiel macht die Sachen, die es macht, richtig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2368071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2368071</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 26 Nov 2013 11:08:25 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Tue, 26 Nov 2013 12:13:16 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Dein Beispiel macht die Sachen, die es macht, richtig.</p>
</blockquote>
<p>Okay, immerhin. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Nur ich wollte ja Teile einer Zeile einer Matrix füllen.</p>
<p>Ich habe folgenden <a href="http://stackoverflow.com/questions/9314590/boost-multiarray-dimensions" rel="nofollow">Voschlag bei Stackoverflow</a> gefunden und mich daran orientiert.</p>
<p>Ich habe dazu ein wrapper geschrieben, der beim Aufruf spontan einen <em>viewer</em> für die betreffende Zeile erstellt und den Bereich dann mittels <code>fill</code> füllt.</p>
<p>Ich dachte, dass es möglich sein müsste den <em>viewer</em> gänzlich von zwei Parametern abhängig zu machen (Zeile und Spalte), nur dann kann ich auch gleich den array <code>A[n][m]</code> selbst nehmen, oder nicht? Oder benötige ich den <em>viewer</em>, um die Syntax <code>data()</code> , <code>begin()</code> verwenden zu können? Ich werde leider noch nicht vollständig schlau draus. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Also es läuft, ich kriege nur folgende Fehlermeldung</p>
<blockquote>
<p>array2d.cpp: In member function ‘void array2d::fill_row(unsigned int, unsigned int, unsigned int, double)’:<br />
array2d.cpp:17:6: warning: ‘new_strides.boost::array&lt;long int, 1ul&gt;::elems[0ul]’ may be used uninitialized in this function [-Wmaybe-uninitialized]</p>
</blockquote>
<pre><code class="language-cpp">/*
array2d.h
*/
#ifndef N_D_ARRAY_H_
#define N_D_ARRAY_H_
#include &lt;algorithm&gt;
#include &lt;boost/multi_array.hpp&gt;
#include &lt;iostream&gt;

typedef boost::multi_array&lt;double,2&gt; array;
typedef boost::multi_array_types::index_range range;

class array2d
{
	public:
		array2d(unsigned int,unsigned int);
		void fill_row(unsigned int, unsigned int, unsigned int, double);
		double content(unsigned int, unsigned int);

	private:
		unsigned int _n, _m;
		array A;
		array::index_gen indices;
};
#endif
</code></pre>
<pre><code class="language-cpp">/*
array2d.cpp
*/
#include &quot;array2d.h&quot;
/*
---{}--- constructor ---{}---
*/
array2d::array2d(unsigned int n, unsigned int m):
_n(n), _m(m),
A(boost::extents[n][m])
{
	std::fill( A.data(), A.data() + A.num_elements(), 0.0);
}
/*
---{}--- fill row ---{}---
*/
auto array2d::fill_row(unsigned int row, unsigned int from,
	unsigned int till, double value) -&gt; void
{
	array::array_view&lt;1&gt;::type view(A[ indices[row][range(0,_m-1)] ]);
	std::fill( view.begin() + from, view.begin() + till, value);
}
/*
---{}--- content ---{}---
*/
auto array2d::content(unsigned int n, unsigned int m) -&gt; double
{
	return A[n][m];
}
</code></pre>
<p>Gruß,<br />
-- Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2368082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2368082</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Tue, 26 Nov 2013 12:13:16 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Tue, 26 Nov 2013 13:22:33 GMT]]></title><description><![CDATA[<p>Ich habe dazu mal noch eine dumme Frage:<br />
Dieses <code>fill</code> übernimmt in Zeile 12 einen Pointer durch <code>A.data()</code> und in Zeile 21 einen Iterator <code>view.begin()</code> .</p>
<p>Wieso knirsch das nicht? Es heißt zwar, dass ein Iterator <em>im Prinzip eine Art</em> Pointer auf eine bestimmte Stelle des Containers ist - aber kann ich beide Objekte im Gebrauch einfach einander tauschen?</p>
<p>Oder wird da irgendwo noch ein Typ konvertiert? Oder ist ein Iterator eine Art Wrapper um einen Pointer, wo die Info schon drin steckt auf welches Objekt der Pointer zeigen soll?</p>
<p>Gruß,<br />
-- Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2368103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2368103</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Tue, 26 Nov 2013 13:22:33 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Tue, 26 Nov 2013 13:36:23 GMT]]></title><description><![CDATA[<p>Klaus: Nicht trailing-return-types falsch verwenden. Du sollst schon weiterhin <code>void</code> und <code>double</code> hinschreiben:</p>
<pre><code>double array2d::content(unsigned int n, unsigned int m)
</code></pre>
<p>Die sind fuer etwas ganz anderes gedacht.</p>
<blockquote>
<p>Wieso knirsch das nicht? Es heißt zwar, dass ein Iterator im Prinzip eine Art Pointer auf eine bestimmte Stelle des Containers ist - aber kann ich beide Objekte im Gebrauch einfach einander tauschen?</p>
</blockquote>
<p>Ein Iterator ist einfach ein allgemeiner Zeiger. <code>vector::iterator</code> kann ein Zeiger sein, aber auch ein Wrapper um einen Zeiger, oder aber ein Zeiger auf den Arrayanfang/Zeiger auf den vector und ein Offset (evt. sinnvoll zum Debuggen).<br />
Ein Zeiger erfuellt genauso die Anforderungen an einen <a href="http://en.cppreference.com/w/cpp/concept/ForwardIterator" rel="nofollow">Forward Iterator</a> wie der Iterator aus dem View.</p>
<blockquote>
<p>aber kann ich beide Objekte im Gebrauch einfach einander tauschen?</p>
</blockquote>
<p>Wenn sie auf dasselbe Objekt verweisen, und dieselbe Operator-Semantik haben (wie sich der Verweis nach ++/-- aendert).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2368104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2368104</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 26 Nov 2013 13:36:23 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Thu, 12 Dec 2013 07:21:38 GMT]]></title><description><![CDATA[<p>Klaus82 schrieb:</p>
<blockquote>
<p>Also es läuft, ich kriege nur folgende Fehlermeldung</p>
<blockquote>
<p>array2d.cpp: In member function ‘void array2d::fill_row(unsigned int, unsigned int, unsigned int, double)’:<br />
array2d.cpp:17:6: warning: ‘new_strides.boost::array&lt;long int, 1ul&gt;::elems[0ul]’ may be used uninitialized in this function [-Wmaybe-uninitialized]</p>
</blockquote>
</blockquote>
<p>Scheinbar ist diese Art Fehler bekannt, wie <a href="https://svn.boost.org/trac/boost/ticket/8601" rel="nofollow">hier gemeldet</a>, nur gibt es noch keine Lösung?</p>
<p>Gruß,<br />
-- Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2371283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2371283</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Thu, 12 Dec 2013 07:21:38 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Thu, 12 Dec 2013 16:03:25 GMT]]></title><description><![CDATA[<p>Kann ich mit Boost 1.49 und GCC 4.8 nicht nachvollziehen. Welche Versionen nutzt du?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2371400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2371400</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 12 Dec 2013 16:03:25 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Thu, 12 Dec 2013 17:28:20 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Kann ich mit Boost 1.49 und GCC 4.8 nicht nachvollziehen. Welche Versionen nutzt du?</p>
</blockquote>
<p>Also laut Paketmanager meines Debiansystems kann ich auch Boost 1.49 installieren, habe allerdings gcc 4.7.2.</p>
<p>Gruß,<br />
-- Klaus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2371412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2371412</guid><dc:creator><![CDATA[Klaus82]]></dc:creator><pubDate>Thu, 12 Dec 2013 17:28:20 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Sun, 22 Feb 2015 05:13:07 GMT]]></title><description><![CDATA[<p>was passiert dann wenn ich sowas definiere?</p>
<pre><code>typedef boost::multi_array&lt;int, 3&gt; array_type;
array_type arr;
arr.resize(boost::extents[2][3][0]);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2443761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2443761</guid><dc:creator><![CDATA[tobi007]]></dc:creator><pubDate>Sun, 22 Feb 2015 05:13:07 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Sun, 22 Feb 2015 05:14:38 GMT]]></title><description><![CDATA[<p>kann ich eine 1d,2d,3d array klasse definieren indem ich die groesse als template param uebergebe?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2443762</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2443762</guid><dc:creator><![CDATA[tobi007]]></dc:creator><pubDate>Sun, 22 Feb 2015 05:14:38 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Sun, 22 Feb 2015 19:32:29 GMT]]></title><description><![CDATA[<p>bitte um hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2443875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2443875</guid><dc:creator><![CDATA[tobi007]]></dc:creator><pubDate>Sun, 22 Feb 2015 19:32:29 GMT</pubDate></item><item><title><![CDATA[Reply to boost multiarray und fill on Sun, 22 Feb 2015 23:18:19 GMT]]></title><description><![CDATA[<p>Vollständige Problembeschreibung. Klare Fragen. Keine Threads grundlos von den Toten beleben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2443907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2443907</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 22 Feb 2015 23:18:19 GMT</pubDate></item></channel></rss>