<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The ILNumerics Blog &#187; C#</title>
	<atom:link href="https://ilnumerics.net/blog/category/c-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://ilnumerics.net/blog</link>
	<description>The Productivity Machine  &#124;  A fresh attempt for scientific computing  &#124;  http://ilnumerics.net</description>
	<lastBuildDate>Thu, 05 Dec 2024 09:09:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Why MINT-students should learn C# instead of Matlab and R</title>
		<link>https://ilnumerics.net/blog/why-mint-students-should-learn-c-instead-of-matlab-and-r/</link>
		<comments>https://ilnumerics.net/blog/why-mint-students-should-learn-c-instead-of-matlab-and-r/#comments</comments>
		<pubDate>Sat, 30 May 2020 10:20:48 +0000</pubDate>
		<dc:creator><![CDATA[Jonas]]></dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[Numerical Algorithms]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Scientific Computing]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=1017</guid>
		<description><![CDATA[<p>For students who want to prototype and code, there’s a wide range of domain specific programming languages around: R or Matlab – just to name a few – make it quite easy to design new algorithms, analyze data and to plot complex functions. However, bringing innovation from science to enterprise-ready software applications still costs lots &#8230; <a href="https://ilnumerics.net/blog/why-mint-students-should-learn-c-instead-of-matlab-and-r/" class="more-link">Continue reading <span class="screen-reader-text">Why MINT-students should learn C# instead of Matlab and R</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/why-mint-students-should-learn-c-instead-of-matlab-and-r/">Why MINT-students should learn C# instead of Matlab and R</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>For students who want to prototype and code, there’s a wide range of domain specific programming languages around: R or Matlab – just to name a few – make it quite easy to design new algorithms, analyze data and to plot complex functions. However, bringing innovation from science to enterprise-ready software applications still costs lots of effort, manpower and experience.</p>
<p>Microsoft’s C# has the potential to fully close this gap: in combination with the ILNumerics numerical library, it becomes the perfect environment both for prototyping and creating powerful software. But why is it that the mainstream in science still doesn’t make use of the power of C#, .NET and Visual studio? Well, let’s have a closer look at computing in academia.</p>
<h2>Scientific Computing vs. Real-Life Applications</h2>
<p>Like in many other areas in academia, the main reason for sticking to out-of-date techniques is “tradition”. That’s why in 2020 there is still a huge gap between mathematical prototyping and industrial-grade production software. Scientists often aim at creating an algorithm solely in order to validate a new model or theory. Once done, they produce a couple of nice looking plots, publish a paper or two and: bye bye.</p>
<p>Unless&#8230; there is a greater use to it!</p>
<h2>Turning Prototypes into Products</h2>
<p>If a model created in science has the potential to earn serious money,  the algorithm created by a mathematician, physicist or microbiologist has to be transformed into something &#8216;production ready&#8217; that can be used in real life.</p>
<p>This is where many development teams in the biggest enterprises are stuck today: Everytime they want to adapt innovation from science for their own software applications, they have to translate Matlab, numpy or R codes into a modern, managed SW framework. This transformation is where the pain starts: It has to be done! And not only once, but with each update. This causes a whole lot of redundant and boilerplate code &#8211; each and every time. This work is expensive: It requires expert knowledge, extensive testing and additional maintenance. And it significantly delays the time to market!</p>
<h2>C# + ILNumerics: Perfect Match for High Performance Applications</h2>
<p>This pain needs to stop. And this is where modern general purpose languages come into play. C# for example fulfills all the requirements for the design of numerical algorithms! Developer tools such as Visual Studio &#8211; especially if complemented with the ILNumerics Array Visualizer und its highly efficient n-dimensional arrays &#8211; allow scientists and software developers to design and prototype their algorithms by directly using production-ready tools.</p>
<p>That means: the painful and time consuming transformation from domain specific prototyping code to an industrial software product is no longer necessary, which allows for huge time savings – often more than 50 percent!</p>
<h2>Maths, Physics, Engineering: Boost Innovation now!</h2>
<p>However, most established scientists in academia today still stick to Matlab, numpy and R &#8211; even though it’s not necessary anymore. But fortunately, a new generation of scientists has started to push innovation at universities ahead. They are often familiar with modern programming languages like C#, and they want to use their knowledge to combine academic prototyping with state of the art software development. This new generation will modernize the intersections between science and industry. Their skills will allow companies all over the world to realize all their innovative potential in a much shorter period of time.</p>
<p>That’s why we think any science and engineering student should get familiar with modern programming languages as early as possible: It will help him or her to boost innovation in their field all over the world!</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/why-mint-students-should-learn-c-instead-of-matlab-and-r/">Why MINT-students should learn C# instead of Matlab and R</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/why-mint-students-should-learn-c-instead-of-matlab-and-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Visual Studio regexp search</title>
		<link>https://ilnumerics.net/blog/fun-with-visual-studio-regexp-search-and-replace/</link>
		<comments>https://ilnumerics.net/blog/fun-with-visual-studio-regexp-search-and-replace/#comments</comments>
		<pubDate>Mon, 17 Oct 2016 15:52:12 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Interesting/ useless]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=981</guid>
		<description><![CDATA[<p>I only recently realized that the Visual Studio regexp feature in Search &#38; Replace is even able to handle regexp captures. Example: In order to locate and replace all line endings in your code which exist at the end of non-empty lines, exluding lines which end at &#8216;/&#8217; or with other non-alphanumeric characters one can &#8230; <a href="https://ilnumerics.net/blog/fun-with-visual-studio-regexp-search-and-replace/" class="more-link">Continue reading <span class="screen-reader-text">Fun with Visual Studio regexp search</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/fun-with-visual-studio-regexp-search-and-replace/">Fun with Visual Studio regexp search</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>I only recently realized that the Visual Studio regexp feature in Search &amp; Replace is even able to handle regexp <a title="Visual Studio regexp" href="https://msdn.microsoft.com/en-us/library/2k3te2cs.aspx">captures</a>. Example: In order to locate and replace all line endings in your code which exist at the end of <em>non-empty</em> lines, exluding lines which end at &#8216;/&#8217; or with other non-alphanumeric characters one can use:</p>
<p>Search Pattern: ([0-9a-zA-Z)])\r\n<br />
Replace: $1;\r\n</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2016/10/SearchAndReplaceVisualStudio.png"><img class="aligncenter size-full wp-image-982" src="http://ilnumerics.net/blog/wp-content/uploads/2016/10/SearchAndReplaceVisualStudio.png" alt="searchandreplacevisualstudio" width="287" height="87" /></a>Matches inside () parenthesis are captured. When it comes to replacing the match the new value is created by first inserting the captured value at the position marked by &#8216;$1&#8242;. This way it it possible to, let&#8217;s say insert a new char in the middle of a search pattern &#8211; if it fulfills certain conditions.</p>
<p>There appears to be an error in the MSDN documentation, unfortunately at the point describing how to reference captures in Visual Studio regexp replace patterns. Anyway, using the &#8216;$&#8217; char in conjunction with the index is the common way and it works here just fine.</p>
<p>Multiple captures are possible as well. Just refer to the captured content by the index according to the count of &#8216;()&#8217; captures in the search pattern.</p>
<p>The Visual Studio regexp support is really helpful when translating huge C header files to C# &#8211; to name only one situations. It saved me a huge amount of time already. Hope you find this useful too.</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/fun-with-visual-studio-regexp-search-and-replace/">Fun with Visual Studio regexp search</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/fun-with-visual-studio-regexp-search-and-replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ILNumerics for Science &#8211; Computation and Visualization</title>
		<link>https://ilnumerics.net/blog/ilnumerics-for-science-computation-and-visualization/</link>
		<comments>https://ilnumerics.net/blog/ilnumerics-for-science-computation-and-visualization/#comments</comments>
		<pubDate>Mon, 30 Mar 2015 13:42:01 +0000</pubDate>
		<dc:creator><![CDATA[Jonas]]></dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Scientific Computing]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=882</guid>
		<description><![CDATA[<p>How did you do that? – The Computation Wrapping up our series of ILNumerics and science we take a closer look at computation and science. Easily code your science into a robust, reliable program with high-speed performance. Science of Function Rules Now that we’re 3 posts in this series I have to address something our &#8230; <a href="https://ilnumerics.net/blog/ilnumerics-for-science-computation-and-visualization/" class="more-link">Continue reading <span class="screen-reader-text">ILNumerics for Science &#8211; Computation and Visualization</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-science-computation-and-visualization/">ILNumerics for Science &#8211; Computation and Visualization</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>How did you do that? – The Computation</h2>
<p style="text-align: justify;">Wrapping up our series of ILNumerics and science we take a closer look at computation and science. Easily code your science into a robust, reliable program with high-speed performance.</p>
<p style="text-align: justify;"><span id="more-882"></span></p>
<h3>Science of Function Rules</h3>
<p style="text-align: justify;">Now that we’re 3 posts in this series I have to address something our support team and our development team told me to: Function Rules. These are important for computation in science because they speed things up.</p>
<p style="text-align: justify;">We encourage everybody to follow these rules because it makes your code faster and more readable. If you follow the function rules you give the computation engine more information about the intended use of the arrays you declare. There are four types:</p>
<ol>
<li style="text-align: justify;">Local arrays: They are declared and used only in the function scope. After leaving the function the memory is released and can be reused.</li>
<li style="text-align: justify;">Input arrays: These are the input parameters to a function. They are immutable and should be used only once when copied to a local array.</li>
<li style="text-align: justify;">Output arrays: With this option many different arrays can be returned to the calling function. In the calling function an array must be declared and passed to the called function.</li>
<li style="text-align: justify;">Return arrays: These arrays are the return values of functions. They are erased immediately after usage.</li>
</ol>
<p style="text-align: justify;">What I found most interesting are the output arrays. In the header of the function I can declare a number of output arrays. However, they are optional. When I call this function I don’t need to pass any of these to the function. If an output array is omitted that means that I’m not interested in this particular array. The function will then only calculate the arrays that I’m interested in and omit the rest of the code. This is a powerful tool to save development time and run time &#8211; and gets you back to science quicker.</p>
<h3>Computation Module</h3>
<p style="text-align: justify;">Now, let’s get back to our 2D particle in a box. We still need to add the computation module. This is easily done by right-clicking on your WindowsFormsApplication in the solution explorer and adding the computation module. This will create a class called Computing_Module1 that is derived from ILMath. It comes with a few example functions where you can see some examples of the function rules.</p>
<p>Here is again the code that will calculate the wave function on a grid:</p>
<pre class="brush: csharp; title: ; notranslate">
public static ILRetArray&lt;double&gt; CalcWF(int EVXID, int EVYID, double LX, double LY, int MeshSize)
{
   ILArray&lt;double&gt; X = linspace&lt;double&gt;(0, LX, MeshSize);
   ILArray&lt;double&gt; Y = linspace&lt;double&gt;(0, LY, MeshSize);
   ILArray&lt;double&gt; Y2d = 1;
   ILArray&lt;double&gt; X2d = meshgrid(X, Y, Y2d);
   ILArray&lt;double&gt; Z = sqrt(4.0 / LX / LY) * sin(EVXID * pi * X2d / LX) * sin(EVYID * pi * Y2d / LY);
   return Z.Concat(X2d,2).Concat(Y2d,2);
}
</pre>
<p style="text-align: justify;">I put everything in one function here but will now separate the code into more than one function to show how the function rules should be applied. I’ll keep the CalcWF function and will add two more functions. One function will calculate the meshgrid and the other function will actually calculate the wave function values on the grid.</p>
<pre class="brush: csharp; title: ; notranslate">
public static void getGrid(ILInArray&lt;double&gt; inX, ILInArray&lt;double&gt; inY, ILOutArray&lt;double&gt; outX2d = null, ILOutArray&lt;double&gt; outY2d = null)
{
   using (ILScope.Enter(inX, inY))
   {
      ILArray&lt;double&gt; X = check(inX);
      ILArray&lt;double&gt; Y = check(inY);
      outY2d.a = 1;
      outX2d.a = meshgrid(X, Y, outY2d);
      return;
   }
}
</pre>
<p style="text-align: justify;">This piece of code generates the grid over which the wave function will be calculated. I obeyed all function rules here. Obviously, this is not really necessary for such a small problem but I wanted to show the best practice here. This function basically gives back two arrays, outX2d and outY2d. This is only possible with ILOutArray as functions can only return one object.</p>
<pre class="brush: csharp; title: ; notranslate">
public static ILRetArray&lt;double&gt; getWF(int EVXID, int EVYID, double LX, double LY, ILInArray&lt;double&gt; inX2d, ILInArray&lt;double&gt; inY2d)
{
   using (ILScope.Enter(inX2d, inY2d))
   {
      ILArray&lt;double&gt; X2d = check(inX2d);
      ILArray&lt;double&gt; Y2d = check(inY2d);
      return sqrt(4.0 / LX / LY) * sin(EVXID * pi * X2d / LX) * sin(EVYID * pi * Y2d / LY);
   }
}
</pre>
<p style="text-align: justify;">This function will calculate the values of the wave function on a given grid. Declaring the return value as ILRetArray will make sure that the array that is calculated in the last line will be thrown away after the function is executed.</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-science-computation-and-visualization/">ILNumerics for Science &#8211; Computation and Visualization</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/ilnumerics-for-science-computation-and-visualization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HDF5 and Matlab Files &#8211; Fun with ILNumerics</title>
		<link>https://ilnumerics.net/blog/hdf5-and-matlab-files-fun-with-ilnumerics/</link>
		<comments>https://ilnumerics.net/blog/hdf5-and-matlab-files-fun-with-ilnumerics/#comments</comments>
		<pubDate>Thu, 19 Mar 2015 08:12:25 +0000</pubDate>
		<dc:creator><![CDATA[Balázs]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[array visualizer]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[h5dataset]]></category>
		<category><![CDATA[h5file]]></category>
		<category><![CDATA[HDF5]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[mat]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=790</guid>
		<description><![CDATA[<p>Why to use HDF5 and ILNumerics? HDF5 is a file format (Hierarchical Data Format) especially desgined to handle huge amount of numerical data. Just to mention an example,  NASA chose it to be the standard file format for storing data from the Earth Observing System (EOS). ILNumerics easily handles HDF5 files. They can be used &#8230; <a href="https://ilnumerics.net/blog/hdf5-and-matlab-files-fun-with-ilnumerics/" class="more-link">Continue reading <span class="screen-reader-text">HDF5 and Matlab Files &#8211; Fun with ILNumerics</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/hdf5-and-matlab-files-fun-with-ilnumerics/">HDF5 and Matlab Files &#8211; Fun with ILNumerics</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>Why to use HDF5 and ILNumerics?</h3>
<p style="text-align: justify;">HDF5 is a file format (Hierarchical Data Format) especially desgined to handle huge amount of numerical data. Just to mention an example,  NASA chose it to be the standard file format for storing data from the Earth Observing System (EOS).</p>
<p style="text-align: justify;">ILNumerics easily handles HDF5 files. They can be used to exchange data with other software tools, for example Matlab mat files. In this post I will show a step by step guide &#8211; how to interface ILNumerics with Matlab.</p>
<p style="text-align: justify;"><span id="more-790"></span></p>
<h3>Save Matlab data to HDF5 format</h3>
<p style="text-align: justify;">Let&#8217;s start by creating some arbitrary data with Matlab and saving it in HDF5 format, Matlab supports it from 2006 September, version 7.3.</p>
<pre class="brush: matlabkey; title: ; notranslate">
matrix = randn(10, 10) * 5;
vector = [1 2 3 4 5]';
carr = 'It is a char array!';
noise = rand(1,100) - rand(1, 100);
sinus = 10 * sin(linspace(0, 2*pi, 100)) + noise;
complex = rand(1, 5) * (10 + 10i);
save('test_hdf5.mat', '-v7.3');
</pre>
<h3>Load Matlab data with ILNumerics</h3>
<p>Let&#8217;s now see what ILNumerics sees <img src="https://ilnumerics.net/blog/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /></p>
<figure id="attachment_791" style="width: 408px;" class="wp-caption alignnone"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/1.png"><img class="wp-image-791 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/1.png" alt="ILNumerics HDF5 File peek view" width="408" height="228" /></a><figcaption class="wp-caption-text">Children datasets of H5File</figcaption></figure>
<p style="text-align: justify;">Matlab simply stored all arrays as individual datasets in the root node of the HDF5 file. It is now easily possible to access the data! We could take a peek and inspect them right within the Visual Studio debugger visualizers. But let’s see how the data is loaded programmatically:</p>
<pre class="brush: csharp; title: ; notranslate">
// Reading from Matlab
using (H5File file = new H5File(&quot;test_hdf5.mat&quot;))
{
    using (ILScope.Enter())
    {
        ILArray&lt;double&gt; matrix = file.Get&lt;H5Dataset&gt;(&quot;matrix&quot;).Get&lt;double&gt;();
        ILArray&lt;double&gt; vector = file.Get&lt;H5Dataset&gt;(&quot;vector&quot;).Get&lt;double&gt;();
        ILArray&lt;char&gt; carr = file.Get&lt;H5Dataset&gt;(&quot;carr&quot;).Get&lt;char&gt;();
        ILArray&lt;double&gt; noise = file.Get&lt;H5Dataset&gt;(&quot;noise&quot;).Get&lt;double&gt;();
        ILArray&lt;double&gt; sinus = file.Get&lt;H5Dataset&gt;(&quot;sinus&quot;).Get&lt;double&gt;();
    }
}

</pre>
<p style="text-align: justify;">The datasets are loaded &#8211; and the whole process was very easy. It took me less than ten minutes to figure out the methods. It would have been even less if I had take a look on the <a href="http://ilnumerics.net/examples.php">examples</a> of ILNumerics <img src="https://ilnumerics.net/blog/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /></p>
<p style="text-align: justify;">Now, let&#8217;s startup the <a title="ILNumerics Array Visualizer" href="http://ilnumerics.net/Visual-Studio-Graphical-Debugger.html">Array Visualizer</a>! Just write &#8216;array&#8217; in the Quick Launch box of Visual Studio, or open a new visualizer window via VIEW -&gt; OTHER WINDOWS -&gt; Array Visualizer. In the visualizer expression field enter: &#8216;sinus&#8217;. The array is now visualized, how cool is that <img src="https://ilnumerics.net/blog/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /></p>
<h3><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/33.png"><img class="alignnone wp-image-825 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/33.png" alt="ILNumerics Array Visualizer - Drawing local array on the fly" width="664" height="662" /></a></h3>
<h3>Visualizing Matlab mat files &#8211; on the fly</h3>
<p style="text-align: justify;">Now we have shown the content of the variable &#8216;sinus&#8217;. Just as well, we could visualize the content of the HDF5 file and have the visualizer follow any changes to it immediately:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/5.png"><img class="alignnone wp-image-826 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/5.png" alt="ILNumerics Array Visualizer - Reading HDF5 file" width="639" height="425" /></a></p>
<p style="text-align: justify;">If we multiply it with -1, the expression is immediately evaluated:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/6.png"><img class="alignnone wp-image-827 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/6.png" alt="ILNumerics Array Visualizer - Expression evaluation on the fly" width="639" height="425" /></a></p>
<p style="text-align: justify;">And what is even more interesting, if we change the HDF5 file interactively, in the immediate window, the ILNumerics Array Visualizer reflects that on the fly:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/7.png"><img class="alignnone wp-image-829 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/7.png" alt="Manipulating HDF5 file content in immediate window" width="607" height="131" /></a> <a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/8.png"><img class="alignnone wp-image-828 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/8.png" alt="ILNumerics Array Visualizer - Reading HDF5 content on the fly" width="639" height="425" /></a></p>
<h3>Loading ILArrays into Matlab</h3>
<p style="text-align: justify;">Now let us check, what happens if we want to go from ILNumerics to Matlab. Saving a noise cosine with the following code:</p>
<pre class="brush: csharp; title: ; notranslate">
// Writing some data to HDF5
// Note: It will not make it a proper mat file, only HDF5!
if (File.Exists(&quot;test_iln.mat&quot;))
    File.Delete(&quot;test_iln.mat&quot;);

using (H5File newFile = new H5File(&quot;test_iln.mat&quot;))
{
    using (ILScope.Enter())
    {
        ILArray&lt;double&gt; noisyCos = ILMath.cos(ILMath.linspace(0, 3 * Math.PI, 1000)) * 10 + ILMath.rand(1, 1000);
        H5Dataset set = new H5Dataset(&quot;noisyCos&quot;, noisyCos);
        newFile.Add(set);
    }
}
</pre>
<p style="text-align: justify;">Since the ILNumerics HDF5 is not a mat file format, the only way to load it (as for now) is with one of the &#8216;h5*&#8217; methods of Matlab. To check the info and load, the following code is used:</p>
<pre class="brush: matlabkey; title: ; notranslate">
h5info('test_iln.mat', '/')
noisyCos = h5read('test_iln.mat', '/noisyCos');
</pre>
<p>In this way, it is possible to load ILArrays into Matlab <img src="https://ilnumerics.net/blog/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /></p>
<h3>Altering Matlab mat files in ILNumerics</h3>
<p style="text-align: justify;">It is possible to alter loaded mat files with some limitations. What I found is that the length of the array can not be changed. Obviously, Matlab mat files are created as datasets without chunks, so the dataspace size cannot be changed after the file was created. However, one can alter the data (without changing the size) :</p>
<pre class="brush: csharp; title: ; notranslate">
// Altering data of mat file (v7.3 format)
using (H5File file = new H5File(&quot;test_hdf5.mat&quot;))
{
    using (ILScope.Enter())
    {
        ILArray&lt;double&gt; sinus = file.Get&lt;H5Dataset&gt;(&quot;sinus&quot;).Get&lt;double&gt;();
        sinus.a = sinus * -1;
        file.Get&lt;H5Dataset&gt;(&quot;sinus&quot;).Set(sinus, &quot;0;:&quot;);
    }
}
</pre>
<p>Let me draw your attention to the use of the Set function here. I first tried to use:</p>
<pre class="brush: csharp; title: ; notranslate">
file.Get&lt;H5Dataset&gt;(&quot;dsname&quot;).Set(A);
</pre>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/4.png"><img class="alignnone wp-image-810 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/4.png" alt="HDF5 file altering Matlab data" width="804" height="546" /></a></p>
<p style="text-align: justify;">But this would attempt to overwrite the whole dataset &#8211; something which could potentially change the size, hence would require a chunked dataset. Therefore, I figured that I have to be more specific and need to provide the target data range also:</p>
<pre class="brush: csharp; title: ; notranslate">
file.Get&lt;H5Dataset&gt;(&quot;sinus&quot;).Set(sinus, &quot;0;:&quot;)
</pre>
<h3>More Limitations</h3>
<p>Out of curiosity I checked the complex array, to see if it is okay.</p>
<figure id="attachment_792" style="width: 656px;" class="wp-caption alignnone"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/03/2.png"><img class="wp-image-792 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/03/2.png" alt="Loading complex from Matlab" width="656" height="208" /></a><figcaption class="wp-caption-text">Loading a complex vector from mat file</figcaption></figure>
<p style="text-align: justify;">Unfortunately it throws a H5Exception, this is something I will look into and work on. Fixing this problem will require support for compound datatypes in our HDF5 API.</p>
<h3>Try out the example</h3>
<p>To play with it, head to the examples and download the code:<br />
<a title="Reading and Writing Matlab data with ILNumerics" href="http://ilnumerics.net/examples.php?exid=80c65dd5478b9726d6313eed9ef7d241" target="_blank">Reading and Writing Matlab data with ILNumerics</a></p>
<h3>Conclusion</h3>
<p style="text-align: justify;">To sum up, it is possible and easy to load data stored in Matlab mat files to ILNumerics with the HDF5 IO handling, and it is also possible to load ILArrays to Matlab as well.</p>
<p style="text-align: justify;">I am opened to suggestions and feedback, looking forward to hearing from you! Share your experiences with us, so we can learn from you!</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/hdf5-and-matlab-files-fun-with-ilnumerics/">HDF5 and Matlab Files &#8211; Fun with ILNumerics</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/hdf5-and-matlab-files-fun-with-ilnumerics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ILNumerics for Science &#8211; How did you do the Visualization?</title>
		<link>https://ilnumerics.net/blog/ilnumerics-for-scientists-how-did-you-do-the-visualization/</link>
		<comments>https://ilnumerics.net/blog/ilnumerics-for-scientists-how-did-you-do-the-visualization/#comments</comments>
		<pubDate>Mon, 02 Feb 2015 16:35:03 +0000</pubDate>
		<dc:creator><![CDATA[Jonas]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[3d visualization]]></category>
		<category><![CDATA[plots]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=772</guid>
		<description><![CDATA[<p>In the third part of our series we focus on the visualization of scientific data. You learn how to easily display your data with ILNumerics and the ILPanels. Reactions I got a lot of emails after the last two posts (first, second) of people that liked the post and are interested in learning more. Most &#8230; <a href="https://ilnumerics.net/blog/ilnumerics-for-scientists-how-did-you-do-the-visualization/" class="more-link">Continue reading <span class="screen-reader-text">ILNumerics for Science &#8211; How did you do the Visualization?</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-scientists-how-did-you-do-the-visualization/">ILNumerics for Science &#8211; How did you do the Visualization?</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In the third part of our series we focus on the visualization of scientific data. You learn how to easily display your data with ILNumerics and the ILPanels.</p>
<p><span id="more-772"></span></p>
<h3>Reactions</h3>
<p style="text-align: justify;">I got a lot of emails after the last two posts (<a title="ILNumerics for Scientists – An easy start" href="http://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/">first</a>, <a title="ILNumerics for Scientists – Going 3D" href="http://ilnumerics.net/blog/ilnumerics-for-scientists/">second</a>) of people that liked the post and are interested in learning more. Most emails asked me to go into more details about how I did all that. Obviously, not too many people are interested in implementing the particle in a box, so the “what” is not as interesting as the “how”.</p>
<p style="text-align: justify;">In this post I want to focus on the visualization part of the previous two examples and how <a href="http://ilnumerics.net">ILNumerics </a>helped me. As many of our users are scientists and engineers they are typically experts in the computation part but appreciate a little help in the visualization. If you&#8217;re interested in the computation part, please be patient until the next post.</p>
<h3>The Form</h3>
<p style="text-align: justify;">I started by creating a new project in Visual Studio and chose Windows Forms Application. This gives me a vanilla Form1.cs. That’s the basis of all the visualization and helps me – being a scientist and not a coder – a lot, because I couldn’t do all that without the help of Visual Studio in the background.</p>
<p style="text-align: justify;">On the left-hand side in the Toolbox panel I picked TableLayoutPanel under Containers and dragged it into Form1.cs.</p>
<p style="text-align: justify;"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/02/firstimage.png"><img class="alignnone size-full wp-image-775" src="http://ilnumerics.net/blog/wp-content/uploads/2015/02/firstimage.png" alt="firstimage" width="421" height="379" /></a></p>
<p style="text-align: justify;">I adjusted the table to have three rows and a single column. In the Properties section under Dock I chose Fill so that everything scales when scaling the window later on.</p>
<p style="text-align: justify;"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/02/secondimage.png"><img class="alignnone size-full wp-image-777" src="http://ilnumerics.net/blog/wp-content/uploads/2015/02/secondimage.png" alt="secondimage" width="404" height="475" /></a></p>
<p style="text-align: justify;">A right click on Table -&gt; Edit Rows and Columns allows you to change the behavior of the three rows. I wanted the first and last row not to scale when changing the window. This is what I chose here.</p>
<p style="text-align: justify;"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/02/thirdimage.png"><img class="alignnone size-full wp-image-779" src="http://ilnumerics.net/blog/wp-content/uploads/2015/02/thirdimage.png" alt="thirdimage" width="730" height="481" /></a></p>
<p style="text-align: justify;">In the middle row we would like to see two ILNumerics panels. So I dragged another TableLayoutPanel in the middle row and chose two columns and one row. Choosing Dock = Fill for the new table and dragging two ILPanels into the respective columns (again with Dock = Fill) gives us the layout for our final Windows Form.</p>
<p style="text-align: justify;"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/02/fourthimage.png"><img class="alignnone size-full wp-image-776" src="http://ilnumerics.net/blog/wp-content/uploads/2015/02/fourthimage.png" alt="fourthimage" width="685" height="623" /></a></p>
<p style="text-align: justify;">In the header (the first row) I inserted a FlowLayoutPanel that makes sure that everything in there will be displayed rather neatly. Then I added the labels and the NumericUpDown according to my needs. Please make sure that you go through the properties of every item and choose the values according to your needs. In my case, for instance, the minimum value for the state is 1, since 0 would mean that there is no particle present. Here is the final picture of the form for the 1D particle in a box:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/02/fifthimage.png"><img class="alignnone size-full wp-image-774" src="http://ilnumerics.net/blog/wp-content/uploads/2015/02/fifthimage.png" alt="fifthimage" width="935" height="660" /></a></p>
<h3>The Wiring</h3>
<p style="text-align: justify;">After having the layout ready the interactivity needs to be implemented. In this case there is only one point of user interaction. The user can choose which eigenvector to display. Double-clicking on the NumericUpDown control opens a new tab with a predefined class and a function handling the event when a user changes the value of the eigenvector.</p>
<p style="text-align: justify;"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/02/sixthimage.png"><img class="alignnone size-full wp-image-778" src="http://ilnumerics.net/blog/wp-content/uploads/2015/02/sixthimage.png" alt="sixthimage" width="589" height="477" /></a></p>
<p style="text-align: justify;">All that’s needed now is to implement the function numericUpDown1_ValueChanged. This is particularly simple in our case. We just call the Update function (still to be implemented) with the new value for the eigenvector.</p>
<p style="text-align: justify;">In the case of the 2D particle in a box we have, in fact, four events that should trigger the Update function. This is easily done by introducing these lines of code in the public function Form1():</p>
<pre class="brush: csharp; title: ; notranslate">
     numericUpDown1.ValueChanged += Update;
     numericUpDown2.ValueChanged += Update;
     numericUpDown3.ValueChanged += Update;
     textBox1.TextChanged += Update;
</pre>
<h3 style="text-align: left;">The Implementation</h3>
<p style="text-align: justify;">Now, all we need to do is to implement the Update function and the initialization. The initialization makes sure that all the plotting objects are created when starting the program.</p>
<pre class="brush: csharp; title: ; notranslate">
     public Form1()
     {
        InitializeComponent();

        var EVID = 1;
        var MeshSize = 1000;

        InitializePanel1(EVID, MeshSize);
        InitializePanel2(EVID, MeshSize);

        label2.Text = string.Format(&quot;In appropriate units the energy is {0}&quot;, EVID * EVID);
     }

     private void InitializePanel1(int EVID, int MeshSize)
     {
        ILArray&lt;float&gt; XY = ILMath.tosingle(Computing_Module1.CalcWF(EVID, MeshSize));
        var color = Color.Black;
        ilPanel1.Scene =
          new ILScene {
            new ILPlotCube {
              new ILLinePlot (XY, lineColor : color)
            }
          };
     }
</pre>
<p style="text-align: justify;">The call to Computing_Module1.CalcWF will be explained in the next post. The piece of code above initializes the wave function plot and the density plot in their respective panels with the first eigenvector and a mesh size of 1000.</p>
<p>Finally, the Update function is implemented.</p>
<pre class="brush: csharp; title: ; notranslate">
     private void Update(int EVID, int MeshSize = 1000)
     {
       ILArray&lt;float&gt; XY = ILMath.tosingle(Computing_Module1.CalcWF(EVID, MeshSize));
       ilPanel1.Scene.First&lt;ILLinePlot&gt;().Update(XY);
       ilPanel1.Scene.First&lt;ILPlotCube&gt;().Reset();
       ilPanel1.Refresh();

       ILArray&lt;float&gt; XD = ILMath.tosingle(Computing_Module1.CalcDensity(EVID, MeshSize));
       ilPanel2.Scene.First&lt;ILLinePlot&gt;().Update(XD);
       ilPanel2.Scene.First&lt;ILPlotCube&gt;().Reset();
       ilPanel2.Refresh();
       label2.Text = string.Format(&quot;In appropriate units the energy is {0}&quot;, EVID * EVID);
     }
</pre>
<p style="text-align: justify;">Again, the CalcWF and CalcDensity calls will be explained in the next post. The Reset() function rescales the axes and the Refresh() function finally puts the new plot on screen.</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-scientists-how-did-you-do-the-visualization/">ILNumerics for Science &#8211; How did you do the Visualization?</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/ilnumerics-for-scientists-how-did-you-do-the-visualization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ILNumerics for Scientists &#8211; Going 3D</title>
		<link>https://ilnumerics.net/blog/ilnumerics-for-scientists/</link>
		<comments>https://ilnumerics.net/blog/ilnumerics-for-scientists/#comments</comments>
		<pubDate>Tue, 20 Jan 2015 15:38:39 +0000</pubDate>
		<dc:creator><![CDATA[Jonas]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Interesting/ useless]]></category>
		<category><![CDATA[Scientific Computing]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[3d visualization]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[Getting Started]]></category>
		<category><![CDATA[Quantum Mechanics]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=761</guid>
		<description><![CDATA[<p>Recap Last time I started with one of the easiest problems in quantum mechanics: the particle in a box. This time I’ll add 1 dimension and we’ll see a particle in a 2D box. To visualize its wave function and density we need 3D surface plots. 2D Box This time we have a particle that &#8230; <a href="https://ilnumerics.net/blog/ilnumerics-for-scientists/" class="more-link">Continue reading <span class="screen-reader-text">ILNumerics for Scientists &#8211; Going 3D</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-scientists/">ILNumerics for Scientists &#8211; Going 3D</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>Recap</h3>
<p style="text-align: justify;"><a title="ILNumerics for Scientists – An easy start" href="http://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/">Last time </a>I started with one of the easiest problems in quantum mechanics: the particle in a box. This time I’ll add 1 dimension and we’ll see a particle in a 2D box. To visualize its wave function and density we need 3D surface plots.</p>
<h3>2D Box</h3>
<p style="text-align: justify;">This time we have a particle that is confined in a 2D box. The potential within the box is zero and outside the box infinity. Again the solution is well-known and can be found on <a href="https://en.wikipedia.org/wiki/Particle_in_a_box">Wikipedia</a>. This time the state of the wave function is determined by two numbers. These are typically called quantum numbers and refer to the X and the Y direction, respectively.</p>
<p style="text-align: justify;">The absolute size of the box doesn’t really matter and we didn’t worry about it in the 1D case. However, the relative size of the length and the width make a difference. The solution to our problem reads</p>
<p style="text-align: center;">$\Psi_{n,k}(x,y) = \sqrt{\frac{4}{L_x L_y}} \cdot \sin(n \cdot \pi \cdot x / L_x) \cdot \sin(k \cdot \pi \cdot y / L_y)$</p>
<h3>The Math</h3>
<p style="text-align: justify;">Very similar to the 1D case I quickly coded the wave function and the density for further plotting. I had to make sure that the arrays are fit for 3D plotting, so the code looks a little bit different compared to last post’s</p>
<pre class="brush: csharp; title: ; notranslate">
     public static ILArray&lt;double&gt; CalcWF(int EVXID, int EVYID, double LX, double LY, int MeshSize)
     {
        ILArray&lt;double&gt; X = linspace&lt;double&gt;(0, LX, MeshSize);
        ILArray&lt;double&gt; Y = linspace&lt;double&gt;(0, LY, MeshSize);

        ILArray&lt;double&gt; Y2d = 1;
        ILArray&lt;double&gt; X2d = meshgrid(X, Y, Y2d);

        ILArray&lt;double&gt; Z = sqrt(4.0 / LX / LY) * sin(EVXID * pi * X2d / LX) * sin(EVYID * pi * Y2d / LY);

        return Z.Concat(X2d,2).Concat(Y2d,2);
     }
</pre>
<p>Again, this took me like 10 minutes and I was done.</p>
<h3>The Visualization</h3>
<p>This time the user can choose the quantum numbers for X and Y direction, the ratio between the length and the width of the box and also the number of mesh points along each axis for plotting. This makes the visualization panel a little bit more involved. Nevertheless, it’s still rather simple and easy to use. This time it took me only 45 minutes – I guess I learned a lot from last time.</p>
<h3>The result</h3>
<p>Here is the result of my little program. You can click and play with it. If you’re interested, you can download the <a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/Particle2DBox.zip">Particle2DBox</a> source code. Have fun!</p>
<p style="text-align: justify;"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/Particle2DBox.jpg"><img class="aligncenter wp-image-767 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/01/Particle2DBox.jpg" alt="Particle2DBox" width="928" height="640" /></a>This is a screenshot of the application. I chose the second quantum number along the x axis and the fourth quantum number along the y axis. The box is twice as long in y direction as it is in x direction. The mesh size is 100 in each direction. On the left hand side you see the wave function and on the right hand side the probability density.</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-scientists/">ILNumerics for Scientists &#8211; Going 3D</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/ilnumerics-for-scientists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Directions to the ILNumerics Optimization Toolbox</title>
		<link>https://ilnumerics.net/blog/directions-to-the-ilnumerics-optimization-toolbox/</link>
		<comments>https://ilnumerics.net/blog/directions-to-the-ilnumerics-optimization-toolbox/#comments</comments>
		<pubDate>Wed, 14 Jan 2015 16:27:44 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Scientific Computing]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[Getting Started]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[Toolbox]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=738</guid>
		<description><![CDATA[<p>As of yesterday the ILNumerics Optimization Toolbox is out and online! It&#8217;s been quite a challenge to bring everything together: some of the best algorithms, the convenience you as a user of ILNumerics expect and deserve, and the high performance requirements ILNumerics sets the scale on for. We believe that all these goals could be &#8230; <a href="https://ilnumerics.net/blog/directions-to-the-ilnumerics-optimization-toolbox/" class="more-link">Continue reading <span class="screen-reader-text">Directions to the ILNumerics Optimization Toolbox</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/directions-to-the-ilnumerics-optimization-toolbox/">Directions to the ILNumerics Optimization Toolbox</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>As of yesterday the ILNumerics Optimization Toolbox is out and online! It&#8217;s been quite a challenge to bring everything together: some of the best algorithms, the convenience you as a user of ILNumerics expect and deserve, and the high performance requirements ILNumerics sets the scale on for. We believe that all these goals could be achieved quite greatly.</p>
<p><span id="more-738"></span></p>
<p>During a lengthy beta phase we received a whole bunch of precise and enormous helpful feedback from you. We really appreciate that and again would like to say thanks!</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/Optim_Camel_LBFGS.png"><img class="aligncenter size-full wp-image-747" src="http://ilnumerics.net/blog/wp-content/uploads/2015/01/Optim_Camel_LBFGS.png" alt="Optim_Camel_LBFGS" width="1026" height="868" /></a>ILNumerics Optimization Toolbox adds a number of functions to ILNumerics, useful to find solutions of common optimization problems. Since everything is nicely integrated into ILNumerics it helps you solve the problem easily and very efficiently. Optimization applications like the one shown as screenshot above can now get realized in a couple of minutes!</p>
<p>This blog post sheds some light on the very first steps for using the new Optimization Toolbox. It helps you to start quickly and lists some common documentation sources.</p>
<h2>Obtaining the Optimization Toolbox</h2>
<p>The optimization toolbox is available as a dedicated package and so must be individually purchased and installed. ILNumerics 4.6 or above is needed for that to work. Existing customers can evaluate the new toolbox by installing an extended trial on top of your existing ILNumerics Ultimate VS installation. Just <a href="mailto:sales@ilnumerics.net">let us know</a> and we will lead you the way to the download. Another option is the trial: it includes all toolboxes, hence you can start right away by <a href="http://ilnumerics.net/download.html">downloading</a> and installing a trial of ILNumerics Ultimate VS and get familiar with all optimization methods easily.</p>
<h2>Optimization Toolbox Setup</h2>
<p>The optimization toolbox obviously depends on the ILNumerics Computation Engine. It installs the managed assemblies ILNumerics.Optimization.dll into the GAC and also makes them available inside Visual Studio as reference to your application projects:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2015-01-14-16_26_48-Reference-Manager-ConsoleApplication18.png"><img class="aligncenter size-full wp-image-740" src="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2015-01-14-16_26_48-Reference-Manager-ConsoleApplication18.png" alt="2015-01-14 16_26_48-Reference Manager - ConsoleApplication18" width="700" height="351" /></a>Afterwards, the ILNumerics.Optimization class is found in the ILNumerics namespace which commonly is included in your source files anyway. A super-mini but complete starting example in a fresh new C# console application could look as follows:</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using ILNumerics; 

namespace ConsoleApplication1 {
    class Program : ILMath {

        static ILRetArray&lt;double&gt; myObjFunc(ILInArray&lt;double&gt; A) {
            using (ILScope.Enter(A)) {
                return sum((A - 1) * A);
            }
        }
        static void Main(string[] args) {
            ILArray&lt;double&gt; M = Optimization.fmin(myObjFunc, ones(1,4));
            Console.WriteLine(M);
        }
    }
}

</pre>
<p>Note how we derived our console class from ILNumerics.ILMath! This allows us to omit the namespace.class identifier and &#8216;ILMath.sum&#8217; and &#8216;ILMath.ones&#8217; become just: &#8216;sum&#8217; and &#8216;ones&#8217;.</p>
<p>If you are lucky enough to use Visual Studio 2015, it will allow you the inclusion of the static ILNumerics.Optimization class into your &#8216;using&#8217; directives on top of your source code files also. This will inject all public functions of the Optimization class into your scope also which gives an even shorter syntax. &#8216;fmin&#8217; and all other optimization functions are now readily available right next to the common ILMath functions:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2015-01-14-16_44_19-ConsoleApplication1-Debugging-Microsoft-Visual-Studio.png"><img class="aligncenter size-full wp-image-743" src="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2015-01-14-16_44_19-ConsoleApplication1-Debugging-Microsoft-Visual-Studio.png" alt="2015-01-14 16_44_19-ConsoleApplication1 (Debugging) - Microsoft Visual Studio" width="661" height="373" /></a>That&#8217;s it already! Happy optimizing!</p>
<h2>Optimization Examples</h2>
<p>A number of example applications have been added to the <a href="http://ilnumerics.net/examples.php">examples section</a>. Basically, they accompany the corresponding <a href="/ilnumerics-optimization-toolbox.html">online documentation</a> and let you follow the tutorials step by step on your own machine.</p>
<p>In order to start with an example application, you download the example as a zip package and extract it into a new folder on your local machine. Open the &#8216;*.csproj&#8217; contained in the example package with Visual Studio. You will notice missing references in the References node of your project in the Solution Explorer:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2015-01-14-17_03_38-.png"><img class="aligncenter size-full wp-image-744" src="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2015-01-14-17_03_38-.png" alt="2015-01-14 17_03_38-" width="386" height="523" /></a>Just remove these old references and replace them with references to the files actually installed on your system – using the common method described above.</p>
<p>Hit F5 and run the example!</p>
<h2>Documentation</h2>
<p>The ILNumerics Optimization Toolbox online documentation is available here:</p>
<p><a href="http://ilnumerics.net/ilnumerics-optimization-toolbox.html">http://ilnumerics.net/ilnumerics-optimization-toolbox.html</a></p>
<p>The API /class documentation for all functions of ILNumerics.Optimization is available here:</p>
<p><a href="http://ilnumerics.net/apidoc/?topic=html/T_ILNumerics_Optimization.htm">http://ilnumerics.net/apidoc/?topic=html/T_ILNumerics_Optimization.htm</a></p>
<h2>Wrap up</h2>
<p>We gave a short introduction in how to obtain and install ILNumerics Optimization Toolbox for ILNumerics Computing Engine. We pointed you to the common places of examples and documentation.</p>
<p>If you run into trouble or have useful suggestions and feedback, <a href="/direct-support.html">let us know</a>! Contact <a href="mailto:sales@ilnumerics.net">sales@ilnumerics.net</a> for any licensing questions.</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2014-12-19-17_06_40-Iterations-BFGS_-8-L-BFGS_-22.png"><img class="aligncenter size-full wp-image-739" src="http://ilnumerics.net/blog/wp-content/uploads/2015/01/2014-12-19-17_06_40-Iterations-BFGS_-8-L-BFGS_-22.png" alt="2014-12-19 17_06_40-Iterations BFGS_ 8 L-BFGS_ 22" width="1026" height="805" /></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/directions-to-the-ilnumerics-optimization-toolbox/">Directions to the ILNumerics Optimization Toolbox</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/directions-to-the-ilnumerics-optimization-toolbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ILNumerics for Scientists &#8211; An easy start</title>
		<link>https://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/</link>
		<comments>https://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/#comments</comments>
		<pubDate>Wed, 07 Jan 2015 16:05:43 +0000</pubDate>
		<dc:creator><![CDATA[Jonas]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Scientific Computing]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[Getting Started]]></category>
		<category><![CDATA[Quantum Mechanics]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=714</guid>
		<description><![CDATA[<p>Motivation I’ve been working as a scientist at universities for 10 years before deciding to go into industry. The one thing I hated most was coding. At the end of the day coding for scientists is like running for a football player. Obviously, you need it but it’s not what you’re here for. I really &#8230; <a href="https://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/" class="more-link">Continue reading <span class="screen-reader-text">ILNumerics for Scientists &#8211; An easy start</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/">ILNumerics for Scientists &#8211; An easy start</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>Motivation</h3>
<p style="text-align: justify;">I’ve been working as a scientist at universities for 10 years before deciding to go into industry. The one thing I hated most was coding. At the end of the day coding for scientists is like running for a football player. Obviously, you need it but it’s not what you’re here for.</p>
<p style="text-align: justify;">I really dreaded the coding and the debugging. So much precious time for something that was so clear on paper and I just wanted the solution of my equations to see whether my idea made sense or not. More often than not scientists find that their idea was not so great and now they had spent so much time coding just to find out that the idea didn’t work.<span id="more-714"></span></p>
<p style="text-align: justify;">To make things worse even in the case that the idea was good the code was typically in a scripted language like Python or Matlab and now needed to be rewritten in Fortran or C++. Isn’t there a better way of doing things? Isn’t there a way where the idea creation and the formulation is the bottle neck and not the coding? I could’ve spent so much more time on valuable thinking instead of senseless coding.</p>
<p style="text-align: justify;">Now, obviously, I’m going to tell you how ILNumerics does exactly that. And, obviously, I do that because I work for them. Still, this is my experience and this is how easy it was. And at the end of the day, you’re not going to buy our product because of this blog post, rather because you downloaded our <a href="http://ilnumerics.net/download.html">free trial</a> and convinced yourself.</p>
<h3 style="text-align: justify;">The Problem</h3>
<p style="text-align: justify;">Let’s start with one of the simplest problems in quantum mechanics – the particle in a box. This is a quantum mechanical particle in a potential-free box with an infinite potential outside the box. In other words, the particle is forced to stay within the box. Anybody unfamiliar with this problem can read the <a href="https://en.wikipedia.org/wiki/Particle_in_a_box">Wikipedia article </a>about this.</p>
<p style="text-align: justify;">The solution to this problem is well-known and can be found analytically. As always in quantum mechanics, the solution is quantized with infinitely many solutions – also known as states. Each of the solutions consists of a wave function associated with a corresponding energy.</p>
<p style="text-align: center;">$\Psi_n(x) = \sqrt{\frac{2}{L}} \sin(n \cdot \pi \cdot  x)$</p>
<p style="text-align: justify;">In the equation above $n$ designates the $n^{th}$ state and $L$ is the length of the box, set to 1 in our case.</p>
<h3 style="text-align: justify;">The Goal</h3>
<p style="text-align: justify;">My goal is to display the wave function and the probability density of a user-chosen state. I choose a simple problem and a simple goal because I’m just getting started. Obviously, this is not one of the problems I faced as a scientist in my earlier life, but it is a nice example.</p>
<h3 style="text-align: justify;">The Solution</h3>
<p style="text-align: justify;">Let’s start with the mathematical part. First I implemented the wave function for a given state. As the wave function is supposed to be plotted it is discretized over a mesh. Here is my body of my function:</p>
<pre class="brush: csharp; title: ; notranslate">
     ILArray&lt;double&gt; X = linspace&lt;double&gt;(0,1,MeshSize);
     ILArray&lt;double&gt; Y = sqrt(2.0)*sin(EVID*pi*X);
     return vertcat(X,Y);
</pre>
<p style="text-align: justify;">The parameter EVID is the eigenvector ID, i.e. an integer greater than 0 to identify which state should be calculated. I coded the same for the density, which basically means squaring the wave function stored in vector Y.</p>
<p>Done in less than 10 minutes!!!</p>
<h3>The Graphs</h3>
<p style="text-align: justify;">The rest is all about the presentation to the user. So I created a simple Windows Form with a numeric up/down counter (to allow the user to choose the state) and two panels for simple line plots. I just needed to wire all the components to make sure that the plots were rescaled and updated after the user changes the state. This took me some more time, because it was the first time for me. Still it took me only 60 minutes and done.</p>
<h3>The Result</h3>
<p style="text-align: justify;">Here you can find the result of my simple little program. You can download the <a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/ParticleBoxBest.zip" target="_blank">source code</a> and play with it. Have fun!</p>
<p style="text-align: center;"><a href="http://ilnumerics.net/blog/wp-content/uploads/2015/01/ParticleInABox.png"><img class="alignnone wp-image-715 size-full" src="http://ilnumerics.net/blog/wp-content/uploads/2015/01/ParticleInABox.png" alt="ParticleInABox" width="900" height="603" /></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/">ILNumerics for Scientists &#8211; An easy start</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/ilnumerics-for-scientists-an-easy-start/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting to know your Scene Graph</title>
		<link>https://ilnumerics.net/blog/getting-to-know-your-scene-graph/</link>
		<comments>https://ilnumerics.net/blog/getting-to-know-your-scene-graph/#comments</comments>
		<pubDate>Mon, 29 Dec 2014 12:21:09 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[groups]]></category>
		<category><![CDATA[scene graph]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=703</guid>
		<description><![CDATA[<p>Did you ever miss a certain feature in your ILNumerics scene graph? You probably did. But did you know, that most of the missing &#8220;features&#8221; mean nothing more than a missing &#8220;property&#8221;? Often enough, there is only a convenient access to a certain scene graph object needed in order to finalize a required configuration. Recently, &#8230; <a href="https://ilnumerics.net/blog/getting-to-know-your-scene-graph/" class="more-link">Continue reading <span class="screen-reader-text">Getting to know your Scene Graph</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/getting-to-know-your-scene-graph/">Getting to know your Scene Graph</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Did you ever miss a certain feature in your <a href="/Visualization-API.html">ILNumerics scene graph</a>? You probably did. But did you know, that most of the missing &#8220;features&#8221; mean nothing more than a missing &#8220;property&#8221;? Often enough, there is only a convenient access to a certain scene graph object needed in order to finalize a required configuration.</p>
<p>Recently, a user asked how to turn the background of a legend object in ILNumerics plots transparent. There doesn&#8217;t seem to be a straight forward way to that. One might expect code like the following to work:</p>
<pre class="brush: csharp; title: ; notranslate">
var legend = new ILLegend(&quot;Line 1&quot;, &quot;Line 2&quot;);
legend.Background.Color = Color.FromArgb(200, Color.White);
</pre>
<p><span id="more-703"></span>Unfortunately, it does not. Legend objects do not implement a &#8216;Background&#8217; property which would give convenient access to the background object. However, the background object obviously exists. And ILLegend &#8211; likewise most of the more complex scene graph / plotting objects in ILNumerics &#8211; is derived from ILGroup! <a href="http://ilnumerics.net/group-nodes.html">Group nodes</a> represent the common way to store and manage any number of child objects. At the same time, group nodes gives the user flexible access to their children.<br />
In case of ILLegend we can utilize one of the access methods of ILGroup in order to access the scene graph node which implements the background of the legend. Once we have the background object, we can go out and manipulate it freely. In order to do that, let&#8217;s first investigate, which nodes exist inside a legend object!</p>
<h2>Stepping into living Scene Graphs</h2>
<p>ILNumerics and Visual Studio make it very easy to investigate even complex scenes. Let&#8217;s create a simple line plot application first! We start with a fresh new C# Windows Forms Application and add a Plotting Form Template to it. A detailed instruction is given on the getting started page, at &#8220;<a href="/Getting-Started-with-ILNumerics.html">Creating Visualizations with ILNumerics</a>&#8220;.<br />
Double click on the auto-generated Program.cs file and change the last line to read:</p>
<pre class="brush: csharp; title: ; notranslate">
    Application.Run(new Plotting_Form1());
</pre>
<p>Starting the project via F5 brings up the newly generated example plot. We make one more addition. Double click the Plotting_Form1.cs to show the form in the designer. Now, double click on the white panel1 background to go to the code implementing the scene setup. At the end of the code creating the new plot cube and adding the line plot we add another line which adds a new legend object:</p>
<pre class="brush: csharp; title: ; notranslate">
// Initial plot setup, modify this as needed
private void ilPanel1_Load(object sender, EventArgs e) {

    // create some test data, using our private computation module as inner class
    ILArray&lt;float&gt; Pos = Computation.CreateData(4, 300);

    // setup the plot (modify as needed)
    ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
        new ILLinePlot(Pos, tag: &quot;mylineplot&quot;) {
            Line = {
                Width = 2,
                Color = Color.Red,
                Antialiasing = true,
                DashStyle = DashStyle.Dotted
            }
        }, new ILLegend(&quot;MyLineItem&quot;)
    });
    // register event handler for allowing updates on right mouse click:
    ilPanel1.Scene.First&lt;ILLinePlot&gt;().MouseClick += (_s, _a) =&gt; {
        if (_a.Button == MouseButtons.Right)
            Update(ILMath.rand(3, 30));
    };
}
</pre>
<p>Starting via F5 should give a form similar like this:<br />
<a href="http://ilnumerics.net/blog/wp-content/uploads/2014/12/PlotFormPlain.png"><img class="aligncenter size-full wp-image-704" src="http://ilnumerics.net/blog/wp-content/uploads/2014/12/PlotFormPlain.png" alt="PlotFormPlain" width="675" height="562" /></a>Now, let&#8217;s start the fun! Investigating living objects works best when the objects are alive, right? So let&#8217;s set a breakpoint in Visual Studio right after the legend has been created:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/12/2014-12-29-12_51_22-WindowsFormsApplication4-Debugging-Microsoft-Visual-Studio.png"><img class="aligncenter size-full wp-image-705" src="http://ilnumerics.net/blog/wp-content/uploads/2014/12/2014-12-29-12_51_22-WindowsFormsApplication4-Debugging-Microsoft-Visual-Studio.png" alt="2014-12-29 12_51_22-WindowsFormsApplication4 (Debugging) - Microsoft Visual Studio" width="655" height="292" /></a>As you know, Visual Studio allows for a nice feature &#8216;Edit and Continue&#8217;. Let&#8217;s add a variable as reference to our legend right in Debug mode! This is not really necessary, but eases the inspection. Note, it does not matter, where to add the code line, as long as we step over it in the debugger:</p>
<pre class="brush: csharp; title: ; notranslate">
    var leg = ilPanel1.Scene.First&lt;ILLegend&gt;();
</pre>
<p>Scene graph nodes are clever enough to give reasonable insights into their state and content at runtime. Just hover over the newly created variable &#8216;leg&#8217; with the mouse and Visual Studio will display helpful debugger visualizers. Expand any node to show its content:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/12/2014-12-29-12_57_16-WindowsFormsApplication4-Debugging-Microsoft-Visual-Studio.png"><img class="aligncenter size-full wp-image-706" src="http://ilnumerics.net/blog/wp-content/uploads/2014/12/2014-12-29-12_57_16-WindowsFormsApplication4-Debugging-Microsoft-Visual-Studio.png" alt="2014-12-29 12_57_16-WindowsFormsApplication4 (Debugging) - Microsoft Visual Studio" width="616" height="306" /></a>Inspecting the legend object that way makes it immediately clear, which object legends are made out of: a triangle shape realizes the background, a line strip shape the border. A common group holds the individual legend items and will be filled dynamically at rendering time.</p>
<h2>Configuration Flexibility at its Extreme</h2>
<p>Having access to every single child item in the scene graph obviously brings an extreme flexibility for configurations. Now it is easy to change the color of the background object to make the legend transparent:</p>
<pre class="brush: csharp; title: ; notranslate">
var leg = ilPanel1.Scene.First&lt;ILLegend&gt;();
leg.First&lt;ILTriangles&gt;(&quot;ScreenObjectBackground&quot;).Color = Color.FromArgb(200, Color.White);
</pre>
<p>Which gives us our transparent legend:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/12/2014-12-29-13_10_50-Form1.png"><img class="aligncenter size-full wp-image-707" src="http://ilnumerics.net/blog/wp-content/uploads/2014/12/2014-12-29-13_10_50-Form1.png" alt="2014-12-29 13_10_50-Form1" width="520" height="253" /></a></p>
<h2>Do not stop here!</h2>
<p>This is the message to take away: any object in any visualization and any plot in ILNumerics is composed out of individual smaller objects. You can access them and manipulate them freely without limits! Most &#8216;convenience&#8217; properties like &#8220;colorbar.Background&#8221; barely do more than we have done here: they give easy access to inner children (and add Intellisense support, of course). But if you need access &#8211; you can easily gain it yourself by inspecting the scene graph and its objects by the methods described here.</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/getting-to-know-your-scene-graph/">Getting to know your Scene Graph</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/getting-to-know-your-scene-graph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uncommon data conversion with ILArray</title>
		<link>https://ilnumerics.net/blog/uncommon-data-conversion-with-ilarray/</link>
		<comments>https://ilnumerics.net/blog/uncommon-data-conversion-with-ilarray/#comments</comments>
		<pubDate>Tue, 07 Oct 2014 08:42:14 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[ILArray]]></category>
		<category><![CDATA[pointer arithmetic]]></category>
		<category><![CDATA[unsafe]]></category>
		<category><![CDATA[ushort]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=635</guid>
		<description><![CDATA[<p>ILNumerics Computing Engine supports the most common numeric data types out of the box: double, float, complex, fcomplex, byte, short, int, long, ulong If you need to convert from, let&#8217;s say ushort to float, you will not find any prepared conversion function in ILMath. Luckily, it is very easy to write your own: Here comes &#8230; <a href="https://ilnumerics.net/blog/uncommon-data-conversion-with-ilarray/" class="more-link">Continue reading <span class="screen-reader-text">Uncommon data conversion with ILArray</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/uncommon-data-conversion-with-ilarray/">Uncommon data conversion with ILArray</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>ILNumerics Computing Engine supports the most common numeric data types out of the box: double, float, complex, fcomplex, byte, short, int, long, ulong</p>
<p>If you need to convert from, let&#8217;s say ushort to float, you will not find any prepared conversion function in ILMath. Luckily, it is very easy to write your own:</p>
<p>Here comes a method which implements the conversion from ushort -&gt; float. A straight forward version first:</p>
<pre class="brush: csharp; title: ; notranslate">
        /// &lt;summary&gt;
        /// Convert ushort data to ILArray&amp;lt;float&gt;
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;A&quot;&gt;Input Array&lt;/param&gt;
        /// &lt;returns&gt;Array of the same size as A, single precision float elements&lt;/returns&gt;
        public static ILRetArray&lt;float&gt; UShort2Single(ILInArray&lt;ushort&gt; A) {
            using (ILScope.Enter(A)) {
                ILArray&lt;float&gt; ret = ILMath.zeros&lt;float&gt;(A.S);
                var retArr = ret.GetArrayForWrite();
                var AArr = A.GetArrayForRead();
                int c = 0;
                foreach (ushort a in A) {
                    retArr[c++] = a;
                }
                return ret;
            }
        }</pre>
<p><span id="more-635"></span>This method is used like that:</p>
<pre class="brush: csharp; title: ; notranslate">
            ushort[,] rawSensorData = new ushort[,] {{0,1,2},{3,4,5}};
            ILArray&lt;float&gt; converted = UShort2Single(rawSensorData);
            /*
             * &lt;Single&gt; [3,2]
             * [0]:          0          3
             * [1]:          1          4
             * [2]:          2          5
             */

            // continue working with 'converted' here...
</pre>
<p>The following method does the same but utilizes pointer arithmetic, hence it needs the /unsafe flag. Use this, if performance is critical and your data are sufficiently large:</p>
<pre class="brush: csharp; title: ; notranslate">
        /// &lt;summary&gt;
        /// Convert ushort data to ILArray&amp;lt;float&gt; (unsafe version)
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;A&quot;&gt;Input Array&lt;/param&gt;
        /// &lt;returns&gt;Array of the same size as A, single precision float elements&lt;/returns&gt;
        public unsafe static ILRetArray&lt;float&gt; UShort2SingleUnsafe(ILInArray&lt;ushort&gt; A) {
            using (ILScope.Enter(A)) {
                ILArray&lt;float&gt; ret = ILMath.zeros&lt;float&gt;(A.S);
                var retArr = ret.GetArrayForWrite();
                var AArr = A.GetArrayForRead();

                fixed (ushort* pAArr = AArr)
                fixed (float* pRetArr = retArr) {
                    ushort* pInWalk = pAArr;
                    ushort* pInEnd = pAArr + A.S.NumberOfElements;
                    float* pRetWalk = pRetArr;
                    while (pInWalk &lt; pInEnd) {
                        *(pRetWalk++) = /*implicit: (float)*/ (*(pInWalk++));
                    }
                }
                return ret;
            }
        }</pre>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/uncommon-data-conversion-with-ilarray/">Uncommon data conversion with ILArray</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://ilnumerics.net/blog/uncommon-data-conversion-with-ilarray/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
