<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>.NET Archives - CenterSpace</title>
	<atom:link href="https://www.centerspace.net/category/net/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/category/net</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Tue, 07 Feb 2023 21:47:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">104092929</site>	<item>
		<title>NMath 7.0 &#038; the .NET Standard Library</title>
		<link>https://www.centerspace.net/nmath-on-net-standard-library</link>
					<comments>https://www.centerspace.net/nmath-on-net-standard-library#comments</comments>
		
		<dc:creator><![CDATA[Trevor Misfeldt]]></dc:creator>
		<pubDate>Mon, 27 May 2019 17:43:14 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[.NET Core]]></category>
		<category><![CDATA[.NET Standard]]></category>
		<category><![CDATA[C# Math Libraries]]></category>
		<guid isPermaLink="false">https://www.centerspace.net/?p=7347</guid>

					<description><![CDATA[<p>In December, CenterSpace Software rolled out a major new release of NMath, version 7.0, built on the .NET Standard Library 2.0. The focus of this release has been to support the .NET Standard library, to further improve the ease of use of the NMath library, and to unify all CenterSpace libraries into one. CenterSpace now [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-on-net-standard-library">NMath 7.0 &#038; the .NET Standard Library</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In December, CenterSpace Software rolled out a major new release of <strong>NMath</strong>, version 7.0,<em> built on the .NET Standard Library 2.0</em>. The focus of this release has been to support the .NET Standard library, to further improve the ease of use of the <strong>NMath </strong>library, and to unify all CenterSpace libraries into one. CenterSpace now offers one unified, powerful, math library: <strong>NMath 7.0</strong>.</p>



<p>This version requires developers to be using at least .NET Core 2.0 or at least .NET Framework 4.6.1.  Adding support of .NET Core to <strong>NMath </strong>has been in the works for over a year and was done at the request of many of our active developers.</p>



<p>Future development work will concentrate on the .NET Standard based <strong>NMath 7.0</strong>. However, <strong>NMath 6.2</strong>, build on .NET 4.0, but not supporting the .NET Standard Library, will be available for years to come.</p>



<p>Below is a list of major changes released in NMath 7.0:</p>



<ul><li>32-bit support has been dropped. Demand has been waning for years for this. Dropping it has made usage simpler and easier.</li><li>GPU support has been dropped. As developers, we liked the automatic GPU offloading. However, the technical advantages have dissipated as multi-core processors have improved.  We believe that this is no longer compelling for a general math library.</li><li>NMath Stats has been merged into NMath. This is for ease of use for our users.</li><li>In summer of 2019, our pricing will be streamlined to reflect these changes. There will be one price for a perpetual NMath license and there will be one price for annual NMath maintenance which includes technical support and all upgrades available on NuGet. NMath Stats will no longer be sold separately.</li><li>We have merged the four NMath namespaces into one, <code>CenterSpace.NMath.Core</code>, to simplify development. Originally, CenterSpace had four NMath products and four namespaces, these namespaces <code>CenterSpace.NMath.Core,  CenterSpace.NMath.Matrix, CenterSpace.NMath.Stats,  CenterSpace.NMath.Analysis</code> reflect that history. We have left stubs so users won&#8217;t have any breaking changes.</li><li>We have dropped charting. The ecosystem is full of powerful visualization packages. We have only three main data structures in NMath, vectors, matrices and data frames, and all can be easily used with different charting packages.</li><li>Some of our optimizations use Microsoft Solver Foundation. If you use these, you&#8217;ll need to be on the .NET Framework track and not on the .NET Core track.</li><li>We have dropped the installers. The compelling ease of NuGet for our users has made these obsolete.</li></ul>



<hr class="wp-block-separator"/>



<p><a href="https://www.nuget.org/packages/CenterSpace.NMath.Standard.WindowsAndLinux.X64/">NMath 7.0 on Windows and Linux</a></p>



<p><a href="https://www.nuget.org/packages/CenterSpace.NMath.Standard.Windows.X64/">NMath 7.0 on Windows</a></p>



<p><a href="https://www.nuget.org/packages/CenterSpace.NMath.Standard.Linux.X64/">NMath 7.0 on Linux</a></p>



<p><a href="https://www.nuget.org/packages/CenterSpace.NMath.Standard.OSX.X64/">NMath 7.0 on OSX</a></p>



<p>Please try the new versions on NuGet. Feedback welcome as always.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-on-net-standard-library">NMath 7.0 &#038; the .NET Standard Library</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/nmath-on-net-standard-library/feed</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7347</post-id>	</item>
		<item>
		<title>NMath is Adding .NET Core Support and has Dropped Support of OSX and Linux86</title>
		<link>https://www.centerspace.net/nmath-adding-net-core-net-standard</link>
					<comments>https://www.centerspace.net/nmath-adding-net-core-net-standard#comments</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Tue, 13 Mar 2018 00:29:27 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Premium]]></category>
		<category><![CDATA[.NET Core]]></category>
		<category><![CDATA[.NET Standard]]></category>
		<guid isPermaLink="false">https://www.centerspace.net/?p=7300</guid>

					<description><![CDATA[<p>CenterSpace will be adding support for both .NET Core and .NET Standard to NMath by the end of 2018.  NMath has also dropped support of both the OSX and Linux86 operating systems in NMath release 6.2.0.41.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-adding-net-core-net-standard">NMath is Adding .NET Core Support and has Dropped Support of OSX and Linux86</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h3> Changes to Supported Operating Systems </h3>
<p>With the release of <strong>NMath</strong> 6.2.0.41, on March 10, 2018, <strong>NMath</strong> no longer supports OSX or the Linux x86 operating systems.  We are dropping the support of these operating systems due to a decline of demand by our customers.  Please contact us with any concerns regarding this change.  This release is currently available on <a href="https://www.nuget.org/packages/CenterSpace.NMath.Premium/6.2.0.41">NuGet</a>.</p>
<p>Going forward <strong>NMath</strong> and <strong>NMath Premium</strong> will naturally continue to support both the 32-bit and 64-bit Windows and 64-bit Linux.  </p>
<h3> Adding .NET Standard and .NET Core Support  </h3>
<p><em>By the end of 2018, NMath will support both the .NET Core and .NET Standard</em>.  Supporting both of these .NET standards have been increasingly requested by our customers.  If you are unfamiliar with these newest additions to the .NET world, the following briefly defines them.</p>
<ul>
<li> .NET Core: This is the latest .NET implementation. It’s open source and available for multiple OSes. With .NET Core, you can build cross-platform console apps and ASP.NET Core Web applications and cloud services.</li>
<li>.NET Standard: This is the set of fundamental APIs (commonly referred to as base class library or BCL) that all .NET implementations must implement. By targeting .NET Standard, you can build libraries that you can share across all your .NET apps, no matter on which .NET implementation or OS they run.</li>
</ul>
<p>For further reading on these .NET standards see this <a href="https://msdn.microsoft.com/en-us/magazine/mt842506.aspx">MSDN magazine</a> article for an introduction.</p>
<p>Please don&#8217;t hesitate to contact us in the comments below or via email with any questions regarding these changes to the CenterSpace .NET <strong>NMath</strong> library. </p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-adding-net-core-net-standard">NMath is Adding .NET Core Support and has Dropped Support of OSX and Linux86</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/nmath-adding-net-core-net-standard/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7300</post-id>	</item>
		<item>
		<title>NMath Charts in WPF</title>
		<link>https://www.centerspace.net/nmath-charts-in-wpf</link>
					<comments>https://www.centerspace.net/nmath-charts-in-wpf#comments</comments>
		
		<dc:creator><![CDATA[Trevor Misfeldt]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 01:23:53 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[Visualization]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/uncategorized/nmath-charts-in-wpf/</guid>

					<description><![CDATA[<p>The NMathChart adapter class makes it easy to generate visualizations of NMath data in as little as one line of code.  The Chart class that is created is a Windows Forms control, but this control can be included in a Windows Presentation Foundation application by using the WindowsFormsHost element. To do so: Add references to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-charts-in-wpf">NMath Charts in WPF</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The NMathChart adapter class makes it easy to <a href="https://www.centerspace.net/nmath-charts-in-wpf/" target="_blank" rel="noopener">generate visualizations of NMath data</a> in as little as one line of code.  The <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.chart.aspx" target="_blank" rel="noopener">Chart</a> class that is created is a Windows Forms control, but this control can be included in a Windows Presentation Foundation application by using the <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx" target="_blank" rel="noopener">WindowsFormsHost</a> element.</p>
<p>To do so:</p>
<ol>
<li><span style="color: #333333;">Add references to these namespaces: </span><span style="font-family: Consolas;">System.Windows.Forms<br />
System.Windows.Forms.Integration<br />
</span></li>
<li>In the XAML markup for your WPF window (<span style="font-family: Consolas;">MainWindow.xaml</span> for example), add a <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx" target="_blank" rel="noopener">WindowsFormsHost</a> element at the desired location, e.g:<span style="font-family: Consolas;">&lt;Grid&gt;<br />
&lt;WindowsFormsHost Name=&#8221;ChartHost&#8221;/&gt;<br />
&lt;/Grid&gt;<br />
</span></li>
<li>In the code-behind for the window (<span style="font-family: Consolas;">MainWindow.xaml.cs</span> for example), set the <span style="font-family: Consolas;">Child</span> property of the <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx" target="_blank" rel="noopener">WindowsFormsHost</a> to a <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.chart.aspx" target="_blank" rel="noopener">Chart</a>. For example:<span style="font-family: Consolas;">public MainWindow()<br />
{<br />
InitializeComponent();<br />
ChartHost.Child = NMathChart.ToChart(NMathFunctions.CosFunction,<br />
-Math.PI, Math.PI, 100 );<br />
}</span></li>
</ol>
<p>To see this in action, check out the sample code in the new Visualization Examples solution included in <a href="/nmath-5-3-nmath-stats-3-6-are-coming/" target="_blank" rel="noopener">NMath 5.3</a>. For more information about visualization of NMath data types, see:</p>
<ul>
<li>Whitepaper: <a href="https://www.centerspace.net/doc/NMath/whitepapers/NMath.ChartMicrosoft.pdf">NMath Visualization Using the Microsoft Chart Controls</a></li>
<li>Whitepaper: NMath Stats Visualization Using the Microsoft Chart Controls</li>
<li>the <a href="https://www.centerspace.net/doc/NMath/ref/">API docs</a> for the <code>CenterSpace.NMath.Charting.Microsoft </code>namespace</li>
</ul>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-charts-in-wpf">NMath Charts in WPF</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/nmath-charts-in-wpf/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4292</post-id>	</item>
		<item>
		<title>Building ASP.NET web applications with NMath</title>
		<link>https://www.centerspace.net/building-asp-net-web-applications-with-nmath</link>
					<comments>https://www.centerspace.net/building-asp-net-web-applications-with-nmath#respond</comments>
		
		<dc:creator><![CDATA[Trevor Misfeldt]]></dc:creator>
		<pubDate>Thu, 21 Feb 2013 16:04:14 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[Support]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[NMath configuration]]></category>
		<category><![CDATA[web]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=4219</guid>

					<description><![CDATA[<p>NMath can be used to create ASP.NET web applications, just like any other .NET application. However, there are a few additional considerations for building and deploying ASP.NET applications. Referencing NMath To use NMath types in your application, add a reference to NMath.dll, just as you would with other types of .NET applications. If you are [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/building-asp-net-web-applications-with-nmath">Building ASP.NET web applications with NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>NMath can be used to create ASP.NET web applications, just like any other .NET application. However, there are a few additional considerations for building and deploying ASP.NET applications.</p>
<h3>Referencing NMath</h3>
<p>To use NMath types in your application, add a reference to NMath.dll, just as you would with other types of .NET applications. If you are using web projects in Visual Studio, you can simply right-click the References folder and select the Add Reference… command. If you specify Copy Local = true in the reference’s properties, then the assembly will be copied to the /bin directory of the web application, facilitating deployment to a web server.</p>
<p>If you are not using web projects in Visual Studio (e.g. using the “Open Web Site” command in Visual Studio, or using other development tools), then you can alternatively specify the reference in the web.config file, like this:</p>
<p><span style="font-family: Consolas;">&lt;configuration&gt;<br />
&lt;system.web&gt;<br />
&lt;compilation&gt;<br />
&lt;assemblies&gt;<br />
&lt;add assembly=&#8221;NMath, Version=&lt;Version&gt;, Culture=neutral, PublicKeyToken=&lt;Token&gt;&#8221;/&gt;<br />
&lt;/assemblies&gt;<br />
&lt;/compilation&gt;<br />
&lt;/system.web&gt;<br />
&lt;/configuration&gt;</span></p>
<p>We recommend that you do not add references to the kernel assemblies, as the appropriate kernel assembly for your platform is loaded at runtime and the appropriate native DLL is linked to the kernel.  Instead, place the kernel assemblies in the same location as the native DLLs, as described below.</p>
<p><strong>Note</strong>: when the web server launches an ASP.NET application for the first time, the assemblies in the /bin directory are loaded into memory. If the /bin directory contains a mixture of 32-bit and 64-bit assemblies (for example, both NMathKernelx86.dll and NMathKernelx64.dll), then depending on the configuration of the web server, the application may fail to start and instead throw an exception like this: “An attempt was made to load a program with an incorrect format.”</p>
<h3>Kernel Assemblies and Native DLLs</h3>
<p>For ASP.NET applications, Microsoft recommends that the /bin directory contain only .NET assemblies, not native DLLs.</p>
<p>If the deployment web server may not have NMath installed directly, then we recommend that the appropriate kernel assembly (NMathKernelx86.dll or NMathKernelx64.dll) and the appropriate native DLLs (e.g. nmath_native_x86.dll or nmath_native_x64.dll) be placed in a folder within the web application root directory, such as /NativeBin. This folder should then be copied to the deployment web server along with the rest of your application.</p>
<h3>NMath Configuration</h3>
<p>NMath settings can be configured as described in Chapter 1.5 of the <em>NMath User’s Guide.</em> However, when deploying web applications &#8212; especially to a shared hosting environment &#8212; it&#8217;s quite common not to know the details about the physical structure of the file system, and to have restricted access to the system’s environment variables. The references to resources within web apps are typically relative to the root of the virtual directory for the website, regardless of where they might physically reside on disk.</p>
<p>For this reason, starting in NMath 5.3, the ASP.NET ~ operator can be used to specify the location of the NMath native libraries and the log file, relative to the web application root. That is, these can be specified in the web.config file like this:</p>
<p><span style="font-family: Consolas;"> &lt;add key=&#8221;NMathNativeLocation&#8221; value=&#8221;~/NativeBin&#8221; /&gt;<br />
</span><span style="font-family: Consolas;"> &lt;add key=&#8221;NMathLogLocation&#8221; value=&#8221;~/Logs&#8221; /&gt;</span></p>
<p>It is not sufficient to use relative paths (e.g. &#8220;bin/&#8221;), since the executing assembly is usually the ASP.NET worker process, and depending on the web server configuration, the working directory will usually be a subdirectory of the Windows system directory (e.g. c:\windows\system32).</p>
<p>The ~ operator can only be used in ASP.NET applications; specifying this in a Windows application will cause the path to be resolved incorrectly.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/building-asp-net-web-applications-with-nmath">Building ASP.NET web applications with NMath</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/building-asp-net-web-applications-with-nmath/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4219</post-id>	</item>
		<item>
		<title>Large matrices and vectors</title>
		<link>https://www.centerspace.net/large-matrices-and-vectors</link>
					<comments>https://www.centerspace.net/large-matrices-and-vectors#comments</comments>
		
		<dc:creator><![CDATA[Trevor Misfeldt]]></dc:creator>
		<pubDate>Fri, 27 Jul 2012 10:00:33 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[3GB boot switch]]></category>
		<category><![CDATA[gcAllowVeryLargeObjects]]></category>
		<category><![CDATA[Large matrices .NET]]></category>
		<category><![CDATA[large matricies]]></category>
		<category><![CDATA[massive matricies]]></category>
		<category><![CDATA[massive vectors]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=221</guid>

					<description><![CDATA[<p>Customers frequently ask us the size of the largest matrix they can instantiate. With recent developments at Microsoft the maximum object size now significantly depends on your OS (x86 or x64) and the version of .NET your application is referencing. With .NET 4.5 huge matrices can be created that far exceed the current 2GByte limit. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/large-matrices-and-vectors">Large matrices and vectors</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Customers frequently ask us the size of the largest matrix they can instantiate.  With recent developments at Microsoft the maximum object size now significantly depends on your OS (x86 or x64) and the version of .NET your application is referencing.  With .NET 4.5 huge matrices can be created that far exceed the current 2GByte limit.</p>
<h2> Pre .NET 4.5 </h2>
<p>Until 2012 all Microsoft 32-bit .NET processes were limited to 1.2GB of memory. Theoretically a matrix could take up most of that space. Let&#8217;s suppose it&#8217;s feasible in our application to have a 1 GB matrix. That matrix would contain 134,217,728 doubles or 268,435,456 floats &#8212; for example, a 11,585 x 11,585 square <code>DoubleMatrix</code> or a 16,384 x 16,384 square <code>FloatMatrix</code>.  </p>
<p>There is a workaround in 32-bit .NET to increase the process memory to 2.4GB.</p>
<ol>
<li>Add the /3GB switch to boot.ini.
<li> After building the application, run the linker as follows:
</ol>
<pre lang="c">
link -edit -LARGEADDRESSAWARE application.exe
</pre>
<p>Increasingly, our customers are switching to 64-bit computing in part to get around these memory limitations. Although a 64-bit .NET process&#8217;s memory is only limited by the available RAM, the .NET runtime nevertheless limits any one object to 2GB. For that reason, our matrices are limited to a theoretical maximum of 402,653,184 doubles or 805,306,368 floats &#8212;for example, a 20,066 x 20,066 square DoubleMatrix or a 28,377 x 28,377 square <code>FloatMatrix</code>.</p>
<p>The good news is that this <b>memory limit has <i>finally</i> been lifted with the release of .NET 4.5</b>.  A big thanks to the Microsoft GC .NET team!  As they well know many developers have been requesting this change.</p>
<h2> .NET 4.5 </h2>
<p>With the .NET 4.5 release developers can now create objects that exceed the 2 GB per object limit <i>only in x64 environments</i>.  In order create these large objects the application must enable the element <code>gcAllowVeryLargeObjects</code> in the run-time schema.  This run-time schema controls the behavior of the .NET garbage collection system.</p>
<pre lang="c" >
&lt;configuration&gt;
  &lt;runtime>
    &lt;gcAllowVeryLargeObjects enabled="true" /&gt;
  &lt;/runtime&gt;
&lt;/configuration&gt;
</pre>
<p>These very large objects are subject to the following reasonable restrictions</p>
<ol>
<li>The maximum number of elements in an array is UInt32.MaxValue.
<li>The maximum index in any single dimension is 2,147,483,591 (0x7FFFFFC7) for byte arrays and arrays of single-byte structures, and 2,146,435,071 (0X7FEFFFFF) for other types.
<li>The maximum size for strings and other non-array objects is unchanged.
</ol>
<p>The brief Microsoft documentation note can be found <a href="https://msdn.microsoft.com/en-us/library/hh285054(v=vs.110).aspx">here</a>.</p>
<h2> What does this mean for NMath? </h2>
<p>First NMath has not yet been released with .NET 4.5 (as of July 2012) so all of the following will hold in the future under such a release.  All current releases are still subject to the limits outlined above.  So looking to the near future, underlying all NMath vectors and matrices is a contiguous 1-D array.  This means that for matrices the number of elements must be less than 2,146,435,071.  The same holds for vectors.  The following table summarizes the maximum size of various NMath objects under .NET 4.5 on a x64 OS with <code>gcAllowVeryLargeObjects</code> enabled.</p>
<pre class="code">
<table>
<tr><th> Class object</th>           <th> Maximum size - elements </th>           <th> Memory size - bytes </th> </tr> 
<tr><td> <code> FloatVector </code> </td> <td>  2,146,435,071 </td>       <td> 7.996 GBytes </td> </tr>
<tr><td> <code> DoubleVector </code> </td> <td>  2,146,435,071 </td>       <td> 15.992 GBytes </td> </tr>
<tr><td> <code> FloatMatrix </code> </td> <td>  2,146,435,071 </td>       <td> 7.996 GBytes </td> </tr>
<tr><td> <code> DoubleMatrix</code> </td> <td>  2,146,435,071 </td>       <td> 15.992 GBytes </td> </tr>
</table></pre>
<p>The <code>Complex</code> versions of these classes would have the same maximum number of elements but occupy twice the memory.  This also means that we will soon be able to allocate a square matrix with a maximum size of <code>[ 46329 x 46329 ]</code>.</p>
<p>&#8211; Trevor &#038; Paul</p>
<h2>NMath 5.3</h2>
<p>We have confirmed that the currently shipping version of NMath (version 5.3) can handle very large objects if you use <code>gcAllowVeryLargeObjects</code> and you are targeting .NET 4.5. We have created DoubleMatrix objects as large as 30,000 x 30,000 in this way. That&#8217;s a 6.7GB object.</p>
<p>&#8211; Trevor</p>
<h2>Large Matrices in a Web Environment</h2>
<p>It was reported to CenterSpace that the configuration change did not work in web environments. We confirmed this to be true. The good news is that there&#8217;s a workaround developed by Microsoft. A Microsoft developer says:</p>
<p>Essentially, the reason it can&#8217;t be done at the application-level Web.config is that this particular setting can only be set per-process and only when the CLR is initializing.  Since the CLR is already initialized by the time we start reading your Web.config, it&#8217;s too late to do anything about it at that time.  Using CLRConfigFile should work around this by allowing you to specify an intermediate configuration file that the CLR can use for initialization.  Then once the CLR is up, ASP.NET will read your Web.config and run your application as normal.</p>
<p>More info here: <a href="http://weblogs.asp.net/owscott/setting-an-aspnet-config-file-per-application-pool" title="Web workaround">here</a></p>
<p>We have verified that this works.</p>
<p>&#8211; Trevor</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/large-matrices-and-vectors">Large matrices and vectors</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/large-matrices-and-vectors/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">221</post-id>	</item>
		<item>
		<title>NMath API updated with .NET Func delegates</title>
		<link>https://www.centerspace.net/nmath-api-updated-with-net-func-delegates</link>
					<comments>https://www.centerspace.net/nmath-api-updated-with-net-func-delegates#comments</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Thu, 03 May 2012 00:03:16 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Stats]]></category>
		<category><![CDATA[.NET delegates]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[C# delegates]]></category>
		<category><![CDATA[C# Func]]></category>
		<category><![CDATA[Func]]></category>
		<category><![CDATA[NMath 5.2]]></category>
		<category><![CDATA[NMathStats 3.5]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3711</guid>

					<description><![CDATA[<p>At CenterSpace we are always working hard to keep the core NMath processing kernel start of the art, however changes to our libraries&#8217; API usually lag behind any .NET framework developments in a process of deprecation and introduction. The .NET Func&#60;&#62; and Action&#60;&#62; delegates have been a part of the .NET framework now since .NET [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-api-updated-with-net-func-delegates">NMath API updated with .NET Func&lt;&gt; delegates</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>At CenterSpace we are always working hard to keep the core NMath processing kernel start of the art, however changes to our libraries&#8217; API usually lag behind any .NET framework developments in a process of deprecation and introduction.  The .NET Func&lt;&gt; and Action&lt;&gt; delegates have been a part of the .NET framework now since .NET 3.5 and VS2008.  Therefore, we are now deprecating all of our custom delegates in the NMath API and replacing them with .NET Func&lt;&gt; generic delegates.  This improves interoperability between NMath and our customers&#8217; code and between our C# API and other .NET languages.  Customers will see this change in the NMath 5.2 and NMathStats 3.5.</p>
<p>For those not familiar with the usage and definition of Func&lt;&gt; types within .NET there is a short primer at the end of this post.</p>
<h2>Compiler Warning for [Obsolete] NMath defined delegates</h2>
<p>All of our NMath delegate types have been deprecated using the .NET <code>[Obsolete()]</code> attribute.  The generated compiler warnings will provide the suggested <code>Func</code> type replacement.</p>
<pre lang="csharp">Warning 52 'CenterSpace.NMath.Core.NMathFunctions.FloatUnaryFunction'
   is obsolete: 'Use Func< float, float >'   ...</pre>
<p>To further clarify, the following table lists the deprecated NMath float delegate types side by side with their replacements.  All NMath delegates should be redefined in your code using the generic <code>Func</code> types.</p>
<pre class="code">
<table style="font-size: 7pt;">
<tbody>
<tr>
<th colspan="2"> List of float-precision deprecated NMath delegate types</th>
</tr>
<tr>
<th>Old NMath delegates</th>
<th>Replacement</th>
</tr>
<tr>
<td>float FloatFunction()</td>
<td>Func&lt; float &gt;</td>
</tr>
<tr>
<td>float FloatUnaryFunction( float x )</td>
<td>Func&lt; float, float &gt;</td>
</tr>
<tr>
<td>float FloatBinaryFunction( float x, float y )</td>
<td>Func&lt; float, float, float &gt;</td>
</tr>
<tr>
<td>float FloatIntFunction( float x, int y )</td>
<td>Func&lt; float, int, float &gt;</td>
</tr>
<tr>
<td>float FloatVectorFloatFunction( FloatVector v )</td>
<td>Func&lt; FloatVector, float &gt;</td>
</tr>
<tr>
<td>FloatVector
  FloatVectorFloatVectorFunction( FloatVector x )</td>
<td>Func&lt; FloatVector, FloatVector &gt;</td>
</tr>
</tbody>
</table>
</pre>
<p>There are many other deprecated NMath delegates that should be similarly replaced in your code.</p>
<h2>Code examples for updating your code</h2>
<p>Where previously you might have created a delegate that takes a <code>double</code> argument and returns a <code>double</code> like this:</p>
<pre lang="csharp">NMathFunctions.DoubleUnaryFunction soln =
   delegate(double x) {return (x*x*x) / 3.0 + y0; };</pre>
<p>you should now do it like this:</p>
<pre lang="csharp">Func soln =
   new Func< double, double >(  x => (x*x*x) / 3.0 + y0 );</pre>
<p>All methods in NMath and NMath Stats now take Func&lt;&gt; type delegates. If you use the old NMath delegates types to call a NMath method, an obsolescence warning will be issued by the compiler.</p>
<p>NMath and NMath Stats contain many functors that have now been obsolesced and redefined using a generic Func&lt;&gt; type.  The new functor naming convention simply drops the &#8220;tion&#8221; from &#8220;Function&#8221; to make the new name.  For example, the delegate <code>NMathFunctions.AtanFunction</code> should now be replaced with <code>NMathFunctions.AtanFunc</code>.  The old delegate has a type of <code>NMathFunctions.DoubleUnaryFunction</code>, and the new delegate has a type of <code>Func&lt; double, double &gt;</code>.  This kind of replacement can be done safely with a global search and replace operation to rid yourself of compiler obsolescence warnings.  The table below list a few functor redefinitions that demonstrate the renaming pattern that was applied across the API.</p>
<pre class="code">
<table style="font-size: 7pt;">
<tbody>
<tr>
<th colspan="2"> Sampling of deprecated NMath functors</th>
</tr>
<tr>
<th>Old NMath functor</th>
<th>Replacement</th>
</tr>
<tr>
<td>DoubleUnaryFunction AbsFunction</td>
<td>Func&lt; double, double &gt; AbsFunc</td>
</tr>
<tr>
<td>DoubleUnaryFunction AcosFunction</td>
<td>Func&lt; double, double &gt; AcosFunc</td>
</tr>
<tr>
<td>DoubleUnaryFunction AsinFunction</td>
<td>Func&lt; double, double &gt; AsinFunc</td>
</tr>
<tr>
<td>DoubleBinaryFunction PowFunction</td>
<td>Func&lt; double, double, double &gt; PowFunc</td>
</tr>
<tr>
<td>DoubleIntFunction RoundFunction</td>
<td>Func&lt; double, int, double &gt; RoundFunc</td>
</tr>
<tr>
<td>DoubleVectorDoubleFunction
  DoubleNaNMedianFunction</td>
<td>Func&lt; DoubleVector, double &gt; DoubleNaNMedianFunc</td>
</tr>
</tbody>
</table>
</pre>
<h2>Potential Issues</h2>
<p>The deprecation process requires us to maintain the old custom delegate defintions in the API methods while introducing the new Func&lt;&gt; based API.  As a result, every method call in our API which previously consumed a custom NMath delgate type, a functionally identical signature was added which consumes a Func&lt;&gt; based delegate.  This duplication can cause an easy-to-fix compiler error in situations when an anonymous delegate was used instead of a NMath delegate type.  Consider the follow line of code which inverts the singular values of a SVD.</p>
<pre lang="csharp">      DoubleVector wInverse =
         svDecomp.SingularValues.Apply(
              delegate( double w )
                 { return w < eps ? 0.0 : 1.0 / w; }
         );</pre>
<p>Written this way will now cause the following compiler error.</p>
<pre class="code">
Error	43
The call is ambiguous between the following methods or properties:
'CenterSpace.NMath.Core.DoubleVector.Apply(
    CenterSpace.NMath.Core.NMathFunctions.DoubleUnaryFunction )'
and
'CenterSpace.NMath.Core.DoubleVector.Apply( System.Func )' ....</pre>
<p>In this error message, the first <code>Apply()</code> is the old method signature and the second <code>Apply()</code> is the new Func&lt;&gt; based signature.  The C# compiler can't choose between the two when provided an anonymous delegate.  Exactly why this ambiguity error is generated by the compiler is carefully explained by Eric Lippert over on <a href="http://stackoverflow.com/questions/2057146/compiler-ambiguous-invocation-error-anonymous-method-and-method-group-with-fun">stackoverflow</a>.  Briefly, the ambiguity error arises because both methods equally satisfy the <code>Apply()</code> method signature and the C# standard does not provide a way to judge which would be 'better', and so reports an error.  The fix is simple, we just specified explicitly that we want to use the method that takes a generic Func&lt;&gt;.</p>
<pre lang="csharp">      DoubleVector wInverse =
         svDecomp.SingularValues.Apply(
              new Func< double, double >
                 ( delegate( double w )
                    { return w < eps ? 0.0 : 1.0 / w; }
                 )
         );</pre>
<p>Or, somewhat more concisely using a lamda expression.</p>
<pre lang="csharp">      DoubleVector wInverse =
         svDecomp.SingularValues.Apply(
              new Func< double, double >
                 ( w => w < eps ? 0.0 : 1.0 / w  )
         );</pre>
<h2>A brief Func&lt;&gt; &amp; Action&lt;&gt;  primer</h2>
<p>The generic delegate types, <code>Func&lt;&gt;</code> and <code>Action&lt;&gt;</code>, were introduced with the .NET 3.5 framework to unify delegate types across various .NET libraries.  This allows a .NET library developer like CenterSpace to create an API that accepts generic delegates that are defined elsewhere in client code.  The <code>Func</code> and <code>Action</code> are differentiated by their return values:  <code>Actions</code> have no return value, <code>Funcs</code> always have a <em>single</em> return value of type <code>TResult</code>.  For each of them, the .NET framework defines a type signature that takes between <code>0</code> and <code>16</code> generically typed arguments.</p>
<pre class="code">
<table style="font-size: 7pt;">
<tbody>
<tr>
<th colspan="2"> .NET Func&lt;&gt; and Action&lt;&gt; definitions</th>
</tr>
<tr>
<th>Func</th>
<th>Action</th>
</tr>
<tr>
<td>TResult Func()</td>
<td>void Action&lt;&gt;()</td>
</tr>
<tr>
<td>TResult Func( T arg )</td>
<td>void Action( T arg )</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>TResult Func(
	T1 arg1,
	T2 arg2,
	...
	T15 arg15,
	T16 arg16 )</td>
<td>void Action(
	T1 arg1,
	T2 arg2,
	...
	T15 arg15,
	T16 arg16 )</td>
</tr>
</tbody>
</table>
</pre>
<p>This is still all abstract.  Here's how we create a <code>Func</code> using a lambda expression.</p>
<pre lang="csharp">Func mySquaringFunc =
   new Func< double, double> ( x =>  x*x ); 

double xSquared = mySquaringFunc( 45 );  // xSquared = 2025</pre>
<p>This <code>Func</code> delegate takes single double value and returns a double value.  Lamda expressions are commonly used today to generate delegates, however an anonymous delegate could also be used for the same purpose.</p>
<pre lang="csharp">Func mySquaringFunc =
   new Func< double, double> ( delegate( double x ) { return x*x; } ); 

double xSquared = mySquaringFunc( 45 );  // xSquared = 2025</pre>
<p>I find the lambda syntax to be more expressive and succinct.  From the table above, <code>T1 = double</code>, and <code>TResult = double</code>.</p>
<p><code>Action</code> types are not used within the NMath API because we are always dealing with functions and return values.  However, <code>Actions</code> are similarly defined, and may be used for example in queuing code where a queue manager takes work in the form of <code>Action</code> delegates.</p>
<pre lang="csharp">Action< DoubleVector > FFTWorker =
   new Action< DoubleVector >( v =>
      {
         DoubleComplexForward1DFFT fft = new DoubleComplexForward1DFFT( v.Length );
         fft.FFTInPlace( v );
       } );
...
QueueManager.AddWork( FFTWorker, bigDataVector );</pre>
<p>The <code>Action</code> above computes the in-place FFT, and the <code>QueueManager</code> can now generically schedule this work on the queue.</p>
<p>Happy Computing,<br />
Paul Shirkey</p>
<p><!-- NOTES // Error DoubleVector kernel = new DoubleVector(kernelLength, -8.2 * Math.PI, 1).Transform(Math.Sin); //Fix DoubleVector kernel = new DoubleVector(kernelLength, -8.2*Math.PI,1).Transform( new Func&lt;double, double&gt;( Math.Sin ) ); --></p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-api-updated-with-net-func-delegates">NMath API updated with .NET Func&lt;&gt; delegates</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/nmath-api-updated-with-net-func-delegates/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3711</post-id>	</item>
		<item>
		<title>NMath and Silverlight</title>
		<link>https://www.centerspace.net/nmath-and-silverlight-2</link>
					<comments>https://www.centerspace.net/nmath-and-silverlight-2#comments</comments>
		
		<dc:creator><![CDATA[Trevor Misfeldt]]></dc:creator>
		<pubDate>Thu, 09 Feb 2012 20:26:02 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[math and silverlight]]></category>
		<category><![CDATA[nmath and silverlight]]></category>
		<category><![CDATA[silverlight with nmath]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/uncategorized/nmath-and-silverlight-2/</guid>

					<description><![CDATA[<p>From time to time, we’re asked about the best way to use NMath to build Silverlight applications. Unfortunately, like so many answers in software development, the answer is: it depends. Silverlight is a great way to build line of business applications, but at its core, Silverlight runs within a sandboxed environment, typically within a browser, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-and-silverlight-2">NMath and Silverlight</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>From time to time, we’re asked about the best way to use NMath to build Silverlight applications. Unfortunately, like so many answers in software development, the answer is: <em>it depends</em>.</p>
<p>Silverlight is a great way to build line of business applications, but at its core, Silverlight runs within a sandboxed environment, typically within a browser, and usually within a networked intranet or Internet environment.  NMath, on the other hand, uses native libraries to provide high-performance math capabilities to managed code.  While it’s possible to build a Silverlight application that calls NMath functions, it’s worth taking a step back to look at what you really want to accomplish with your software project.</p>
<p>Most often, we find that developers are tasked with building dashboard-style business applications that allow the user to initiate some sort of data analysis, and then see a visualization of results.  In these cases, we generally recommend:</p>
<p><strong>1) Use Silverlight (or HTML5) on the client, perform the analysis on one or more servers, and expose web services to initiate the analysis and deliver the results.</strong></p>
<p>This is probably the most favorable approach, and usually the architecture to default to unless there’s a compelling reason to the contrary.  Some of the advantages of this approach:</p>
<ul>
<li>It’s consistent with typical Silverlight application architecture; capabilities in Silverlight and ASP.NET make it easy to build this kind of application.</li>
<li>It retains the deployment advantages of Silverlight: there’s no need to distribute and install native components to every client machine.</li>
<li>It retains the cross-platform advantages of Silverlight: the application will work smoothly regardless of client hardware (including on Mac OS).</li>
<li>Centralizing the analysis on a server makes it easier to scale up with improved server hardware and/or server farms.</li>
<li>It makes efficient use of network bandwidth: usually there’s little need to transfer all of the source data between client and server, just the results of the analysis.</li>
</ul>
<p>The primary disadvantages of this approach include:</p>
<ul>
<li>This might drive an architectural shift if it’s not already working in a client-server environment.</li>
<li>It doesn’t take maximum advantage of available computing resources on the client, at least for the analysis (although the application can potentially use the client’s GPU for the visualization).</li>
</ul>
<p>If you’re certain that you want to perform the analysis on the client using a Silverlight application, you can:</p>
<p><strong>2) Use Silverlight 4+, and use COM interop to invoke COM components that were previously installed on the client.</strong></p>
<p><strong>3) Use Silverlight 5, and use Platform Invoke (P/Invoke) to invoke native components.</strong></p>
<p>There are significant disadvantages to these approaches, in particular:</p>
<ul>
<li>You would need to separately distribute your components and get them preinstalled on the local machine.</li>
<li>The client applications will only run on Windows; you cannot invoke native code on Mac OS from Silverlight.</li>
<li>Users will need to explicitly grant elevated trust to the Silverlight application.</li>
<li>You would also need to build your application with out of browser support (if you’re using COM interop).</li>
</ul>
<p>For the COM interop approach you would use ComAutomationFactory.CreateObject() to instantiate dynamic COM objects, which would also mean that you would require C# 4, Silverlight 4, and Visual Studio 2010.  This approach is less than ideal for new applications; it&#8217;s primarily intended for interaction within controlled environments (e.g. interop with Microsoft Office).  For more about this, see:</p>
<ul>
<li>Silverlight and Desktop .NET Integration</li>
<li><a href="http://justinangel.net/CuttingEdgeSilverlight4ComFeatures" target="_blank" rel="noopener">Cutting Edge Silverlight4 COM+ Features</a></li>
</ul>
<p>For information about P/Invoke in Silverlight 5, see:</p>
<ul>
<li><a href="https://msdn.microsoft.com/en-us/library/hh560563(v=vs.95).aspx" target="_blank" rel="noopener">How to: Call Unmanaged Code from Trusted Applications</a></li>
</ul>
<p>However, if you’re certain that you want to build a rich client application to perform the analysis on Windows, then you should also evaluate whether Silverlight is the best choice for doing so.  Some alternatives include:</p>
<p><strong>4) Create a rich client application using Windows Presentation Foundation, and run in within the browser using XBAP.</strong></p>
<p>XBAP applications are WPF applications that run in partial trust inside a web browser.  You do have access to more local resources than you do in Silverlight, and you can request the user to grant additional trust if needed.  You&#8217;re restricted to using Internet Explorer and Firefox.  For more about this, see:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/aa970060.aspx" target="_blank" rel="noopener">WPF XAML Browser Applications Overview</a></li>
<li><a href="https://en.wikipedia.org/wiki/XBAP" target="_blank" rel="noopener">Wikipedia: XAML Browser Applications</a></li>
<li><a href="http://www.xbap.org/" target="_blank" rel="noopener">XBap.org</a></li>
</ul>
<p><strong>5) Create a rich client application using Windows Presentation Foundation or Windows Forms, and distribute it via ClickOnce Deployment.</strong></p>
<p>In this scenario, you&#8217;re running a full client application within Windows, but taking advantage of some of the deployment advantages of the web, including initial distribution and facilities for automatic application updates.  Generally speaking, this is the preferred way to build rich client applications on Windows.  For more about ClickOnce, see:</p>
<ul>
<li><a href="https://msdn.microsoft.com/en-US/library/t71a733d(v=VS.100).aspx" target="_blank" rel="noopener">ClickOnce Security and Deployment</a></li>
<li><a href="https://en.wikipedia.org/wiki/ClickOnce" target="_blank" rel="noopener">Wikipedia: ClickOnce</a></li>
</ul>
<p>Our experienced consulting team is available to help you work through the architectural options that would make the most sense for your specific application; just contact us at <a href="mailto:consulting@centerspace.net">consulting@centerspace.net</a>.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/nmath-and-silverlight-2">NMath and Silverlight</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/nmath-and-silverlight-2/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3698</post-id>	</item>
		<item>
		<title>Clearing a vector</title>
		<link>https://www.centerspace.net/clearing-a-vector</link>
					<comments>https://www.centerspace.net/clearing-a-vector#respond</comments>
		
		<dc:creator><![CDATA[Trevor Misfeldt]]></dc:creator>
		<pubDate>Wed, 09 Nov 2011 22:28:01 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[clearing a matrix]]></category>
		<category><![CDATA[clearing a vector]]></category>
		<category><![CDATA[NMath matirx]]></category>
		<category><![CDATA[NMath vector]]></category>
		<category><![CDATA[zeroing a matrix]]></category>
		<category><![CDATA[zeroing a vector]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3621</guid>

					<description><![CDATA[<p>A customer recently asked us for the best method to zero out a vector. We decided to run some tests to find out. Here are the five methods we tried followed by performance timing and any drawbacks. The following tests were performed on a DoubleVector of length 10,000,000. 1) Create a new vector. This isn&#8217;t [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/clearing-a-vector">Clearing a vector</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A customer recently asked us for the best method to zero out a vector. We decided to run some tests to find out. Here are the five methods we tried followed by performance timing and any drawbacks.</p>
<p>The following tests were performed on a <code>DoubleVector</code> of length 10,000,000.</p>
<p>1) Create a new vector. This isn&#8217;t really clearing out an existing vector but we thought we should include it for completeness.</p>
<pre lang="csharp" line="1"> DoubleVector v2 = new DoubleVector( v.Length, 0.0 );</pre>
<p>The big drawback here is that you&#8217;re creating new memory. Time: <strong>419.5ms</strong></p>
<p>2) Probably the first thing to come to mind is to simply iterate through the vector and set everything to zero.</p>
<pre lang="csharp" line="1">
for ( int i = 0; i < v.Length; i++ )
{
  v[i] = 0.0;
}</pre>
<p>We have to do some checking in the index operator. No new memory is created. Time: <strong>578.5ms</strong></p>
<p>3) In some cases, you could iterate through the underlying array of data inside the DoubleVector.</p>
<pre lang="csharp" line="1"> 
for ( int i = 0; i &lt; v.DataBlock.Data.Length; i++ )
{
  v.DataBlock.Data[i] = 0.0;
}</pre>
<p>This is a little less intuitive. And, very importantly, it will not work with many views into other data structures. For example, a row slice of a matrix. However, it's easier for the CLR to optimize this loop. Time: <strong>173.5ms</strong></p>
<p>4) We can use the power of Intel's MKL to multiply the vector by zero.</p>
<pre lang="csharp" line="1"> v.Scale( 0.0 );</pre>
<p>Scale() does this in-place. No new memory is created. In this example, we assume that MKL has already been loaded and is ready to go which is true if another MKL-based NMath call was already made or if NMath was <a href="/initializing-nmath/">initialized</a>. This method will work on all views of other data structures. Time: <strong>170ms</strong></p>
<p>5) This surprised us a bit but the best method we could find was to clear out the underlying array using Array.Clear() in .NET</p>
<pre lang="csharp" line="1"> Array.Clear( v.DataBlock.Data, 0, v.DataBlock.Data.Length );</pre>
<p>This creates no new memory. However, this will not work with non-contiguous views. However, this method is very fast. Time: <strong> 85.8ms</strong></p>
<p>To make efficiently clearing a vector simpler for NMath users we have created a <code>Clear()</code> method and a <code>Clear( Slice )</code> method on the vector and matrix classes.  It will do the right thing in the right circumstance. It will be released in NMath 5.2 in 2012.</p>
<h3> Test Code </h3>
<pre lang="csharp" line="1">
using System;
using CenterSpace.NMath.Core;

namespace Test
{
  class ClearVector
  {
    static int size = 100000000;
    static int runs = 10;
    static int methods = 5;
    
    static void Main( string[] args )
    {
      System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
      DoubleMatrix times = new DoubleMatrix( runs, methods );
      NMathKernel.Init();

      for ( int run = 0; run < runs; run++ )
      {
        Console.WriteLine( "Run {0}...", run );
        DoubleVector v = null;

        // Create a new one
        v = new DoubleVector( size, 1.0, 2.0 );
        sw.Start();
        DoubleVector v2 = new DoubleVector( v.Length, 0.0 );
        sw.Stop();
        times[run, 0] = sw.ElapsedMilliseconds;
        Console.WriteLine( Assert( v2 ) );

        // iterate through vector
        v = new DoubleVector( size, 1.0, 2.0 );
        sw.Reset();
        sw.Start();
        for ( int i = 0; i < v.Length; i++ )
        {
          v[i] = 0.0;
        }
        sw.Stop();
        times[run, 1] = sw.ElapsedMilliseconds;
        Console.WriteLine( Assert( v ) );

        // iterate through array
        v = new DoubleVector( size, 1.0, 2.0 );
        sw.Reset();
        sw.Start();
        for ( int i = 0; i < v.DataBlock.Data.Length; i++ )
        {
          v.DataBlock.Data[i] = 0.0;
        }
        sw.Stop();
        times[run, 2] = sw.ElapsedMilliseconds;
        Console.WriteLine( Assert( v ) );
        
        // scale
        v = new DoubleVector( size, 1.0, 2.0 );
        sw.Reset();
        sw.Start();
        v.Scale( 0.0 );
        sw.Stop();
        times[run, 3] = sw.ElapsedMilliseconds;
        Console.WriteLine( Assert( v ) );

        // Array Clear
        v = new DoubleVector( size, 1.0, 2.0 );
        sw.Reset();
        sw.Start();
        Array.Clear( v.DataBlock.Data, 0, v.DataBlock.Data.Length );
        sw.Stop();
        times[run, 4] = sw.ElapsedMilliseconds;
        Console.WriteLine( Assert( v ) );
        Console.WriteLine( times.Row( run ) );
      }
      Console.WriteLine( "Means: " + NMathFunctions.Mean( times ) );
    }

    private static bool Assert( DoubleVector v )
    {
      if ( v.Length != size )
      {
        return false;
      }
      for ( int i = 0; i < v.Length; ++i )
      {
        if ( v[i] != 0.0 )
        {
          return false;
        }
      }
      return true;
    }
  }
}
</pre>
<p>- Trevor</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/clearing-a-vector">Clearing a vector</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/clearing-a-vector/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3621</post-id>	</item>
		<item>
		<title>FFT Performance Benchmarks in .NET</title>
		<link>https://www.centerspace.net/fft-performance-benchmarks-in-net</link>
					<comments>https://www.centerspace.net/fft-performance-benchmarks-in-net#respond</comments>
		
		<dc:creator><![CDATA[Paul Shirkey]]></dc:creator>
		<pubDate>Wed, 05 Jan 2011 20:07:46 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[FFT]]></category>
		<category><![CDATA[FFT .NET benchmarks]]></category>
		<category><![CDATA[FFT benchmarks]]></category>
		<category><![CDATA[fft C#]]></category>
		<category><![CDATA[FFT in .NET]]></category>
		<category><![CDATA[Multicore FFT]]></category>
		<category><![CDATA[NMATH FFT and FFTW]]></category>
		<category><![CDATA[Non power of 2 FFT]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2942</guid>

					<description><![CDATA[<p>We've had a number of inquires about the CenterSpace FFT benchmarks, so I thought I would code up a few tests and run them on my machine.  I've included our FFT performance numbers and the code that generated those numbers so you can try them on your machine.  (If you don't have NMath, you'll need to download the <a href="https://www.centerspace.net/downloads/trial-versions/">eval version</a>).  I also did a head-to-head comparison with FFTW, one of the fastest desktop FFT implementations.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/fft-performance-benchmarks-in-net">FFT Performance Benchmarks in .NET</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We&#8217;ve had a number of inquires about the CenterSpace FFT benchmarks, so I thought I would code up a few tests and run them on my machine.  I&#8217;ve included our FFT performance numbers and the code that generated those numbers so you can try them on your machine.  (If you don&#8217;t have NMath, you&#8217;ll need to download the <a href="/trial-version/">eval version</a>).  I also did a comparison of 1 dimensional real DFTs, with FFTW, one of the fastest desktop FFT implementations available.</p>
<h3> Benchmarks </h3>
<p>These benchmarks were run on a 2.80 Ghz, Intel Core i7 CPU, with 4Gb of memory installed. </p>
<pre class="code">
The clock resolution is 0.003 ns
1024 point, forward, real FFT required 4361.364 ns, Mflops 4069
1000 point, forward, real FFT required 5338.785 ns, Mflops 3235
4096 point, forward, real FFT required 21708.565 ns, Mflops 3924
4095 point, forward, real FFT required 43012.010 ns, Mflops 1980
1024 * 1024 point, forward, real FFT required 15.635 ms, Mflops 2324
</pre>
<p>I&#8217;m estimating the megaflop performance during the FFT using:<br />
<center><br />
<img decoding="async" src="http://latex.codecogs.com/gif.latex?MFlops \approx {2.5*n \ ln (n)) \over{ \textit{time in} \ \mu s} }" title="MFlops \approx {2.5*n \ ln (n)) \over{ \textit{time in} \ \mu s} }" /><br />
</center></p>
<p>This is the asymptotic number of floating point operations for the radix-2 Cooley-Tukey FFT algorithm. This FFT MFlop estimate is used in a number of FFT benchmark reports and serves as a good basis for comparing algorithm efficiency.</p>
<p>As expected we take a performance hit for non-power of 2 lengths, but due to various optimizations for processing prime length FFT kernels (3, 5, 7 &#038; 11), the performance hit is minimal in many cases. The 1000-point FFT has prime factors <code>(2)(2)(2)(5)(5)(5)</code>, and the 4095-point FFT has prime factors <code>(3)(3)(5)(7)(13)</code>, so those larger prime factors in the 4095-point FFT cost us some performance.  Typically, user&#8217;s zero pad their data vectors to a power-of-two length to get optimal performance.</p>
<h3> Side by side comparison with FFTW </h3>
<p>FFTW claims to be the &#8220;Fastest Fourier Transform in the West&#8221;, and is a clever, high performance implementation of the discrete Fourier transform.  This algorithm is shipped with all copies of MATLAB.  FFTW is implemented in C and has the reputation as being one of the fastest desktop FFT algorithm.  </p>
<p>Both the NMath FFT and the FFTW have a pre-computation setup that establishes the best algorithmic approach for the DFT at hand, before computing any FFT&#8217;s.  This pre-computational phase is not included in the times below.   In the case of the NMath FFT classes, this pre-computational phase in done in the class constructor; Therefore users must avoid constructing NMath FFT classes in tight loops for best performance (as shown in the benchmark code below).  Below is a small side-by-side comparison between FFTW and NMath&#8217;s FFT (using the numbers from above).</p>
<pre class="code">
<table><tbody>
<tr>
<th colspan="3"> Comparison of a forward, real, out-of-place FFT. </th>
</tr>
<tr> 
<th> FFT length</th> <th> FFTW </th> <th> NMATH FFT </th>
</tr>
<tr> 
<td> 1024 </td> <td> 4.14 &mu;s</td> <td> 4.36 &mu;s </td> 
</tr>
<tr> 
<td> 1000</td> <td> 5.98 &mu;s </td> <td> 5.33 &mu;s </td> 
</tr>
<tr> 
<td> 4096</td> <td> 20.31 &mu;s </td> <td> 21.71 &mu;s </td> 
</tr>
<tr> 
<td> 4095</td> <td> 49.90 &mu;s </td> <td> 43.01 &mu;s </td> 
</tr>
<tr> 
<td> 1024^2 </td> <td> 17.16 ms </td> <td> 15.63 ms </td> 
</tr>
</tbody>
</table>
</pre>
<p>Clearly NMATH is very competitive with, and at times out-performs FFTW for real FFT&#8217;s of both power-of-2 length signals and otherwise.  I chose 1D real signals as a test case because this is one of the most frequent use cases of our NMATH FFT library. </p>
<p>On a subjective scale, running a 1024-point FFT on a desktop commodity machine at around (an algorithm normalized) 4 GFlops is amazing.  That means that in a real time measurement situation, users can compute 1024-point FFT&#8217;s at around 220kHz &#8211; all with just a couple of lines of code.</p>
<p>Happy Computing,<br />
<em> Paul </em></p>
<h3> Benchmark Code </h3>
<pre lang="csharp">
 public void BenchMarks()
    {
      Double numberTrials = 10000;
      Double flops;

      Stopwatch timer = new System.Diagnostics.Stopwatch();
      Console.WriteLine( String.Format("The clock resolution is {0:0.000} ns", Stopwatch.Frequency / 1000000000.0 ) );

      // Snip one - power of two
      RandGenUniform rand = new RandGenUniform();
      DoubleForward1DFFT fft = new DoubleForward1DFFT( 1024 );
      DoubleVector realsignal = new DoubleVector( 1024, rand );

      DoubleVector result = new DoubleVector( 1024 * 1024 );

      timer.Reset();
      for( int i = 0; i < numberTrials; i++ )
      {
        timer.Start();
        fft.FFT( realsignal, ref result );
        timer.Stop();
      }
      flops = (2.5 * 1024 * NMathFunctions.Log(1024)) / (((timer.ElapsedTicks / numberTrials) / Stopwatch.Frequency) * 1000000.0 );
      Console.WriteLine( String.Format( "1024 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}", ( ( timer.ElapsedTicks / numberTrials ) / Stopwatch.Frequency ) * 1000000000.0, flops ) );

      // length 1000
      fft = new DoubleForward1DFFT( 1000 );
      realsignal = new DoubleVector( 1000, rand );

      timer.Reset();
      for( int i = 0; i < numberTrials; i++ )
      {
        timer.Start();
        fft.FFT( realsignal, ref result );
        timer.Stop();
      }
      flops = ( 2.5 * 1000 * NMathFunctions.Log( 1000 ) ) / ( ( ( timer.ElapsedTicks / numberTrials ) / Stopwatch.Frequency ) * 1000000.0 );
      Console.WriteLine( String.Format( "1000 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}", ( ( timer.ElapsedTicks / numberTrials ) / Stopwatch.Frequency ) * 1000000000.0, flops ) );

      // length 4096
      fft = new DoubleForward1DFFT( 4096 );
      realsignal = new DoubleVector( 4096, rand );

      timer.Reset();
      for( int i = 0; i < numberTrials; i++ )
      {
        timer.Start();
        fft.FFT( realsignal, ref result );
        timer.Stop();
      }
      flops = ( 2.5 * 4096 * NMathFunctions.Log( 4096 ) ) / ( ( ( timer.ElapsedTicks / numberTrials ) / Stopwatch.Frequency ) * 1000000.0 );
      Console.WriteLine( String.Format( "4096 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}", ( ( timer.ElapsedTicks / numberTrials ) / Stopwatch.Frequency ) * 1000000000.0, flops ) );

      // length 4095
      fft = new DoubleForward1DFFT( 4095 );
      realsignal = new DoubleVector( 4095, rand );

      timer.Reset();
      for( int i = 0; i < numberTrials; i++ )
      {
        timer.Start();
        fft.FFT( realsignal, ref result );
        timer.Stop();
      }
      flops = ( 2.5 * 4095 * NMathFunctions.Log( 4095 ) ) / ( ( ( timer.ElapsedTicks / numberTrials ) / Stopwatch.Frequency ) * 1000000.0 );
      Console.WriteLine( String.Format( "4095 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}", ( ( timer.ElapsedTicks / numberTrials ) / Stopwatch.Frequency ) * 1000000000.0, flops ) );


      // length 1M
      fft = new DoubleForward1DFFT( 1024 * 1024 );
      realsignal = new DoubleVector( 1024 * 1024, rand );

      timer.Reset();
      for( int i = 0; i < 100; i++ )
      {
        timer.Start();
        fft.FFT( realsignal, ref result );
        timer.Stop();
      }
      flops = ( 2.5 * 1024 * 1024 * NMathFunctions.Log( 1024 * 1024 ) ) / ( ( ( timer.ElapsedTicks / 100.0 ) / Stopwatch.Frequency ) * 1000000.0 );
      Console.WriteLine( String.Format( "Million point (1024 * 1024), forward, real point FFT required {0:0.000} ms, Mflops {1:0}", ( ( timer.ElapsedTicks / 100.0 ) / Stopwatch.Frequency ) * 1000.0, flops ) );

    }
</pre>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/fft-performance-benchmarks-in-net">FFT Performance Benchmarks in .NET</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/fft-performance-benchmarks-in-net/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2942</post-id>	</item>
		<item>
		<title>ClickOnce Deployment</title>
		<link>https://www.centerspace.net/clickonce-deployment</link>
					<comments>https://www.centerspace.net/clickonce-deployment#comments</comments>
		
		<dc:creator><![CDATA[Trevor Misfeldt]]></dc:creator>
		<pubDate>Tue, 17 Aug 2010 18:13:16 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ClickOnce Deployment]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2575</guid>

					<description><![CDATA[<p>In general, when you deploy an NMath application you want to ensure that all NMath DLLs in the installation Assemblies directory are installed in either the GAC or next to the application. (You can read an overview of NMath deployment in Section 1.7 the NMath User&#8217;s Guide.) ClickOnce automagically tries to determine the appropriate dependencies [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/clickonce-deployment">ClickOnce Deployment</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In general, when you deploy an NMath application you want to ensure that all NMath DLLs in the installation Assemblies directory are installed in either the GAC or next to the application. (You can read an overview of NMath deployment in <a title="Section 1.3" href="https://www.centerspace.net/doc/NMath/user/overview-83427.htm">Section 1.7</a> the NMath User&#8217;s Guide.)</p>
<p>ClickOnce automagically tries to determine the appropriate dependencies to deploy. However, since the NMath kernel and native DLLs are not required at compile-time, but are required at run-time, the ClickOnce mechanism fails. The best solution we&#8217;ve found is to:</p>
<ol>
<li>Add NMathKernelx86.dll, NMathKernelx64.dll, nmath_native_x86.dll, nmath_native_x64.dll as files to the project.</li>
<li>Set the <strong>Build Action</strong> to <strong>Content</strong>.</li>
<li>Set <strong>Copy to Output Directory</strong> to <strong>Copy Always</strong>.</li>
<li>Publish your project, then go to the publish directory\<strong>Application Files</strong> to verify that these four DLLs have been included.</li>
</ol>
<p>&#8211; Trevor</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/clickonce-deployment">ClickOnce Deployment</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/clickonce-deployment/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2575</post-id>	</item>
	</channel>
</rss>
