<?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>CenterSpace Blog &#187; .NET</title>
	<atom:link href="http://www.centerspace.net/blog/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.centerspace.net/blog</link>
	<description>The CenterSpace blog about our NMath mathematical and statistical libraries in .NET/C#, and object-oriented numerics in general.</description>
	<lastBuildDate>Tue, 13 Dec 2011 17:35:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Clearing a vector</title>
		<link>http://www.centerspace.net/blog/nmath/clearing-a-vector/</link>
		<comments>http://www.centerspace.net/blog/nmath/clearing-a-vector/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 22:28:01 +0000</pubDate>
		<dc:creator>Trevor Misfeldt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3621</guid>
		<description><![CDATA[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, with any drawbacks and the timings. These were performed on a DoubleVector, v,  of length 10,000,000. 1) Create a new vector. This isn&#8217;t really clearing...]]></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, with any drawbacks and the timings.</p>
<p>These were performed on a DoubleVector, v,  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> 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>
for ( int i = 0; i &lt; v.Length; i++ )
{
  v[i] = 0.0;
}</pre>
<p>We have to do some checking in the index operator. No new memory 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>
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&#8217;s easier for the CLR to optimize this loop. Time: <strong>173.5ms</strong></p>
<p>4) We can use the power of Intel&#8217;s MKL to multiply the vector by zero.</p>
<pre> 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="http://www.centerspace.net/blog/nmath/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> 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 this much simpler, we have created a <code>Clear()</code> method and a <code>Clear( Slice)</code> method on vectors and matrices. It will do the right thing in the right circumstance. It will be released in NMath 5.2 in 2012.</p>
<p>And, here is the code we used for this test:</p>
<pre>
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><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.centerspace.net%2Fblog%2Fnmath%2Fclearing-a-vector%2F&amp;title=Clearing%20a%20vector"><img src="http://www.centerspace.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/clearing-a-vector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FFT Performance Benchmarks in .NET</title>
		<link>http://www.centerspace.net/blog/nmath/fft-performance-benchmarks-in-net/</link>
		<comments>http://www.centerspace.net/blog/nmath/fft-performance-benchmarks-in-net/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 20:07:46 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<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[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="http://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.
]]></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="http://www.centerspace.net/downloads/trial-versions/">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 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>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> BenchMarks<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #FF0000;">Double</span> numberTrials <span style="color: #008000;">=</span> <span style="color: #FF0000;">10000</span><span style="color: #008000;">;</span>
      <span style="color: #FF0000;">Double</span> flops<span style="color: #008000;">;</span>
