<?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[Function Objects]]></title><description><![CDATA[<p>Hallo,</p>
<p>fällt jemandem auf die schnelle ein, wie ich folgenden code durch ein/meherer FunctionObject(s) ersetze:</p>
<pre><code class="language-cpp">double xpart[3 * n];
    double mass[n];

    /* Fülle xpart und mass */       

    /* Wähle Partikel aus */
    vector&lt;unsigned int&gt; indices();
    indices.push_back(3);
    indices.push_back(4);

    /* Berechne Schwerpunkt */
	vector&lt;unsigned int&gt;::iterator it;

	for (it = indices.begin(); it != indices.end(); ++it) {
		octree.multipol.m += mass[*it];
	}

	for (it = indices.begin(); it != indices.end(); ++it) {
		double * ptr = xpart + *it * 3;
		for (unsigned int j = 0; j &lt; 3; ++j) {
			octree .multipol.x[j] += ptr[j] * mass[*it];
		}
	}
	for (unsigned int i = 0; i &lt; 3; ++i) {
		octree.multipol.x[i] /= octree.multipol.m;
	}
</code></pre>
<p>Der obige Code implementiert</p>
$\vec{y} = \frac{ \sum^n_{i=1} m\_i \cdot \vec{x}\_i } { \sum^n_{i=1} m_i }$

<p>Ich bin bereits komponentenweise vorgegangen, also</p>
<pre><code class="language-cpp">octree.multipol.m = accumulate(indices.begin(), indices.end(), ....);

for_each(octree.multipol.x, octree.multipol.x+3, scale_and_add());

transform(octree.multipol.x, octree.multipol.x+3, bind2nd(divide(), octree.multipol.m));
</code></pre>
<p>allerdings war die Geschwindingkeit ca. 1/3 langsamer. Ich habe den Code leider nicht mehr, so dass ich ihn hätte zeigen können.</p>
<p>Danke für eure Ideen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/274686/function-objects</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 08:45:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274686.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Sep 2010 20:07:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Function Objects on Thu, 30 Sep 2010 20:07:31 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>fällt jemandem auf die schnelle ein, wie ich folgenden code durch ein/meherer FunctionObject(s) ersetze:</p>
<pre><code class="language-cpp">double xpart[3 * n];
    double mass[n];

    /* Fülle xpart und mass */       

    /* Wähle Partikel aus */
    vector&lt;unsigned int&gt; indices();
    indices.push_back(3);
    indices.push_back(4);

    /* Berechne Schwerpunkt */
	vector&lt;unsigned int&gt;::iterator it;

	for (it = indices.begin(); it != indices.end(); ++it) {
		octree.multipol.m += mass[*it];
	}

	for (it = indices.begin(); it != indices.end(); ++it) {
		double * ptr = xpart + *it * 3;
		for (unsigned int j = 0; j &lt; 3; ++j) {
			octree .multipol.x[j] += ptr[j] * mass[*it];
		}
	}
	for (unsigned int i = 0; i &lt; 3; ++i) {
		octree.multipol.x[i] /= octree.multipol.m;
	}
</code></pre>
<p>Der obige Code implementiert</p>
$\vec{y} = \frac{ \sum^n_{i=1} m\_i \cdot \vec{x}\_i } { \sum^n_{i=1} m_i }$

<p>Ich bin bereits komponentenweise vorgegangen, also</p>
<pre><code class="language-cpp">octree.multipol.m = accumulate(indices.begin(), indices.end(), ....);

for_each(octree.multipol.x, octree.multipol.x+3, scale_and_add());

transform(octree.multipol.x, octree.multipol.x+3, bind2nd(divide(), octree.multipol.m));
</code></pre>
<p>allerdings war die Geschwindingkeit ca. 1/3 langsamer. Ich habe den Code leider nicht mehr, so dass ich ihn hätte zeigen können.</p>
<p>Danke für eure Ideen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1959750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1959750</guid><dc:creator><![CDATA[sunnyholland]]></dc:creator><pubDate>Thu, 30 Sep 2010 20:07:31 GMT</pubDate></item><item><title><![CDATA[Reply to Function Objects on Thu, 30 Sep 2010 20:12:26 GMT]]></title><description><![CDATA[<p>Warum willst du den Code unleserlich und langsam machen und nicht so einfach lassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1959752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1959752</guid><dc:creator><![CDATA[iwonder]]></dc:creator><pubDate>Thu, 30 Sep 2010 20:12:26 GMT</pubDate></item></channel></rss>