<?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; .NET</title>
	<atom:link href="https://ilnumerics.net/blog/category/net/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>ILNumerics: High Performance as Default</title>
		<link>https://ilnumerics.net/blog/ilnumerics-high-performance-as-default/</link>
		<comments>https://ilnumerics.net/blog/ilnumerics-high-performance-as-default/#comments</comments>
		<pubDate>Mon, 01 Apr 2024 11:25:09 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Scientific Computing]]></category>
		<category><![CDATA[accelerator]]></category>
		<category><![CDATA[autonomous]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[v7]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=1091</guid>
		<description><![CDATA[<p>ILNumerics releases Version 7.0 The ILNumerics team is proud and excited to announce the availability of a new major release of its ILNumerics Ultimate VS product line. This milestone represents a significant advancement in compiler technology: it introduces the first autonomously parallelizing array compiler, ILNumerics Accelerator. Array codes, such as numpy and Matlab, are popular within &#8230; <a href="https://ilnumerics.net/blog/ilnumerics-high-performance-as-default/" class="more-link">Continue reading <span class="screen-reader-text">ILNumerics: High Performance as Default</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-high-performance-as-default/">ILNumerics: High Performance as Default</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>ILNumerics releases Version 7.0</h2>
<p>The ILNumerics team is proud and excited to announce the availability of a new major release of its ILNumerics Ultimate VS product line. This milestone represents a significant advancement in compiler technology: it introduces the first autonomously parallelizing array compiler, ILNumerics Accelerator.</p>
<p>Array codes, such as numpy and Matlab, are popular within the scientific community. They simplify the description of complex numerical algorithms. However, when these numerical codes are implemented into industrial-grade products, distributed to customers, and maintained by a larger development team for many years, existing tools reveal considerable limitations, with execution speed being possibly the greatest limitation.</p>
<p>ILNumerics Accelerator is here to resolve this issue once and for all. Built on the convenient language of ILNumerics Computing Engine for authoring scientific array codes directly in C# /.NET, our intelligent Accelerator compiler reformulates array codes and executes them in the most efficient manner, unguided and autonomously.</p>
<h2>Short Dive: Building an Array Compiler &#8230;</h2>
<p>The key to optimal hardware utilization today is, of course, the ability to efficiently parallelize the workload. Therefore, ILNumerics Accelerator compiler automatically detects and utilizes parallel potential within subsequent array instructions of your algorithm.</p>
<p>The prevalent approach to automatic parallelization today involves analyzing your code to detect instructions that can execute in parallel. The code is then rewritten to allow these independent instructions to run concurrently. This approach originated at a time when C/C++ and FORTRAN were considered &#8216;high-level&#8217; languages. While these languages offer some basic array support, numerical algorithms written in them inherently deal with <em>scalar</em> data.</p>
<p>In contrast, the algorithms we handle use n-dimensional arrays as the fundamental data type. When striving for real efficiency, the arrays&#8217; complexity prohibits any compile-time decision about data independence, a suitable execution device, or a low-level implementation using vector instructions, among other factors. Too many variables determine the optimal execution strategy, and their variation is too extensive to identify at development time.</p>
<h2>&#8230; with a fresh Approach to Parallelization &#8230;</h2>
<p>ILNumerics takes a data-driven approach to parallelization, making all crucial decisions &#8216;just in time&#8217; at <em>runtime</em>. This method enables us to implement the low-level internals of array instructions efficiently and eliminates the need for expensive dependency analysis of large program segments. It&#8217;s easier to determine at runtime whether an instruction relies on other data and when that data will be available.</p>
<p>However, this increases the compiler&#8217;s complexity significantly. Instead of producing fixed code for an array instruction found in the original program, we now generate an intermediate program, often representing several subsequent array instructions. This intermediate program is then transformed at runtime to reflect the original instructions in a manner that respects all influencing factors and enables optimal efficiency.</p>
<h2>&#8230; with Intelligence and Freedom</h2>
<p>These programs all run asynchronously, scheduling themselves onto suitable devices for execution at runtime. They connect with previous and subsequent asynchronous neighbors on the fly, even as they progress in calculating results. They autonomously determine the optimal implementation on the device they select. Significant decision-making power comes with immense responsibility. The final program code builds up asynchronously and autonomously at runtime.</p>
<p>Executing the same code branch twice may result in very different machine instructions. As the creators of the compiler, we can&#8217;t predict many details of the final implementation. We can&#8217;t even forecast the actual number of asynchronous programs, which we refer to as segments, executing concurrently. The decision now rests with the computer. It has a better understanding of the situation than we do and can process information and make educated decisions much faster and more effectively.</p>
<h2>Why another Beta, then?</h2>
<p>The first autonomous array compiler has arrived. Are you eager to try it out? Great! <a title="Getting Started: ILNumerics Accelerator" href="https://ilnumerics.net/accelerate-sum-examples.html" target="_blank">Go ahead and test</a> the current beta from nuget.org. Its performance is genuinely impressive.</p>
<p>The majority of our users are building industrial products and have chosen ILNumerics for its reliability and seamless integration into .NET (which means all of .NET, since 2005). The compiler will become a regular part of the ILNumerics Computing Engine once it&#8217;s ready. Currently, it&#8217;s like a young child, learning new things each day. It&#8217;s learning to walk and talk, occasionally stumbling over previously unknown obstacles. Sometimes, it even surprises its creators with unexpected efficiency.</p>
<p>With recent advancements, the Accelerator compiler is now set to &#8216;always on&#8217; mode. This marks a significant milestone in the development of a compiler. It&#8217;s now trusted to be stable and flexible enough to handle all codes, even unseen ones, ensuring it produces correct results and serves its primary purpose: to enhance efficiency.</p>
<p>The compiler will continue to <a title="Roadmap: ILNumerics Accelerator Compiler" href="https://ilnumerics.net/roadmap.html" target="_blank">develop</a> until the final release. It will become more <a title="State if the Art: Progressing Development of Accelerator Compiler" href="https://ilnumerics.net/accelerator-limitations.html" target="_blank">stable</a> and gain more real-world exposure. We would greatly appreciate if your feedback contributes to its maturity by then.</p>
<p>All previous modules of ILNumerics have been adapted for the new Accelerator. They are thoroughly tested, have undergone many <a title="ILNumerics Changelog" href="https://ilnumerics.net/changelog.html">bugfixes and improvements</a>, and are available for production on nuget.org as of today.</p>
<hr />
<p>&nbsp;</p>
<p>Introducing the ILNumerics Accelerator:</p>
<div style="width: 474px; " class="wp-video"><!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->
<video class="wp-video-shortcode" id="video-1091-1" width="474" height="267" preload="metadata" controls="controls"><source type="video/mp4" src="https://ilnumerics.net/media/andere/ILNumerics_Segments_2022.mp4?_=1" /><a href="https://ilnumerics.net/media/andere/ILNumerics_Segments_2022.mp4">https://ilnumerics.net/media/andere/ILNumerics_Segments_2022.mp4</a></video></div>
<p>[ Video does not show? Download here: <a href="/media/andere/ILNumerics_Segments_2022.mp4">https://ilnumerics.net/media/andere/ILNumerics_Segments_2022.mp4</a> ]</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/ilnumerics-high-performance-as-default/">ILNumerics: High Performance as Default</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-high-performance-as-default/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="https://ilnumerics.net/media/andere/ILNumerics_Segments_2022.mp4" length="1709355" type="video/mp4" />
		</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>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>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>Fun with HDF5, ILNumerics and Excel</title>
		<link>https://ilnumerics.net/blog/fun-with-hdf5-ilnumerics-and-excel/</link>
		<comments>https://ilnumerics.net/blog/fun-with-hdf5-ilnumerics-and-excel/#comments</comments>
		<pubDate>Sat, 29 Nov 2014 16:19:45 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[HDF5]]></category>
		<category><![CDATA[Office]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=663</guid>
		<description><![CDATA[<p>It is amazing how many complex business processes in major industries today are supported by a tool that shines by its simplicity: Microsoft Excel. &#8216;Recently&#8217; (with Visual Studio 2010) Microsoft managed to polish the development tools for all Office applications significantly. The whole Office product line is now ready to serve as a convenient, flexible &#8230; <a href="https://ilnumerics.net/blog/fun-with-hdf5-ilnumerics-and-excel/" class="more-link">Continue reading <span class="screen-reader-text">Fun with HDF5, ILNumerics and Excel</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/fun-with-hdf5-ilnumerics-and-excel/">Fun with HDF5, ILNumerics and Excel</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>It is amazing how many complex business processes in major industries today are supported by a tool that shines by its simplicity: Microsoft Excel. &#8216;Recently&#8217; (with Visual Studio 2010) Microsoft managed to polish the development tools for all Office applications significantly. The whole Office product line is now ready to serve as a convenient, flexible base framework for stunning custom business logic, custom computations and visualizations &#8211; with just a little help of tools like <a href="http://ilnumerics.net">ILNumerics</a>.</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/11/ExcelWorkbook1.png"><img class="aligncenter size-full wp-image-664" src="http://ilnumerics.net/blog/wp-content/uploads/2014/11/ExcelWorkbook1.png" alt="ExcelWorkbook1" width="1118" height="594" /></a>In this blog post I am going to show how easy it is to extend the common functionality of Excel. We will enable an Excel Workbook to load arbitrary <a href="http://www.hdfgroup.org/">HDF5</a> data files, inspect the content of such files and show the data as interactive 2D or 3D plots. <span id="more-663"></span>HDF5 is an industry standard for the structured storage of technical data and is maintained by the <a href="http://www.hdfgroup.org/">HDF Group</a>. With version 4.0 <a href="http://ilnumerics.net">ILNumerics </a>supports the HDF5 file format with a very convenient, object oriented API. Visualizations have always been a popular feature since the early days of ILNumerics. And Excel can be another convenient GUI tool to marry both.</p>
<h2>Prerequisites</h2>
<p>Customizations like the one we are going to show are done in Visual Studio and utilize <a href="http://msdn.microsoft.com/en-us/library/jj620922.aspx">Visual Studio Tools for Office (VSTO)</a>. If you don&#8217;t own a copy of Visual Studio, you may find it useful that Microsoft gives away their <a href="http://www.visualstudio.com/en-us/products/free-developer-offers-vs.aspx">flagship for free</a> under certain conditions. Another prerequisite we will need: Office 2010 or 2013. I use Office 2010 on my computer. For some reason, Visual Studio 2013 did not allow me to create a new Workbook project for the 2010 version of Office and rather requested Office 2013. Therefore, I used Visual Studio 2012 instead. Just make sure to use the version of Office which is supported by your Visual Studio installation.</p>
<p>The last ingredient needed is ILNumerics. <a href="http://ilnumerics.net/download.html">Download the free trial</a> &#8211; it contains all features and tools you may possibly want and makes them available systemwide.</p>
<h2>Setup</h2>
<p>Let&#8217;s start with a fresh new Workbook project in Visual Studio:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/11/NewProject.png"><img class="aligncenter size-full wp-image-666" src="http://ilnumerics.net/blog/wp-content/uploads/2014/11/NewProject.png" alt="NewProject" width="955" height="660" /></a>We take all defaults here. This will create a new Visual Studio project with three worksheets, ready for your customizations. Double click on Sheet1.cs to open the designer view.  In the Visual Studio Toolbox find the ILNumerics section and drag a new instance of ILPanel onto your sheet:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/11/Workbook1_VisualStudioDesigner.png"><img class="aligncenter size-full wp-image-667" src="http://ilnumerics.net/blog/wp-content/uploads/2014/11/Workbook1_VisualStudioDesigner.png" alt="Workbook1_VisualStudioDesigner" width="1334" height="885" /></a>This will add the reference of ILNumerics to your project and places the ILPanel control on your sheet. You may want to resize and reposition the control. It will be available from now on as &#8216;iLNumerics_Drawing_ILPanel1&#8242; in your code-behind classes. Feel free to adjust the name &#8211; for this demonstration we will leave it as it is.</p>
<p>&nbsp;</p>
<h2>Loading HDF5 Files in Excel</h2>
<p>Excel does not support HDF5 file imports directly (yet?). Luckily, ILNumerics bridges the gap very efficiently and conveniently. First, we add a reference to the HDF5 assembly which comes with ILNumerics. In the last step the reference to ILNumerics was added automagically. For HDF5 we have to do this manually. Right click on the References tab in the solution explorer and chose: Add Reference. Now search for &#8220;HDF5&#8243; on your system, select the item found and hit &#8220;OK&#8221;:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/11/AddHDF5Reference.png"><img class="aligncenter size-full wp-image-668" src="http://ilnumerics.net/blog/wp-content/uploads/2014/11/AddHDF5Reference.png" alt="AddHDF5Reference" width="776" height="350" /></a>If no item was found, make sure you have installed the latest ILNumerics package using our installer and that you selected the Assemblies tab in the Reference Manager window.</p>
<p>Once we have the HDF5 assembly available, we can start coding. The idea is, that the user should be able to load an HDF5 file from disk, inspect the datasets contained and get the option to load and/or visualize their data. So, let&#8217;s add some more controls from the toolbox to the workbook sheet: OpenFileDialog and a button to trigger the opening. Drag the button (Common Controls in the Toolbox) and the OpenFileDialog (Dialogs tab in the Toolbox) to the designer surface:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/11/DragButtonOFDDesigner.png"><img class="aligncenter size-full wp-image-669" src="http://ilnumerics.net/blog/wp-content/uploads/2014/11/DragButtonOFDDesigner.png" alt="DragButtonOFDDesigner" width="906" height="560" /></a><br />
Now, rename the new button and double click it to open the auto-generated event handler method. This is where we are going to implement the code to open and inspect the HDF5 file:</p>
<pre class="brush: csharp; title: ; notranslate">
private void button1_Click(object sender, EventArgs e) {
    var fod = new OpenFileDialog();
    if (fod.ShowDialog() == DialogResult.OK) {

        var filename = fod.FileName;
        // access the HDF5 file for reading
        using (var file = new H5File(filename, accessMode: FileAccess.Read)) {
            int row = 4; // start listing at row 4
            // list all datasets in the file
            foreach (var ds in file.Find&lt;H5Dataset&gt;()) {
                Cells[row,   3].Value = ds.Path;
                Cells[row++, 4].Value = ds.Size.ToString();
            }
            while (row &lt; 100) {
                Cells[row, 3].Value = &quot;&quot;;
                Cells[row++, 4].Value = &quot;&quot;;
            }
            // display filename
            Cells[2, 4].Value = filename;
        }
    }
}
</pre>
<p>First, we ask for the filename to open. If the user provided a valid filename we open the file for reading. HDF5 files in ILNumerics are used in &#8216;using&#8217; blocks. No matter how you leave the block, ILNumerics ensures that the file is not left open. Read <a href="http://ilnumerics.net/hdf5-interface.html">here for more details</a>.<br />
Once we have the HDF5 file we start iterating over its datasets. C# foreach constructs make that really easy. Other languages have similar constructs. Inside the foreach loop we simply write out the path of the current dataset and its size to columns of the worksheet.<br />
The while loop afterwards is only needed to clear entries potentially left over from earlier loadings. This expects no more than 100 datasets in a file. In a production code, you will do better&#8230;<br />
Finally, the name of the HDF5 file is written into cell[2,4] for user information.</p>
<p>If we now run the workbook (hit F5) and click on our &#8220;Load HDF5 Dataset&#8221; button a file dialog opens up. Once we select an existing HDF5 file from our disk the file&#8217;s datasets are listed on the worksheet:<br />
<a href="http://ilnumerics.net/blog/wp-content/uploads/2014/11/FirstRun.png"><img class="aligncenter size-full wp-image-671" src="http://ilnumerics.net/blog/wp-content/uploads/2014/11/FirstRun.png" alt="FirstRun" width="464" height="478" /></a></p>
<h2>Loading HDF5 Dataset Content</h2>
<p>Next, register a new event handler for the double click event in the worksheet. The worksheet template offers a good place to do so: the Sheet1_Startup event handler is auto generated by Visual Studio. Add the following line in order to allow to react to double click events on the sheet:</p>
<pre class="brush: csharp; title: ; notranslate">
this.BeforeDoubleClick += Sheet1_BeforeDoubleClick;
</pre>
<p>The implementation of the Sheet1_BeforeDoubleClick method does all the work:</p>
<pre class="brush: csharp; title: ; notranslate">
void Sheet1_BeforeDoubleClick(Excel.Range Target, ref bool Cancel) {
    // only take cells we are interested in
    if (Target.Value == null || Cells[2, 4].Value == null) return;
    // grab the hdf5 filename from the cell
    var curFilename = Cells[2, 4].Value.ToString();
    // check if this points to an existing file
    if (File.Exists(curFilename)) {
        // grab the dataset name (if the user clicked on it)
        var dsName = ((object)Target.Value).ToString();
        // reasonable?
        if (Target.Count == 1 &amp;&amp; !String.IsNullOrEmpty(dsName)) {
            // open the file
            using (var file = new H5File(curFilename, accessMode: FileAccess.Read)) {
                // find the dataset in the file, we provide the full abs. path so we
                // are sure that there is only one such dataset
                var ds = file.First&lt;H5Dataset&gt;(dsName);
                if (ds != null) {
                    // add a new sheet with the name of the dataset
                    var sheet = (Excel.Worksheet)Globals.ThisWorkbook.Sheets.Add();
                    sheet.Name = checkName(dsName);
                    // ... and make it active
                    Globals.ThisWorkbook.Sheets[sheet.Name].Activate();
                    // load data using our extension method (see text)
                    sheet.Set(ds.Get&lt;double&gt;());
                } else {
                    // user has clicked on the size column -&gt; plot the data
                    var size = ParseSize(dsName);
                    if (size != null &amp;&amp; Target.Previous.Value != null) {
                        dsName = ((object)Target.Previous.Value).ToString();
                        // read data and render into panel
                        renderDS(file, dsName);
                    }
                }
            }
        }
    }
}
</pre>
<p>This is all straight forward: we do some very simple error checking here, just to make sure we only react to clicks on interesting columns. In your production code you will do much better error checking! However, here we decide if the user has clicked on a cell with a valid dataset name. If so, the file is opened (fetching the name from the HDF5 filename cell written to earlier), the dataset is located and its content loaded.<br />
The content is written to a new workbook sheet. Attention must be drawn to the naming of the sheet. If a sheet with a similar name exists already, Excel will throw an exception. One easy solution is to add the timestamp to the name, which is left as an exercise. Here, we only do very simple name checking to make sure, no invalid characters enter the name of the sheeet:</p>
<pre class="brush: csharp; title: ; notranslate">
string checkName(string name) {
    var ret = name.Replace('/','_');
    if (ret.Length &gt; 31) {
        ret = ret.Substring(-31);
    }
    return ret;
}
</pre>
<p>The method to actually load the data from an ILArray to the new sheet is found in the following extension method. This is one rather efficient attempt to load large data:</p>
<pre class="brush: csharp; title: ; notranslate">
public static void Set(this Worksheet worksheet, ILInArray&lt;double&gt; A, int fromColumn = 1, int fromRow = 1) {
    using (ILScope.Enter(A)) {

        var luCell = worksheet.Cells[fromRow, fromColumn];
        var rbCell = worksheet.Cells[fromRow + A.S[0] - 1, fromColumn + A.S[1] - 1];
        Range range = worksheet.Range[luCell, rbCell];
        range.Value = A.T.ToSystemMatrix();
    }
}

private static System.Array ToSystemMatrix&lt;T&gt;(this ILDenseArray&lt;T&gt; A) {
    using (ILScope.Enter(A)) {
        // some error checking (to be improved...)
        if (object.Equals(A, null)) throw new ArgumentException(&quot;A may not be null&quot;);
        if (!A.IsMatrix) throw new ArgumentException(&quot;Matrix expected&quot;);

        // create return array
        System.Array ret = Array.CreateInstance(typeof(T), A.S.ToIntArray().Reverse().ToArray());
        // fetch underlying system array
        T[] workArr = A.GetArrayForRead();
        // copy memory block
        Buffer.BlockCopy(workArr, 0, ret, 0, Marshal.SizeOf(typeof(T)) * A.S.NumberOfElements);
        return ret;
    }
}
</pre>
<p>Set() creates the range in the sheet to load the data into. The size is computed by the size of the incoming ILArray&lt;T&gt;. In order to load the data, we do not want to iterate over each<br />
individual cell for performance reasons. One option is to set the Value property of the range to a two dimensional System.Array. ToSystemArray() does exactly that conversion. However, you have to<br />
be careful not to get transposed data unexpectedly. The reason is that .NET multidimensional arrays are stored in row major order. ILNumerics on the other hand stores arrays in the same order as Matlab, FORTRAN and other technical tools do. Hence, we need to transpose our data before we assign them to the range. Read more details <a href="http://stackoverflow.com/a/19636778 /1215993">here</a>.</p>
<p>Now, when we run the application and load a HDF5 file, we can double click on the cell holding a dataset name and have Excel load the dataset contents into a new worksheet &#8211; fast. This can be easily adopted by defining ranges (hyperslabs) and only load partial datasets. Also you can adopt the method described here for writing worksheet contents to HDF5 datasets.</p>
<h2>Visualizing HDF5 Dataset Contents</h2>
<p>Now let&#8217;s add another nice feature to our workbook: instead of simply loading the data from a dataset to the worksheet, we add the option of creating interactive, fully configurable and fast visualizations and plots of the data. We&#8217;ll use the predefined plot classes of ILNumerics Visualization Engine here.</p>
<p>Back to the double click event handler created earlier, we left out the path which is executed once the user clicked on the size displayed next to each dataset. What happens here is also straightforward.</p>
<p>First we parse the size to see, if it gives something reasonable (again, you&#8217;ll add better error checking for a production release). If so, we give the HDF5 file together with the dataset name to the renderDS() method which does the rendering:</p>
<pre class="brush: csharp; title: ; notranslate">
private void renderDS(H5File file, string dsName) {
    var ds = file.First&lt;H5Dataset&gt;(dsName);
    if (ds != null) {
        using (ILScope.Enter()) {
            ILArray&lt;float&gt; A = ds.Get&lt;float&gt;();
            if (A.IsVector) {
                iLNumerics_Drawing_ILPanel1.Scene = new ILScene() {
                    new ILPlotCube(twoDMode: true) {
                        new ILLinePlot(A, markerStyle: MarkerStyle.Diamond, lineWidth: 2)
                    }
                };
            } else if (A.IsMatrix) {
                iLNumerics_Drawing_ILPanel1.Scene = new ILScene() {
                    new ILPlotCube(twoDMode: false) {
                        new ILSurface(A, colormap: Colormaps.Hot) {
                            UseLighting = true
                        }
                    }
                };
            }
            iLNumerics_Drawing_ILPanel1.Refresh();
        }
    }
}
</pre>
<p>This code does not need commenting. It fetches the dataset and loads its content into an ILArray&lt;float&gt;. A new scene replaces the existing one in the worksheet ILPanel. The new scene contains a <a href="http://ilnumerics.net/plot-cube-properties.html">plot cube</a> and a line plot or a <a href="http://ilnumerics.net/surface-plots.html">surface plot</a>. Which one is created depends on the shape of the data. Vector sized data create a lineplot, matrices are rendered as a surface plot. In order to have the new scene show up, we must trigger a refresh on the panel.<br />
<a href="http://ilnumerics.net/blog/wp-content/uploads/2014/11/WorkbooksLines.png"><img class="aligncenter size-full wp-image-673" src="http://ilnumerics.net/blog/wp-content/uploads/2014/11/WorkbooksLines.png" alt="WorkbooksLines" width="877" height="602" /></a>Now, run the workbook, load a HDF5 file having some vector and/or matrix sized datasets, select a dataset by double clicking on its <em>size</em> cell. The plot is created according to the data. Like all visualizations in ILNumerics we can interact with the data: rotation/ zoom /pan is done with the left/right mouse buttons. And of course, you are free to apply any of the very flexible configuration options in order to <a href="http://ilnumerics.net/visualization-engine.html">customize your plots</a> further. For line plots this includes: <a href="http://ilnumerics.net/line-plots.html#markers">markers</a>, <a href="http://ilnumerics.net/line-plots.html#customizing-line-properties">dash styles</a>, <a href="http://ilnumerics.net/labels.html">tex labeling</a>, advanced coloring, <a href="http://ilnumerics.net/axis-configuration.html#logarithmic-scales">logarithmic axes </a>and much <a href="http://ilnumerics.net/plotting-api.html">more</a> &#8230;</p>
<h2>Deploying ILNumerics Excel Workbooks</h2>
<p>Once the workbook is ready for distribution, we build a Release version from Visual Studio and from now on – do not need Visual Studio anymore! In order to make any machine ready for handling HDF5 data and create Excel worksheets with nice visualizations on it, one only needs to run the <a href="http://ilnumerics.net/download.html">ILNumerics installer</a> and transfer the workbook to that machine. It will run on any platform, regardsless if 32 or 64 bit!</p>
<p>You can find the full example for downloading on our <a href="http://ilnumerics.net/examples.php">examples page</a>.</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/fun-with-hdf5-ilnumerics-and-excel/">Fun with HDF5, ILNumerics and Excel</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-hdf5-ilnumerics-and-excel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Performance on ILArray</title>
		<link>https://ilnumerics.net/blog/performance-on-ilarray/</link>
		<comments>https://ilnumerics.net/blog/performance-on-ilarray/#comments</comments>
		<pubDate>Tue, 25 Nov 2014 16:59:13 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[scalar]]></category>
		<category><![CDATA[system types]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=650</guid>
		<description><![CDATA[<p>Having a convenient data structure like ILArray&#60;T&#62; brings many advantages when handling numerical data in your algorithms. On the convenience side, there are flexible options for creating subarrays, altering existing data (i.e. lengthening or shortening individual dimensions on the run), keeping dimensionality information together with the data, and last but not least: being able to &#8230; <a href="https://ilnumerics.net/blog/performance-on-ilarray/" class="more-link">Continue reading <span class="screen-reader-text">Performance on ILArray</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/performance-on-ilarray/">Performance on ILArray</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Having a convenient data structure like ILArray&lt;T&gt; brings many advantages when handling numerical data in your algorithms. On the convenience side, there are flexible options for creating subarrays, altering existing data (i.e. lengthening or shortening individual dimensions on the run), keeping dimensionality information together with the data, and last but not least: being able to formulate an algorithm by concentrating on the math rather than on loops and the like.</p>
<h2>Convenience <em>and</em> Speed</h2>
<p>Another advantage is performance: by writing C = A + B, with A and B being large arrays, the inner implementation is able to choose the most efficient way of evaluating this expression. Here is, what ILNumerics internally does:<span id="more-650"></span></p>
<ul>
<li>Pointer artithmetics &#8211; we remove the obligatory bound checks on array accesses by using C# pointers.</li>
<li>Cache aware implementations &#8211; the biggest bottleneck in modern processors is memory, as your know. ILNumerics implements all basic math functions in a way which allows to very efficiently profit from cache hierarchies in your processor. You will notice, if you time ILMath.sum over the rows of an array against a naive implementation.</li>
<li>Loops over large arrays are unrolled, saving a great amount of bookkeeping overhead.</li>
<li>Multithreading support &#8211; iterations over large arrays are split and distributed to multiple cores.</li>
</ul>
<h2>ILNumerics Accelerator</h2>
<p>Here is, what we are planning to add to this list:</p>
<ul>
<li>Utilizing SIMD vector extensions (SSE, AVX). Today, this parallel potential is accessed via the (native) MKL in ILNumerics. There has been a recent update to MKL 11.2 in ILNumerics Ultimate VS 4.4 which brings AVX2 support on corresponding Intel processors. For the future, we are planning to bring in extendend support for all managed evaluations as well. This will be introduced with the release of our ILNumerics Accelerator. Stay tuned &#8211; this will be a very exciting release&#8230; !</li>
<li>The Accelerator will also do onother highly efficient feature: removal of intermediate arrays. Expressions like C = A + 2 * B will no longer create an intermediate result for<br />
2 * B, but reformulate the expression before evaluation. Again: memory is the bottleneck and this will save a lot of memory transfer to the CPU.</li>
<li>Having a vast amount of GPUs available in basically every desktop computer today makes one wanting to <em>use</em> that – especially when waiting for your results. ILNumerics Accelerator will do it! It will decide on its own during runtime, which part of your algorithms are best executed on which available hardware and do it in the most efficient way possible. Need a further speedup? Just buy a better graphics card!</li>
</ul>
<h2>Limitations of n-dim arrays</h2>
<p>Nothing comes for free, right? All the above is great for large data on vectorized algorithms. But what if we have a tight loop over small ILArrays or an algorithm which basically does a vast amount of scalar computations?</p>
<p>The flexibility of ILArray certainly comes at a price here. It becomes clear if you imagine the difference between a single double value and its corresponding representation in terms of a scalar ILArray&lt;double&gt;. The former – while being a value type lives on the stack rather than on the managed heap. It is not involved in garbage collection and there is basically no cost involved for its construction, access and destruction &#8211; at least when compared to the full featured implementation of ILArray.</p>
<p>ILArray, on the other hand, is a class instance. It lives on the heap instead of the stack storage. Creating an instance corresponds to the creation with &#8216;new&#8217;. For the destruction ILNumerics is able to completely prevent the GC having to handle ILArray instances. But even this memory management comes with a cost, naturally.</p>
<p>So there are two sides of the medal: flexibility and better performance for &#8216;large&#8217; data. Flexibility and slower speed for tiny &#8230; to scalar data. For most algorithms, having a reasonable amount of management of small data does not hurt performance. But if such operations are to be done in tight loops, one starts looking for alternatives.</p>
<h2>Alternatives</h2>
<p>Especially for small data the flexible subarray features of ILArray are often not needed anyways.  Such scalar algorithm parts are much more efficiently implemented by using data structures that are especially designed for it: System.ValueType and System.Array. The good news: ILNumerics makes it very easy to resort to such system types instead. Here comes a comprehensive list of options:</p>
<p>Scalar operations on an ILArray&lt;T&gt;</p>
<table>
<tbody>
<tr>
<th>Scalar access</th>
<th>Returns</th>
<th>Efficiency</th>
<th>Documentation</th>
</tr>
<tr>
<td>A[0,1]</td>
<td>ILArray&lt;T&gt;</td>
<td>Improved since 4.3, but will not be fastest on scalars (ILNumerics Accelerator might change this!)</td>
<td><a href="/Subarray0.html">Subarrays</a></td>
</tr>
<tr>
<td>A.GetValue()<br />
A.SetValue()</td>
<td>T</td>
<td>faster and efficient if you only need a single element occasionally</td>
<td><a href="http://ilnumerics.net/ArrayAlter.html">Writing to Arrays</a></td>
</tr>
<tr>
<td>foreach (var a in A) { &#8230; }</td>
<td>T</td>
<td>very efficient iteration over all elements of A, gives copies as system types</td>
<td><a title="ILNumerics and LINQ" href="http://ilnumerics.net/blog/ilnumerics-and-linq/">ILArray and LINQ</a></td>
</tr>
<tr>
<td>A.GetArrayForRead()<br />
A.GetArrayForWrite()</td>
<td>T[]</td>
<td>direct access to the underlying system array of A. Use this for hand tuned inner kernels or if you need access to native libraries.</td>
<td><a title="Import/ Export" href="http://ilnumerics.net/ArrayImExport.html">Array Import / Export</a></td>
</tr>
</tbody>
</table>
<p>You may also consider the following references:<br />
Stackoverflow posts dealing with the scalar access issue:<br />
<a href="http://stackoverflow.com/questions/19224626/performance-of-ilnumerics-of-simple-math-operations-over-vectors-vs-system-array">http://stackoverflow.com/questions/20944672/iteration-through-ilarraydouble-is-very-slow</p>
<p>http://stackoverflow.com/questions/19224626/performance-of-ilnumerics-of-simple-math-operations-over-vectors-vs-system-array</a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/performance-on-ilarray/">Performance on 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/performance-on-ilarray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plotting Fun with ILNumerics and IronPython</title>
		<link>https://ilnumerics.net/blog/plotting-fun-with-ilnumerics-and-ironpython/</link>
		<comments>https://ilnumerics.net/blog/plotting-fun-with-ilnumerics-and-ironpython/#comments</comments>
		<pubDate>Mon, 15 Sep 2014 10:31:45 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[IronPython]]></category>
		<category><![CDATA[numerical algorithms]]></category>
		<category><![CDATA[plots]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=599</guid>
		<description><![CDATA[<p>Since the early days of IronPython, I keep shifting one bullet point down on my ToDo list: * Evaluate options to use ILNumerics from IronPython Several years ago there has been some attempts from ILNumerics users who successfully utilized ILNumerics from within IronPython. But despite our fascination for these attempts, we were not able to &#8230; <a href="https://ilnumerics.net/blog/plotting-fun-with-ilnumerics-and-ironpython/" class="more-link">Continue reading <span class="screen-reader-text">Plotting Fun with ILNumerics and IronPython</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/plotting-fun-with-ilnumerics-and-ironpython/">Plotting Fun with ILNumerics and IronPython</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Since the early days of IronPython, I keep shifting one bullet point down on my ToDo list:</p>
<p>* Evaluate options to use <a href="http://ilnumerics.net">ILNumerics</a> from IronPython</p>
<p>Several years ago there has been some attempts from<a href="https://code.google.com/p/ironlab/"> ILNumerics users</a> who successfully utilized ILNumerics from within IronPython. But despite our fascination for these attempts, we were not able to catch up and deeply evaluate all options for joining both projects. Years went by and Microsoft has dropped support for IronPython in the meantime. Nevertheless, a considerably large community seems to be active on IronPython. Finally, today is the day I am going to give this a first quick shot.</p>
<p><span id="more-599"></span></p>
<p><em>Disclaimer: I am not a python developer. My experience with IronPython range from 0 &#8230; zero (unfortunatley, since the project deserves <strong>much</strong> more attention). For CPython it is only slighly better. So please bare with me if I went into some stupid direction or if I have completely missed better options in this article! Corrections and suggestions are always warmly welcome.</em></p>
<h1>Setup</h1>
<p>I downloaded and installed <a href="https://ironpython.codeplex.com/releases/view/90087">IronPython from CodePlex</a>. Also, in Visual Studio 2013 there exists a link in the NEW PROJECT dialog advertising the download of IronPython Tools for Visual Studio. I used that to setup Visual Studio for IronPython projects. All setup went smooth and easy. Nice!</p>
<h1>Creating Plots with IronPython</h1>
<p>The challenge I was interested in the most was how it is possible to utilize the great plotting capabilities of <a href="http://ilnumerics.net/Visualization-API.html">ILNumerics Visualization Engine</a> from IronPython projects. Since matplotlib seems not to be available for IronPython and other alternatives are also pretty rare (if any at all?) having our visualization engine available to IronPython projects seem to be a big improvement.</p>
<p>The good news first: it works and it does so very easily. The following plot is done purely in IronPython:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/09/Plotting-Fun-with-ILNumerics-in-IronPython1.png"><img class="aligncenter size-full wp-image-613" src="http://ilnumerics.net/blog/wp-content/uploads/2014/09/Plotting-Fun-with-ILNumerics-in-IronPython1.png" alt="" width="661" height="470" /></a>I started with a fresh new Iron Python Windows Forms Application from the &#8216;New Project&#8217; dialog in Visual Studio 2013.</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/09/IronPython_ILPanel_NewProjectVS2013.png"><img src="http://ilnumerics.net/blog/wp-content/uploads/2014/09/IronPython_ILPanel_NewProjectVS2013.png" alt="" width="662" height="384" /></a></p>
<p>This gives a template python file &#8216;IronPython_ILPanel.py&#8217; with the following content:</p>
<pre class="brush: python; title: ; notranslate">
import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')

from System.Drawing import *
from System.Windows.Forms import *

class MyForm(Form):
    def __init__(self):
        # Create child controls and initialize form
        pass

Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)

form = MyForm()
Application.Run(form)</pre>
<p>If you are familiar with the common setup of Windows Forms you may notice some similarities with the stub provided by a new C# Windows Forms Application project. What is otherwise spread over multiple files, now is done all within the global scope of the one and only *.py file: the form class is defined, the static Application class is configured and the event loop is started with an instance of the formerly defined MyForm class. Straight. This corresponds to the common setup for Windows.Forms from any language, where no Designer support exists for. The same could be done in PowerShell, to name just another example.</p>
<p>In order to integrate support for ILNumerics Visualization Engine, I did the following simple steps:</p>
<p>1) If not done so far, go and install <a href="http://ilnumerics.net">ILNumerics Ultimate VS</a>. We offer <a href="http://ilnumerics.net/download.html">30 days trials</a> which contain all features without limitation.<br />
2) Once installed, ILNumerics is available in the &#8220;Add Reference&#8221; dialog (right click on References in the Solution Explorer). ILNumerics.dll is added from the .NET tab:</p>
<p><a href="http://ilnumerics.net/blog/wp-content/uploads/2014/09/IronPython_ILPanel_Select_Component.png"><img class="aligncenter size-full wp-image-606" src="http://ilnumerics.net/blog/wp-content/uploads/2014/09/IronPython_ILPanel_Select_Component.png" alt="" width="592" height="476" /></a>3) Make the ILNumerics namespaces available: I added the following lines to the import section at the very top of IronPython_ILPanel.py:</p>
<pre class="brush: python; title: ; notranslate">
import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
clr.AddReference('ILNumerics')

from System.Drawing import *
from System.Windows.Forms import *
from ILNumerics import *
from ILNumerics.Drawing import *
from ILNumerics.Drawing.Plotting import *
</pre>
<p>4) Now we are ready to add a plot to the form. In C# we would simply use the <code>ilPanel1_Load</code> event handler which is easily added by help of the forms designer. Since we do not have designer support here, we simply add the setup to the constructor of MyForm:</p>
<pre class="brush: python; title: ; notranslate">
class MyForm(Form):
   def __init__(self):
     # Create child controls and initialize form
     ilpanel = ILPanel()
     ilpanel.Dock = DockStyle.Fill
     self.Controls.Add(ilpanel)
     # show some demo: first create a plotcube
     pc = ILPlotCube(&quot;pc&quot;, 0)
     # it will hold a surface with some sinc data in 3D
     # You can use ILRetArray returned from any ILNumerics Computing
     # Module as input argument here directly. Type conversions seem to happen automatically.
     sf = ILSurface(ILSpecialData.sincf(40,50))
     pc.Add(sf)
     # add the plotcube to the scene
     ilpanel.Scene.Add(pc)
     self.Text = &quot;Plotting Fun with ILNumerics in IronPython&quot;
</pre>
<p>This is all straightforward. The configuration of the panel and the plots is exactly as it would have been done in C# or Visual Basic. However, we have to add the ILPanel to the self.Controls collection manually. The result, of course is exactly the same: a nice interactive form, utilizing OpenGL, with all manipulation options like rotation, pan and zoom. The full spectrum of the Visualization Engine should work out of the box. This includes several, flexible <a href="http://ilnumerics.net/plotting-api.html">3D and 2D plotting types</a> as well as the whole <a href="http://ilnumerics.net/scene-graph-shapes-and-buffers.html">scene graph functionality</a> for building your own interactive visualizations.</p>
<p>This is all what needs to be done in order to create nice professional plots directly within IronPython. Press F5 and start your application, rotate the plot with the mouse and learn about all the <a href="http://ilnumerics.net/visualization-engine.html">options you have</a>.</p>
<p><iframe width="474" height="267" src="https://www.youtube.com/embed/G9WWy_u-vvI?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<h1>Computing Fun with IronPython and ILNumerics</h1>
<p>ILNumerics not only rely on its own flexible n-dimensional array implementation, it also introduces its very own memory management &#8211; for <a href="http://ilnumerics.net/performance.html">very good reasons</a>. In order for the memory managements to work, <a href="http://ilnumerics.net/GeneralRules.html">individual array types</a> (ILArray, ILInArray, ILOutArray and ILRetArray) are used in ILNumerics algorithms. This makes great use of the strict type safety of .NET languages as C# and Visual Basic and of automatic conversions between those types.</p>
<p>Python on the other side is a dynamic language. It does not know the concept of types to the same extend. A straightforward application of the ILNumerics array types is not possible. IronPython, however offers workarounds (clr.Convert) but they are not able to provide the same syntactical convenience as a pure C# algorithm.</p>
<p>My recommendation for the utilization of ILNumerics Computing Engine therefore is as follows:</p>
<p>ILNumerics Computing Engine can be used without restriction. The utilization of existing algorithms is straightforward. Algorithms leveraging the ILNumerics Function Rules can be called directly without any type conversions. The creation of local variables on the other side requires type conversions from ILRetArray to ILArray. This can be done by help of IronPythons clr.Convert function.</p>
<p>The type conversion issue possibly makes it less feasible to write own ILNumerics Computing Engine algorithms in IronPython. But most the time, one would rather want to use existing python algorithms anyway. In order to actually create a new algorithm, one should rather utilize C# and compile the algorithm into its own .NET module which can than easily be imported into your python project and get interfaced from your python code.</p>
<h1>Summary</h1>
<p>This blog demonstrated how easy it is to utilize ILNumerics from IronPython. Especially the Visualization Engine is incorporated without any problems and offers the full set of visualization and plotting options out of the box. Algorithms created with ILNumerics Computation Engine can directly be interfaced and used &#8211; in parallel with numpy algorithms, if the need arise. The syntax of the Computing Engine however is not as expressive and more clumsy due to the absense of implicit type conversions and operator overloads. Complex algorithms one therefore would rather implement in C# or VisualBasic than in IronPython. For small algorithms, like data preprocessing and the like, ILNumerics Computing Engine serves as a faster alternative to numpy arrays.</p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/plotting-fun-with-ilnumerics-and-ironpython/">Plotting Fun with ILNumerics and IronPython</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/plotting-fun-with-ilnumerics-and-ironpython/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Large Object Heap Compaction &#8211; on Demand ??</title>
		<link>https://ilnumerics.net/blog/large-object-heap-compaction-on-demand/</link>
		<comments>https://ilnumerics.net/blog/large-object-heap-compaction-on-demand/#comments</comments>
		<pubDate>Thu, 16 Jan 2014 22:46:11 +0000</pubDate>
		<dc:creator><![CDATA[haymo]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ILNumerics]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[function rule]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[heap]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[Memory Management]]></category>
		<category><![CDATA[OutOfMemory]]></category>
		<category><![CDATA[pool]]></category>

		<guid isPermaLink="false">http://ilnumerics.net/blog/?p=529</guid>
		<description><![CDATA[<p>In the 4.5.1 side-by-side update of the .NET framework a new feature has been introduced, which will really remove one annoyance for us: Edit &#38; Continue for 64 bit debugging targets. That is really a nice one! Thanks a million, dear fellows in &#8220;the corp&#8221;! Another useful one: One can now investigate the return value &#8230; <a href="https://ilnumerics.net/blog/large-object-heap-compaction-on-demand/" class="more-link">Continue reading <span class="screen-reader-text">Large Object Heap Compaction &#8211; on Demand ??</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/large-object-heap-compaction-on-demand/">Large Object Heap Compaction &#8211; on Demand ??</a> appeared first on <a rel="nofollow" href="https://ilnumerics.net/blog">The ILNumerics Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In the <a href="http://msdn.microsoft.com/en-us/library/ms171868%28v=vs.110%29.aspx#v451">4.5.1 side-by-side</a> update of the .NET framework a new feature has been introduced, which will really remove one annoyance for us: <a href="http://msdn.microsoft.com/library/ms164927%28v=vs.120%29.aspx">Edit &amp; Continue for 64 bit debugging targets</a>. That is really a nice one! Thanks a million, dear fellows in &#8220;the corp&#8221;! </p>
<p>Another useful one: One can now <a href="http://msdn.microsoft.com/library/e3245b37-8e2e-4200-ba84-133726e95f1f%28v=vs.120%29.aspx">investigate the return value</a> of functions during a debug session. </p>
<p>Now, while both features will certainly help to create better applications by helping you to get through your debug session more quickly and conveniently, another feature was introduced, which deserves a more critical look: now, there exist an option to explicitly compact the large object heap (LOH) during garbage collections. <a href="http://msdn.microsoft.com/en-us/library/system.runtime.gcsettings.largeobjectheapcompactionmode%28v=vs.110%29.aspx">MSDN says</a>:</p>
<blockquote><p>If you assign the property a value of GCLargeObjectHeapCompactionMode.CompactOnce, the LOH is compacted during the next full blocking garbage collection, and the property value is reset to GCLargeObjectHeapCompactionMode.Default. </p></blockquote>
<p>Hm&#8230; They state further: </p>
<blockquote><p>You can compact the LOH immediately by using code like the following:</p>
<pre class="brush: csharp; title: ; notranslate">
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(); 
</pre>
</blockquote>
<p>Ok. Now, it looks like there has been quite some demand for &#8216;a&#8217; solution for a serious problem: LOH fragmentation. This basically happens all the time when large objects are created within your applications and relased and created again and released&#8230; you get the point: disadvantageous allocation pattern with &#8216;large&#8217; objects will almost certainly lead to holes in the heap due to reclaimed objects, which are no longer there, but other objects still resisting in the corresponding chunk, so the chunk is not given back to the memory manager and OutOfMemoryExceptions are thrown rather early &#8230; </p>
<p>If all this sounds new and confusing to you &#8211; no wonder! This is probably, because you are using ILNumerics <img src="https://ilnumerics.net/blog/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> Its memory management prevents you reliably from having to deal with these issues. How? Heap fragmentation is caused by garbage. And the best way to handle garbage is to prevent from it, right? This is especially true for large objects and the .NET framework. And how would one prevent from garbage? By reusing your plastic bags until they start disintegrating and your eggs get in danger of falling through (and switching to a solid basket afterwards, I guess). </p>
<p>In terms of computers this means: reuse your memory instead of throwing it away! Especially for large objects this puts way too much pressure on the garbage collector and at the end it doesn&#8217;t even help, because there is still fragmentation going on on the heap. For &#8216;reusing&#8217; we must save the memory (i.e. large arrays in our case) somewhere. This directly leads to a pooling strategy: once an ILArray is not used anymore &#8211; its storage is kept safe in a pool and used for the next ILArray. </p>
<p>That way, no fragmentation occurs! And just as in real life &#8211; keeping the environment clean gives you even more advantages. It helps the caches by presenting recently used memory and it protects the application from having to waste half the execution time in the GC. Luckily, the whole pooling in ILNumerics works completely transparent in the back. There is nothing one needs to do in order to gain all advantages, except following the <a href="http://ilnumerics.net/FunctionRules.html">simple rules of writing ILNumerics functions</a>. ILNumerics keeps track of the lifetime of the arrays, safes their underlying System.Arrays in the ILNumerics memory pool, and finds and returns any suitable array for the next computation from here.</p>
<p>The pool is smart enough to learn what &#8216;suitable&#8217; means: if no array is available with the exact length as requested, a next larger array will do just as well: </p>
<pre class="brush: csharp; title: ; notranslate">
public ILRetArray CreateSymm(int m, int n) {
    using (ILScope.Enter()) {
        ILArray A = rand(m,n); 
        // some very complicated stuff here...
        A = A * A + 2.3; 
        return multiply(A,A.T);
    }
}

// use this function without worrying about your heap!
while (true) {
   dosomethingWithABigMatrix(CreateSymm(1000,2000)); // one can even vary the sizes here!
   // at this point, your heap is clean ! No fragmentation! No GC gen.2 collections ! 
}
</pre>
<p>Keep in mind, the next time you encounter an unexpected OutOfMemoryException, you can either go out and try to make use of that obscure GCSettings.LargeObjectHeapCompactionMode property, or &#8230; simply start using ILNumerics and forget about that problem at least. </p>
<p>The post <a rel="nofollow" href="https://ilnumerics.net/blog/large-object-heap-compaction-on-demand/">Large Object Heap Compaction &#8211; on Demand ??</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/large-object-heap-compaction-on-demand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