&nbsp;
      Stopwatch timer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">Stopwatch</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;The clock resolution is {0:0.000} ns&quot;</span>, Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">1000000000.0</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// Snip one - power of two</span>
      RandGenUniform rand <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RandGenUniform<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      DoubleForward1DFFT fft <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleForward1DFFT<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1024</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      DoubleVector realsignal <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1024</span>, rand <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      DoubleVector result <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1024</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1024</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      timer.<span style="color: #0000FF;">Reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> numberTrials<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span> <span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        timer.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fft.<span style="color: #0000FF;">FFT</span><span style="color: #000000;">&#40;</span> realsignal, <span style="color: #0600FF;">ref</span> result <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        timer.<span style="color: #0000FF;">Stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
      flops <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2.5</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1024</span> <span style="color: #008000;">*</span> NMathFunctions.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1024</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials<span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000.0</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span> <span style="color: #666666;">&quot;1024 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}&quot;</span>, <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000000.0</span>, flops <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// length 1000</span>
      fft <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleForward1DFFT<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1000</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      realsignal <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1000</span>, rand <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      timer.<span style="color: #0000FF;">Reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> numberTrials<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span> <span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        timer.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fft.<span style="color: #0000FF;">FFT</span><span style="color: #000000;">&#40;</span> realsignal, <span style="color: #0600FF;">ref</span> result <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        timer.<span style="color: #0000FF;">Stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
      flops <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">2.5</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">*</span> NMathFunctions.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1000</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000.0</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span> <span style="color: #666666;">&quot;1000 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}&quot;</span>, <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000000.0</span>, flops <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// length 4096</span>
      fft <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleForward1DFFT<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">4096</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      realsignal <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">4096</span>, rand <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      timer.<span style="color: #0000FF;">Reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> numberTrials<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span> <span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        timer.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fft.<span style="color: #0000FF;">FFT</span><span style="color: #000000;">&#40;</span> realsignal, <span style="color: #0600FF;">ref</span> result <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        timer.<span style="color: #0000FF;">Stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
      flops <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">2.5</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">4096</span> <span style="color: #008000;">*</span> NMathFunctions.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">4096</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000.0</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span> <span style="color: #666666;">&quot;4096 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}&quot;</span>, <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000000.0</span>, flops <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// length 4095</span>
      fft <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleForward1DFFT<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">4095</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      realsignal <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">4095</span>, rand <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      timer.<span style="color: #0000FF;">Reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> numberTrials<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span> <span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        timer.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fft.<span style="color: #0000FF;">FFT</span><span style="color: #000000;">&#40;</span> realsignal, <span style="color: #0600FF;">ref</span> result <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        timer.<span style="color: #0000FF;">Stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
      flops <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">2.5</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">4095</span> <span style="color: #008000;">*</span> NMathFunctions.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">4095</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000.0</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span> <span style="color: #666666;">&quot;4095 point, forward, real FFT required {0:0.000} ns, Mflops {1:0}&quot;</span>, <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> numberTrials <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000000.0</span>, flops <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
      <span style="color: #008080; font-style: italic;">// length 1M</span>
      fft <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleForward1DFFT<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1024</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1024</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      realsignal <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1024</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1024</span>, rand <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      timer.<span style="color: #0000FF;">Reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">100</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span> <span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        timer.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        fft.<span style="color: #0000FF;">FFT</span><span style="color: #000000;">&#40;</span> realsignal, <span style="color: #0600FF;">ref</span> result <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        timer.<span style="color: #0000FF;">Stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
      flops <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">2.5</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1024</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1024</span> <span style="color: #008000;">*</span> NMathFunctions.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">1024</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1024</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">100.0</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000000.0</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span> <span style="color: #666666;">&quot;Million point (1024 * 1024), forward, real point FFT required {0:0.000} ms, Mflops {1:0}&quot;</span>, <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> timer.<span style="color: #0000FF;">ElapsedTicks</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">100.0</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> Stopwatch.<span style="color: #0000FF;">Frequency</span> <span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000.0</span>, flops <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/fft-performance-benchmarks-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ClickOnce Deployment</title>
		<link>http://www.centerspace.net/blog/net/clickonce-deployment/</link>
		<comments>http://www.centerspace.net/blog/net/clickonce-deployment/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 18:13:16 +0000</pubDate>
		<dc:creator>Trevor Misfeldt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ClickOnce Deployment]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2575</guid>
		<description><![CDATA[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.3 the NMath User&#8217;s Guide.) ClickOnce automagically tries to determine the appropriate dependencies...]]></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="http://www.centerspace.net/doc/NMath/user/overview4.html#81117">Section 1.3</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>- Trevor</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.centerspace.net%2Fblog%2Fnet%2Fclickonce-deployment%2F&amp;title=ClickOnce%20Deployment"><img src="http://www.centerspace.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/net/clickonce-deployment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nevron Partnership</title>
		<link>http://www.centerspace.net/blog/corporate/nevron-partnership/</link>
		<comments>http://www.centerspace.net/blog/corporate/nevron-partnership/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 16:00:57 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Corporate]]></category>
		<category><![CDATA[charting with NMath]]></category>
		<category><![CDATA[data smoothing]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[linear regression]]></category>
		<category><![CDATA[math charts]]></category>
		<category><![CDATA[Nevron Partnership]]></category>
		<category><![CDATA[polyfit]]></category>
		<category><![CDATA[process control charts]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1903</guid>
		<description><![CDATA[<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit-300x216.png" alt="" title="Fitting a polynomial to some sample data."  class="excerpt" />  All of us at CenterSpace software are proud to announce a partnership with <a href="http://www.nevron.com">Nevron</a>, leaders in data visualization.   Nevron builds .NET components which enable developers to quickly build clean, enterprise quality, user interfaces incorporating well rendered maps, gauges, diagrams, or charts.  Check out our <a href="http://www.centerspace.net/partners/nevron" >partnership page</a> for more information and free examples.]]></description>
			<content:encoded><![CDATA[<p>All of us at CenterSpace software are proud to announce a partnership with <a href="http://www.nevron.com">Nevron</a>, leaders in data visualization.  <img src="http://www.centerspace.net/blog/wp-content/uploads/2010/03/NevronChartArt.jpg" alt="Nevron Chart Visualizations" title="NevronChartArt" width="308" height="239" class="alignright size-full wp-image-1905" /> Nevron builds .NET components which enable developers to quickly build clean, enterprise quality, user interfaces incorporating well rendered maps, gauges, diagrams, or charts.  Nevron has built it&#8217;s visualization framework with the developer in mind and has created components that are powerful, yet quick to pick up and work with.  </p>
<h3> Free Project Examples </h3>
<p>As part of of this partnership our software engineers are working together to develop a series of example applications to help our customers quickly become productive using our tool set.  Our first example demonstrates how to use the Nevron .NET chart component with some of NMath Stat&#8217;s fundamental capabilities: regression and prediction, polynomial curve fitting, and data smoothing.  <a href="http://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit.png"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit-300x216.png" alt="" title="Fitting a polynomial to some sample data." width="300" height="216" class="alignleft size-medium wp-image-1907" /></a> To build and run this example, you&#8217;ll need to download this VS8 project, along with evaluation copies of the CenterSpace NMath Suite and the Nevron .NET Chart package. All of this is freely available from our <a href="http://www.centerspace.net/partners/nevron">partnership page</a>.</p>
<p>As I mentioned this is the first in a series of examples that we will be jointly developing.  Our next example application is in the planning stages, and will cover the building of common charts in statistical process control.  Statistical process control is employed across many industries ranging from manufacturing to medicine and has been an area of interest by customers of both companies.  We&#8217;ll post up a blog article about the example once it&#8217;s finished and you&#8217;ll see a tweet about it if you are <a href="http://twitter.com/centerspacesoft">following us</a>.  </p>
<p>If you have an idea for an example using Nevon&#8217;s and CenterSpace&#8217;s tools together, which would help speed along your own project, leave a comment or drop us an email.   We just may cook it up!</p>
<h3> Discount Bundle </h3>
<p>As part of our partnership with Nevron, we are able to offer a substantial discount on package licenses.  If you are interested, please email our <a href="mailto:sales@centerspace.net">sales</a> staff and request the Nevron partnership discount.</p>
<p>Thanks for reading,</p>
<p><em>-The CenterSpace Team</em><br />
<br />
<b> Resources </b></p>
<ul>
<li>CenterSpace partnership information <a href="http://www.centerspace.net/partners/nevron">partnership page</a>.
<li>Nevron technology partnership information <a href="http://www.nevron.com/Nevron.Company.Partners.TechnologyPartners.aspx">page</a>.
<li>Nevron&#8217;s .NET Chart <a href="http://www.nevron.com/Products.ChartFor.NET.Overview.aspx"> home page</a>.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/corporate/nevron-partnership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Excel with NMath</title>
		<link>http://www.centerspace.net/blog/net/using-excel-with-nmath/</link>
		<comments>http://www.centerspace.net/blog/net/using-excel-with-nmath/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 12:24:15 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Support]]></category>
		<category><![CDATA[calling C# from VBA]]></category>
		<category><![CDATA[calling excel from .NET assembly]]></category>
		<category><![CDATA[COM .NET interop]]></category>
		<category><![CDATA[Excel functions]]></category>
		<category><![CDATA[Excel math functions]]></category>
		<category><![CDATA[Excel port c#]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1043</guid>
		<description><![CDATA[<img src="http://s84547.gridserver.com/blog/./blog/wp-content/uploads/2010/02/233px-Microsoft_Excel_Icon.svg_.png" alt="" title="Excel Icon"  class="excerpt" />
We've had several customers ask about porting their Excel model to a .NET language in order to leverage the performance and functionality of NMath or NMath Stats. NMath does have good crossover functionality with Excel making this porting job easier. It is also possible to accelerate your Excel models by calling the NMath .NET assemblies directly from a VBA macro in Excel. This post provides some guidance for porting all or just a portion of your Excel model to C# and NMath.]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve had several customers ask about porting their Excel model to a .NET language in order to leverage the performance and functionality of NMath or NMath Stats. NMath does have good crossover functionality with Excel making this porting job easier. It is also possible to accelerate your Excel models by calling the NMath .NET assemblies directly from a VBA macro in Excel . This post provides some guidance for porting all or just a portion of your Excel model to C# and NMath.</p>
<p>Excel is designed to interoperate with external assemblies from VBA using COM.  Type libraries built in .NET are not directly COM compatible, however all .NET class libraries including NMath and NMath Stats can be made to present a COM interface making Excel interop possible. This interop is acheived by building the <em>COM type library</em> directly from the assembly &#8211; no recompiling needed &#8211; using a tool shipped with the .NET framework, and then adding this type library as a reference to an Excel sheets&#8217; VBA macro.  Because of the many differences between the C# language and VBA, only a small portion of NMath will be accessable from Excel using this procedure, however a simple remedy will be outlined below that can expand the available functionality to all of NMath.</p>
<ol>
<li>To build the type library interface to the NMath.dll use the <code>regasm.exe</code> utility shipped with the .NET framework <quote>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"> <span style="color: #339933;">&gt;</span>regasm.<span style="color: #202020;">exe</span> NMath.<span style="color: #202020;">dll</span> <span style="color: #339933;">/</span>tlb<span style="color: #339933;">:</span>NMathCom.<span style="color: #202020;">tlb</span></pre></div></div>

<p> </quote>  The COM compatible type library now resides in the <code> NMathCom.tlb</code> file.  You will see some warning messages regarding incompatibilities between COM and NMath.</p>
<li>Open a spreadsheet, right click on a sheet tab and choose <b>View Code</b>  to open the VBA development environment.
<li>In the <b>Tools</b> menu select <b>References&#8230;</b> and browse to the location of the new NMath type library.
</ol>
<p>Now the COM compatible portions of NMath are now available for use from VBA.  At this point we can code up simple example for generating random numbers in VBA to test out the NMath interoperability</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> TestNMath<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #0600FF;">Dim</span> rand <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> NMath.<span style="color: #0000FF;">RandGenLogNormal</span>
  rand.<span style="color: #0000FF;">Mean</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span>
  rand.<span style="color: #0000FF;">Variance</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span>
&nbsp;
  <span style="color: #0600FF;">Dim</span> i <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span>
  <span style="color: #FF8000;">For</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span> <span style="color: #FF8000;">To</span> <span style="color: #FF0000;">10</span>
    Cells<span style="color: #000000;">&#40;</span>i, <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> rand.<span style="color: #FF8000;">Next</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #FF8000;">Next</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></div></div>

<p>This simple VBA script populates cells A1:A10 with LogNormal distributed random numbers with a mean of 50 and a variance of 10.  This is not so easily achieved within Excel natively.<br />
<span id="more-1043"></span><br />
Because NMath was not designed from the ground up to interoperate with the aging COM standard, many types will not be useable from VBA.  All types lacking an empty (default) constructor, generic classes, static methods, and all static classes are not directly usable from VBA.  However, any of these incompatible classes or methods can be wrapped in VB and then made available to Excel via COM.  We understand many Excel users are not C#/.NET experts and so we are happy to help wrapping any <a href="http://www.centerspace.net/products/nmath/">NMath classes</a> or <a href="http://www.centerspace.net/products/nmathstats/">NMath Stats classes</a> you may need for enhancing and accelerating your Excel models.    </p>
<h2> Porting Excel Models to C# using NMath </h2>
<p>As models grow in Excel, they commonly devolve into a  bizantine workbook that becomes slow, opaque, and difficult to version, debug and manage.  Usually, it is at this point that users start looking at porting the complex portions to another compatible platform, typically VB.  These workbooks tend to be business critical applications so the port must be done carefully and in a piecewise fashion.   This conservative strategy can be acheived using the following steps.</p>
<ol>
<li> Identify the computationally demanding and complex portion of the spreadsheet carefully selecting a separation point where the interface is thin between the workbook and the new VB class.
<li> Identify all of the input and output cells of this computation.
<li> Create build a VB wrapper class in a (class library) VB project that wraps the functionality necessary for the port.  This class should include methods for loading and returning results in types compatible with VBA.
<li> Build the library and generate the COM type library and add this new type library to the workbook&#8217;s VBA.
<li> Test the new model in parallel with the existing model.
<li> Remove the duplicated Excel computation and enjoy the new faster model.
</ol>
<p>Porting functionality from an Excel model to a VB type library can be facilitated by NMath due to the large crossover in functionality between Excel and NMath Stats.  Also, due to NMath&#8217;s high performance, once ports are complete, considerable performance gains can be expected.  Below is a table of Excel functions and their supporting classes in either NMath Stats or native .NET.   </p>
<p>Happy Computing,</p>
<p>-Paul</p>
<p><em> Resources </em></p>
<ul>
<li>Microsoft ported the Excel financial functions to F#, making them accessible to any VB or C# project.  Follow this <a href="http://code.msdn.microsoft.com/FinancialFunctions">link</a> to download this library and read the libraries&#8217; documentation and limitations.
<li>Microsoft&#8217;s landing page on the <a href="http://msdn.microsoft.com/en-us/library/tzat5yw6(VS.80).aspx">assembly registration tool</a> <code>regasm.exe</code> for building the COM type libraries.
<li>A little dated but clear and complete <a href="http://richnewman.wordpress.com/2007/04/15/a-beginner’s-guide-to-calling-a-net-library-from-excel/">article</a> on accessing .NET assemblies from Excel.
</ul>
<h2> Excel Functions Supported in NMath and .NET </h2>
<p>Between the NMath and NMath Stats numeric libraries and the .NET framework many of the Excel functions are covered for a port to C#.  If you have a math function that you need which is not covered or is not in this list, let us know and we can probably add it to NMath or NMath Stats.  Note resources above if financial functions are needed.</p>
<table border="1" cellpadding=5 align="center" width="500">
<tr>
<th> Excel Function </th>
<th> Framework/NameSpace </th>
<th> Class/Method</th>
<tr>
<td>ABS
<td> NMath.Core
<td> NMathFunctions.Abs()</p>
<tr>
<td>ACOS
<td> NMath.Core
<td> NMathFunctions.ACos()</p>
<tr>
<td>AND
<td> NMath.Core
<td> NMathFunctions.And()</p>
<tr>
<td>ASIN
<td> NMath.Core
<td> NMathFunctions.ASin()</p>
<tr>
<td>AREAS
<td>No
<td>
<tr>
<td>ASIN
<td> NMath.Core
<td>NMathFunctions.Asin()</p>
<tr>
<td>ASINH
<td>No
<td>
<tr>
<td>ATAN
<td>NMath.Core
<td>NMathFunctions.Atan()</p>
<tr>
<td>ATAN2
<td>NMath.Core
<td>NMathFunctions.Atan2()</p>
<tr>
<td>ATANH
<td>No
<td>
<tr>
<td>AVEDEV
<td>NMath.Stats
<td>StatsFunctions.MeanDeviation()</p>
<tr>
<td>AVERAGE
<td>NMath.Stats
<td>StatsFunctions.Mean()</p>
<tr>
<td>AVERAGEA
<td>No
<td>
<tr>
<td>BETADIST
<td>NMath.Stats
<td>BetaDistribution class</p>
<tr>
<td>BETAINV
<td>NMath.Stats
<td>InverseCDF method in BetaDistribution class</p>
<tr>
<td>BINOMDIST
<td>NMath.Stats
<td>BinomialDistribution class</p>
<tr>
<td>CALL
<td>.NET
<td>
<tr>
<td>CEILING
<td>NMath.Core
<td>NMathFunctions.Ceil()</p>
<tr>
<td>CELL
<td>No
<td>
<tr>
<td>CHAR
<td>No
<td>
<tr>
<td>CHIDIST
<td>NMath.Stats
<td>ChiSquareDistribution class</p>
<tr>
<td>CHIINV
<td>NMath.Stats
<td>InverseCDF method in ChiSquareDistribution class</p>
<tr>
<td>CHITEST
<td>No
<td>
<tr>
<td>CHOOSE
<td>No
<td>
<tr>
<td>CLEAN
<td>No
<td>
<tr>
<td>CODE
<td>No
<td>
<tr>
<td>COLUMN
<td>No
<td>
<tr>
<td>COLUMNS
<td>NMath.Core
<td>DataFrame class using Cols property </p>
<tr>
<td>COMBIN
<td>NMath.Stats
<td>StatsFunctions.Binomial()</p>
<tr>
<td>CONCATENATE
<td>.NET
<td>
<tr>
<td>CONFIDENCE
<td>NMath.Stats
<td>OneSampleZTest class using LowerConfidenceBound or UpperConfidenceBound properties </p>
<tr>
<td>CORREL
<td>NMath.Stats
<td>StatsFunctions.Correlation()</p>
<tr>
<td>COS
<td>NMath.Core
<td>NMathFunctions.Cos()</p>
<tr>
<td>COSH
<td>NMath.Core
<td>NMathFunctions.Cosh()</p>
<tr>
<td>COUNT
<td>NMath.Stats
<td>StatsFunctions.Count()</p>
<tr>
<td>COUNTBLANK
<td>NMath.Stats
<td>If blanks are represented by NaNs then use StatsFunctions.NaNCount()</p>
<tr>
<td>COUNTIF
<td>NMath.Stats
<td>StatsFunctions.CountIf()</p>
<tr>
<td>COVAR
<td>NMath.Stats
<td>StatsFunctions.Covariance()</p>
<tr>
<td>CRITBINOM
<td>NMath.Stats
<td>BinomialDistribution class</p>
<tr>
<td>DATE
<td>.NET
<td>
<tr>
<td>DATEVALUE
<td>.NET
<td>
<tr>
<td>DAVERAGE
<td>NMath.Stats
<td>StatsFunctions.If() to get Subset then StatsFunctions.Mean()</p>
<tr>
<td>DAY
<td>.NET
<td>
<tr>
<td>DAYS360
<td>.NET
<td>
<tr>
<td>DB
<td>No
<td>
<tr>
<td>DCOUNT
<td>NMath.Stats
<td>StatsFunctions.CountIf()</p>
<tr>
<td>DCOUNTA
<td>NMath.Stats
<td>If blanks are represented by NaNs then use StatsFunctions.NaNCountIf()</p>
<tr>
<td>DDB
<td>No
<td>
<tr>
<td>DEGREES
<td>No
<td>
<tr>
<td>DEVSQ
<td>NMath.Stats
<td>StatsFunctions.SumOfSquares()</p>
<tr>
<td>DGET
<td>NMath.Stats
<td>StatsFunctions.If() and then index property on resulting DataFrame</p>
<tr>
<td>DMAX
<td>NMath.Stats
<td>StatsFunctions.If() to create Subset then StatsFunctions.Max()</p>
<tr>
<td>DMIN
<td>NMath.Stats
<td>StatsFunctions.If() to create Subset then StatsFunctions.Min()</p>
<tr>
<td>DOLLAR
<td>.NET
<td>
<tr>
<td>DPRODUCT
<td>NMath.Stats
<td>StatsFunctions.If() to create Subset then to DoubleVector() then NMathFunctions.Product()</p>
<tr>
<td>DSTDEV
<td>NMath.Stats
<td>StatsFunctions.If() to create Subset then StatsFunctions.StandardDeviation(BiasType.Unbiased)</p>
<tr>
<td>DSTDEVP
<td>NMath.Stats
<td>StatsFunctions.If() to create Subset then StatsFunctions.StandardDeviation()</p>
<tr>
<td>DSUM
<td>NMath.Stats
<td>StatsFunctions.SumIf()</p>
<tr>
<td>DVAR
<td>NMath.Stats
<td>StatsFunctions.If() to create Subset then toDoubleVector() then NMathFunctions.Variance(BiasType.Unbiased)</p>
<tr>
<td>DVARP
<td>NMath.Stats
<td>StatsFunctions.If() to create Subset then toDoubleVector() then NMathFunctions.Variance()</p>
<tr>
<td>ERROR.TYPE
<td>No
<td>
<tr>
<td>EVEN
<td>.NET
<td>
<tr>
<td>EXACT
<td>.NET
<td>
<tr>
<td>EXP
<td>NMath.Core
<td>NMathFunctions.Exp()</p>
<tr>
<td>EXPONDIST
<td>NMath.Stats
<td>ExponentialDistribution class</p>
<tr>
<td>FACT
<td>NMath.Stats
<td>StatsFunctions.Factorial()</p>
<tr>
<td>FALSE
<td>.NET
<td>
<tr>
<td>FDIST
<td>NMath.Stats
<td>FDistribution class</p>
<tr>
<td>FIND
<td>.NET
<td>
<tr>
<td>FINV
<td>NMath.Stats
<td>InverseCDF method in FDistribution class</p>
<tr>
<td>FISHER
<td>No
<td>
<tr>
<td>FISHERINV
<td>No
<td>
<tr>
<td>FIXED
<td>.NET
<td>
<tr>
<td>FLOOR
<td>NMath.Core
<td>NMathFunctions.Floor()</p>
<tr>
<td>FORECAST
<td>NMath.Stats
<td>LinearRegression class in Stats</p>
<tr>
<td>FREQUENCY
<td>NMath.Stats
<td>StatsFunctions.Mode() for frequency, use StatsFunctions.If() to find the indicies.</p>
<tr>
<td>FTEST
<td>NMath.Stats
<td>TwoSampleFTest class in Stats</p>
<tr>
<td>FV
<td>No
<td>
<tr>
<td>GAMMADIST
<td>NMath.Stats
<td>GammaDistribution class</p>
<tr>
<td>GAMMAINV
<td>NMath.Stats
<td>InverseCDF method in GammaDistribution class</p>
<tr>
<td>GAMMALN
<td>NMath.Stats
<td>StatsFunctions.GammaLn()</p>
<tr>
<td>GEOMEAN
<td>NMath.Stats
<td>StatsFunctions.GeometricMean()</p>
<tr>
<td>GETPIVOTDATA
<td>No
<td>
<tr>
<td>GROWTH
<td>NMath.Stats
<td>LinearRegression class in Stats</p>
<tr>
<td>HARMEAN
<td>NMath.Stats
<td>StatsFunctions.HarmonicMean()</p>
<tr>
<td>HLOOKUP
<td>No
<td>
<tr>
<td>HOUR
<td>.NET
<td>
<tr>
<td>HYPERLINK
<td>.NET
<td>
<tr>
<td>HYPGEOMDIST
<td>No
<td>
<tr>
<td>IF
<td>NMath.Stats
<td>StatsFunctions.If()</p>
<tr>
<td>INDEX
<td>NMath.Core
<td>Index properties in vector, matrices, columns and frames</p>
<tr>
<td>INDIRECT
<td>No
<td>
<tr>
<td>INFO
<td>.NET
<td>
<tr>
<td>INT
<td>.NET
<td>
<tr>
<td>INTERCEPT
<td>NMath.Stats
<td>LinearRegression class in Stats</p>
<tr>
<td>IPMT
<td>No
<td>
<tr>
<td>IRR
<td>No
<td>
<tr>
<td>ISBLANK
<td>NMath.Core
<td>Can use NaN to indicate missing value. Then use Double.IsNaN(cell) to verify.</p>
<tr>
<td>ISERROR
<td>No
<td>
<tr>
<td>ISLOGICAL
<td>No
<td>
<tr>
<td>ISNA
<td>No
<td>
<tr>
<td>ISNONTEXT
<td>No
<td>
<tr>
<td>ISNUMBER
<td>No
<td>
<tr>
<td>ISPMT
<td>No
<td>
<tr>
<td>ISREF
<td>No
<td>
<tr>
<td>ISTEXT
<td>No
<td>
<tr>
<td>KURT
<td>NMath.Stats
<td>StatsFunctions.Kurtosis()</p>
<tr>
<td>LARGE
<td>NMath.Stats
<td>StatsFunctions.Sort() with StatsFunctions.Percentile()</p>
<tr>
<td>LEFT
<td>.NET
<td>
<tr>
<td>LEN
<td>.NET
<td>
<tr>
<td>LINEST
<td>NMath.Stats
<td>LeastSquares class</p>
<tr>
<td>LN
<td>NMath.Core
<td>NMathFunctions.Log()</p>
<tr>
<td>LOG
<td>No
<td>
<tr>
<td>LOG10
<td>NMath.Core
<td>NMathFunctions.Log10()</p>
<tr>
<td>LOGEST
<td>NMath.Stats
<td>LinearRegression class in Stats</p>
<tr>
<td>LOGINV
<td>NMath.Stats
<td>InverseCDF method in LognormalDistribution class</p>
<tr>
<td>LOGNORMDIST
<td>NMath.Stats
<td>LognormalDistribution class</p>
<tr>
<td>LOOKUP
<td>NMath.Stats
<td>IndexOf(), IndicesOf() methods in DataFrame class</p>
<tr>
<td>LOWER
<td>.NET
<td>
<tr>
<td>MATCH
<td>No
<td>
<tr>
<td>MAX
<td>NMath.Stats
<td>StatsFunctions.Max()</p>
<tr>
<td>MAXA
<td>No
<td>
<tr>
<td>MDETERM
<td>NMath.Stats
<td>Use LUFact class to factorize then call Determinant() method to compute.</p>
<tr>
<td>MEDIAN
<td>NMath.Stats
<td>StatsFunctions.Median()</p>
<tr>
<td>MID
<td>.NET
<td>
<tr>
<td>MIN
<td>NMath.Stats
<td>StatsFunctions.Min()</p>
<tr>
<td>MINA
<td>No
<td>
<tr>
<td>MINUTE
<td>.NET
<td>
<tr>
<td>MINVERSE
<td>NMath.Stats
<td>Use LUFact class to factorize then call Inverse() method to compute.</p>
<tr>
<td>MIRR
<td>No
<td>
<tr>
<td>MMULT
<td>NMath.Core
<td>Call Multiply() on a matrix class</p>
<tr>
<td>MOD
<td>.NET
<td>
<tr>
<td>MODE
<td>NMath.Stats
<td>StatsFunctions.Mode()</p>
<tr>
<td>MONTH
<td>.NET
<td>
<tr>
<td>N
<td>No
<td>
<tr>
<td>NA
<td>.NET
<td>
<tr>
<td>NEGBINOMDIST
<td>NMath.Stats
<td>NegativeBinomialDistribution class</p>
<tr>
<td>NORMDIST
<td>NMath.Stats
<td>NormalDistribution class</p>
<tr>
<td>NORMINV
<td>NMath.Stats
<td>InverseCDF() in NormalDistribution class</p>
<tr>
<td>NORMSDIST
<td>NMath.Stats
<td>NormalDistribution class </p>
<tr>
<td>NORMSINV
<td>NMath.Stats
<td>InverseCDF() in NormalDistribution class</p>
<tr>
<td>NOT
<td>.NET
<td>
<tr>
<td>NOW
<td>.NET
<td>
<tr>
<td>NPER
<td>No
<td>
<tr>
<td>NPV
<td>No
<td>
<tr>
<td>ODD
<td>.NET
<td>
<tr>
<td>OFFSET
<td>No
<td>
<tr>
<td>OR
<td>.NET
<td>
<tr>
<td>PEARSON
<td>NMath.Stats
<td>StatsFunctions.Correlation()</p>
<tr>
<td>PERCENTILE
<td>NMath.Stats
<td>StatsFunctions.Percentile()</p>
<tr>
<td>PERCENTRANK
<td>NMath.Stats
<td>StatsFunctions.PercentileRank()</p>
<tr>
<td>PERMUT
<td>NMath.Stats
<td>Factorial() in StatsFunctions</p>
<tr>
<td>PI
<td>.NET System.Math.PI
<td>
<tr>
<td>PMT
<td>No
<td>
<tr>
<td>POISSON
<td>NMath.Stats
<td>PoissonDistribution class</p>
<tr>
<td>POWER
<td>NMath.Stats
<td>NMathFunctions.Pow</p>
<tr>
<td>PPMT
<td>No
<td>
<tr>
<td>PROB
<td>NMath.Stats
<td>PDF methods in all of the distribution classes</p>
<tr>
<td>PRODUCT
<td>NMath.Stats
<td>NMathFunctions.Product()</p>
<tr>
<td>PROPER
<td>.NET
<td>
<tr>
<td>PV
<td>No
<td>
<tr>
<td>QUARTILE
<td>NMath.Stats
<td>StatsFunctions.Quartile()</p>
<tr>
<td>RADIANS
<td>.NET
<td>
<tr>
<td>RAND
<td>NMath.Stats
<td>Many RandomNumberGenerator classes in NMath Core</p>
<tr>
<td>RANK
<td>NMath.Stats
<td>StatsFunctions.Rank()</p>
<tr>
<td>RATE
<td>No
<td>
<tr>
<td>REGISTER.ID
<td>No
<td>
<tr>
<td>REPLACE
<td>.NET
<td>
<tr>
<td>REPT
<td>.NET
<td>
<tr>
<td>RIGHT
<td>.NET
<td>
<tr>
<td>ROMAN
<td>No
<td>
<tr>
<td>ROUND
<td>NMath.Core
<td>NMathFunctions.Round()</p>
<tr>
<td>ROUNDDOWN
<td>NMath.Core
<td>NMathFunctions.Round()</p>
<tr>
<td>ROUNDUP
<td>NMath.Core
<td>NMathFunctions.Round()</p>
<tr>
<td>ROW
<td>NMath.Stats
<td>Row property on DataFrame</p>
<tr>
<td>ROWS
<td>NMath.Stats
<td>Rows property on DataFrame</p>
<tr>
<td>RSQ
<td>No
<td>
<tr>
<td>SEARCH
<td>.NET
<td>
<tr>
<td>SECOND
<td>.NET
<td>
<tr>
<td>SIGN
<td>.NET
<td>
<tr>
<td>SIN
<td>NMath.Core
<td>NMathFunctions.Sin()</p>
<tr>
<td>SINH
<td>NMath.Core
<td>NMathFunctions.Sinh()</p>
<tr>
<td>SKEW
<td>NMath.Stats
<td>StatsFunctions.Skewness() for samples or Skewness properties on Distribution classes.</p>
<tr>
<td>SLN
<td>No
<td>
<tr>
<td>SLOPE
<td>NMath.Stats
<td>LinearRegression class in Stats</p>
<tr>
<td>SMALL
<td>NMath.Stats
<td>StatsFunctions.Sort() and then index or find percentage of count and use StatsFunctions.Percentile()</p>
<tr>
<td>SQRT
<td>NMath.Core
<td>NMathFunctions.Sqrt()</p>
<tr>
<td>STANDARDIZE
<td>NMath.Stats
<td>NormalDistribuion class</p>
<tr>
<td>STDEV
<td>NMath.Stats
<td>StatsFunctions.StandardDeviation(BiasType.Unbiased)</p>
<tr>
<td>STDEVA
<td>No
<td>
<tr>
<td>STDEVP
<td>NMath.Stats
<td>StatsFunctions.StandardDeviation()</p>
<tr>
<td>STDEVPA
<td>No
<td>
<tr>
<td>STEYX
<td>NMath.Stats
<td>LinearRegression class in Stats</p>
<tr>
<td>SUBSTITUTE
<td>.NET
<td>
<tr>
<td>SUBTOTAL
<td>NMath.Stats
<td>Use Slice/Subset/Range to get portion of data then StatsFunctions.Sum(), Or, StatsFunctions.SumIf()</p>
<tr>
<td>SUM
<td>NMath.Stats
<td>StatsFunctions.Sum()</p>
<tr>
<td>SUMIF
<td>NMath.Stats
<td>StatsFunctions.SumIf()</p>
<tr>
<td>SUMPRODUCT
<td>NMath.Stats
<td>Use operator* on vectors then NMathFunctions.Sum()</p>
<tr>
<td>SUMSQ
<td>NMath.Stats
<td>StatsFunctions.SumOfSquares()</p>
<tr>
<td>SUMX2MY2
<td>NMath.Core
<td>Square each vector using NMathFunctions.Pow(2) then us operator- for difference then NMathFunctions.Sum()</p>
<tr>
<td>SUMX2PY2
<td>NMath.Core
<td>Square each vector using NMathFunctions.Pow(2) then use operator+ for difference then NMathFunctions.Sum()</p>
<tr>
<td>SUMXMY2
<td>NMath.Stats
<td>use operator- to find difference then Product(2) then NMathFunctions.Sum()</p>
<tr>
<td>SYD
<td>No
<td>
<tr>
<td>T
<td>No
<td>
<tr>
<td>TAN
<td>NMath.Core
<td>NMathFunctions.Tan()</p>
<tr>
<td>TANH
<td>NMath.Core
<td>NMathFunctions.Tanh()</p>
<tr>
<td>TDIST
<td>NMath.Stats
<td>TDistribution class</p>
<tr>
<td>TEXT
<td>No
<td>
<tr>
<td>TIME
<td>.NET
<td>
<tr>
<td>TIMEVALUE
<td>.NET
<td>
<tr>
<td>TINV
<td>NMath.Stats
<td>InverseCDF() in TDistribution class</p>
<tr>
<td>TODAY
<td>.NET
<td>
<tr>
<td>TRANSPOSE
<td>NMath.Core
<td>Transpose() method on a matrix</p>
<tr>
<td>TREND
<td>NMath.Stats
<td>LinearRegression class in Stats</p>
<tr>
<td>TRIM
<td>NMath.Stats
<td>StatsFunctions.Trim()</p>
<tr>
<td>TRIMMEAN
<td>NMath.Stats
<td>StatsFunctions.TrimmedMean()</p>
<tr>
<td>TRUE
<td>.NET
<td>
<tr>
<td>TRUNC
<td>.NET
<td>
<tr>
<td>TTEST
<td>NMath.Stats
<td>TwoSamplePairedTTest or TwoSampleUnpairedTTest classes</p>
<tr>
<td>TYPE
<td>.NET
<td>
<tr>
<td>UPPER
<td>.NET
<td>
<tr>
<td>VALUE
<td>.NET
<td>
<tr>
<td>VAR
<td>NMath.Stats
<td>StatsFunctions.Variance(BiasType.Unbiased)</p>
<tr>
<td>VARA
<td>No
<td>
<tr>
<td>VARP
<td>NMath.Stats
<td>StatsFunctions.Variance()</p>
<tr>
<td>VARPA
<td>No
<td>
<tr>
<td>VDB
<td>No
<td>
<tr>
<td>VLOOKUP
<td>NMath.Stats
<td>Combination of IndexOf() method on DataFrame and index operators</p>
<tr>
<td>WEEKDAY
<td>.NET
<td>
<tr>
<td>WEIBULL
<td>NMath.Stats
<td>WeibullDistribution</p>
<tr>
<td>ZTEST
<td>NMath.Stats
<td>OneSampleZTest</p>
</table>
<p><!--</p>
<p>The following are built into .NET</p>
<p>CALL<br />
CONCATENATE<br />
DATE<br />
DATEVALUE<br />
DAY<br />
DAYS360<br />
DOLLAR<br />
EVEN<br />
EXACT<br />
FALSE<br />
FIND<br />
FIXED<br />
HOUR<br />
HYPERLINK<br />
INFO<br />
INT<br />
LEFT<br />
LEN<br />
LOWER<br />
MID<br />
MINUTE<br />
MOD<br />
MONTH<br />
NA<br />
NOW<br />
ODD<br />
PI<br />
PROPER<br />
RADIANS<br />
REPLACE<br />
REPT<br />
RIGHT<br />
SEARCH<br />
SECOND<br />
SIGN<br />
SUBSTITUTE .NET<br />
TIME<br />
TIMEVALUE<br />
TODAY<br />
TRUE<br />
TRUNC<br />
TYPE<br />
UPPER<br />
VALUE<br />
WEEKDAY<br />
YEAR</p>
<p>These functions are ones we may add to the library. Let us know if you're interested;</p>
<p>AREAS<br />
ASINH<br />
ATANH<br />
AVERAGEA<br />
CELL<br />
CHAR<br />
CHITEST<br />
CHOOSE<br />
CLEAN<br />
CODE<br />
COLUMN<br />
DB<br />
DDB<br />
DEGREES<br />
ERROR.TYPE<br />
FISHER<br />
FISHERINV<br />
FV<br />
GETPIVOTDATA<br />
HLOOKUP<br />
HYPGEOMDIST<br />
INDIRECT<br />
IPMT<br />
IRR<br />
ISERROR<br />
ISLOGICAL<br />
ISNA<br />
ISNONTEXT<br />
ISNUMBER<br />
ISPMT<br />
ISREF<br />
ISTEXT<br />
LOG<br />
MATCH<br />
MAXA<br />
MINA<br />
MIRR<br />
N<br />
NPER<br />
NPV<br />
OFFSET<br />
PMT<br />
PPMT<br />
PV<br />
RATE<br />
REGISTER.ID<br />
ROMAN<br />
RSQ<br />
SLN<br />
STDEVA<br />
STDEVPA<br />
SYD<br />
T<br />
TEXT<br />
VARA<br />
VARPA<br />
VDB</p>
<p>--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/net/using-excel-with-nmath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Large matrices and vectors</title>
		<link>http://www.centerspace.net/blog/nmath/large-matrices-and-vectors/</link>
		<comments>http://www.centerspace.net/blog/nmath/large-matrices-and-vectors/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 18:52:33 +0000</pubDate>
		<dc:creator>Trevor Misfeldt</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[3GB boot switch]]></category>
		<category><![CDATA[Large matrices .NET]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=221</guid>
		<description><![CDATA[Customers frequently ask us how large their matrices can be. NMath matrices (and vectors) are stored internally as an array of floats or doubles. 32-bit .NET processes are limited to 1.2GB of memory. Theoretically a matrix could take up most of that space. Let&#8217;s say it&#8217;s feasible to have a 1 GB matrix. That matrix...]]></description>
			<content:encoded><![CDATA[<p>Customers frequently ask us how large their matrices can be.</p>
<p>NMath matrices (and vectors) are stored internally as an array of floats or doubles.</p>
<p>32-bit .NET processes are limited to 1.2GB of memory. Theoretically a matrix could take up most of that space. Let&#8217;s say it&#8217;s feasible 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 DoubleMatrix or a 16,384 x 16,384 square FloatMatrix.</p>
<p>There&#8217;s a workaround in 32-bit .NET to increase the memory to 2.4GB&#8230;</p>
<p>1. Add the /3GB switch to boot.ini.</p>
<p>2. After building the application, run the<br />
linker as follows:</p>
<p>link -edit -LARGEADDRESSAWARE myapp.exe</p>
<p>where myapp.exe is your application.</p>
<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 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 FloatMatrix.</p>
<p>- Trevor</p>
<p><strong>Update</strong></p>
<p>We have spoken with Microsoft. They are well aware of this issue and are working on a solution. That solution could involve a blob object that could be created of arbitrary size. We have no word on when this will be available.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.centerspace.net%2Fblog%2Fnmath%2Flarge-matrices-and-vectors%2F&amp;title=Large%20matrices%20and%20vectors"><img src="http://www.centerspace.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/large-matrices-and-vectors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Contracts in .NET</title>
		<link>http://www.centerspace.net/blog/net/contracts-in-net/</link>
		<comments>http://www.centerspace.net/blog/net/contracts-in-net/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 16:19:11 +0000</pubDate>
		<dc:creator>Steve Sneller</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.net code contracts]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=138</guid>
		<description><![CDATA[Back in the early 90&#8242;s I went to work for a small, progressive company that was creating and selling C++ class libraries. At this time Object-Oriented programming was still quite new and the developers at the company were a talented group of people who approached programming with a balance of academic rigor and humble pragmatism....]]></description>
			<content:encoded><![CDATA[<p>Back in the early 90&#8242;s I went to work for a small, progressive company that was creating and selling C++ class libraries.  At this time Object-Oriented programming was still quite new and the developers at the company were a talented group of people who approached programming with a balance of academic rigor and humble pragmatism. Selling code other programmers used in their applications meant that the code we sold had to as error free as humanly possible. This meant large, exhaustive tests suites, and copious use of what we called pre-conditions and post-conditions.</p>
<h2>Pre-conditions and Post-conditions</h2>
<p>Frequently, before a function begins executing we require certain conditions to be true for the function to successfully complete. These conditions may be upon the functions arguments, like a reference not being null, or an integer being non-negative or, if the function is a member function on a class, we may require the class instance to be in a particular state. For example, many collection iterators do not reference a collection element when first constructed, you must first call the next method before invoking a dereference method. Doing otherwise will cause an error. In this case the iterators&#8217; dereference method has a <em>pre-condition</em> that the given instance must be actually looking at a valid collection element location.  Similarly, after a function has completed we frequently expect certain <em>post-conditions</em> to be true. If the function computes a return value, we expect it to a valid one. In addition, if the function is a class member function, we may require its invocation to have changed the state of the instance it was invoked upon and a post-condition is a check on the validity of that final state.</p>
<h2>In the Old Days…</h2>
<p>The pre and post condition code we used took the form of C/C++ macros taking a Boolean parameter and were placed at the beginning and end of a functions body. Unless a &#8220;debug&#8221; preprocessor symbol was defined in the compile, the macros expanded to nothing. Thus, not using the condition macros for fear of impacting performance sensitive code with overly obsessive error checking was not a valid excuse. I really liked the idea of pre and post conditions and used them frequently. Sure, invalid input or state will cause an error, hopefully an exception, to occur anyway, so why bother with the extra code? Here are a few reasons:</p>
<ol>
<li>The error that occurs when a pre-condition for a function is not met may be triggered several function calls later, and it may not be obvious that the error occurred from something like invalid input to a function several levels up in the call stack. This is also true for function post-conditions. If, say, invalid input is returned, it may cause an error far removed from the point of infraction. It&#8217;s best to identify these problems as close as possible to the source.</li>
<li>It saves time. Checking for things like valid input arguments is something most programmers do anyway with an if-then-throw statement. Some kind of condition checking code can make this check a one-liner.</li>
<li>It makes code more readable. A function with pre and post conditions makes it explicit to the reader exactly what assumptions are necessary for the function body to execute and what constitutes a successful execution.</li>
</ol>
<p>Pre and post conditions are especially useful for numeric programming. Many mathematical functions have restricted domains, like square root, and log, and linear algebra operations involving matrices and vectors usually require those objects to have consummate dimensions. Many times these errors do not occur immediately upon a function invocation or return, but are removed from those execution points.</p>
<h2>Back to the Future</h2>
<p>As I moved on to work with other companies, I did not encounter any other explicit pre and post condition checking practiced by the programmers. And, I must admit, I didn&#8217;t ever overcome the inertia of having to roll my own, though I did think about doing it more than once. Now the .NET platform has now provided me with pre and post condition checking code!  The project goes by the shorter &#8211; but just as descriptive &#8211; moniker of &#8220;Code Contracts&#8221; and promises to be much more robust than the old  C/C++ macros I had used in the distant past.  I won&#8217;t go into detail about Code Contracts here, because there is lot of information available on line and because we have not yet started using them in our code so I don&#8217;t know a lot about them. However, I look forward to taking .NET Code Contracts for a test drive.</p>
<p><a href="http://research.microsoft.com/en-us/projects/contracts/">http://research.microsoft.com/en-us/projects/contracts/</a></p>
<p>Steve</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.centerspace.net%2Fblog%2Fnet%2Fcontracts-in-net%2F&amp;title=Contracts%20in%20.NET"><img src="http://www.centerspace.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/net/contracts-in-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

