<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic In this case code looks ok to in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074723#M22495</link>
    <description>&lt;P&gt;In this case code looks ok to me. Do you see similar problems with means or 2nd order raw moments?&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jan 2017 15:51:09 GMT</pubDate>
    <dc:creator>Ilya_B_Intel</dc:creator>
    <dc:date>2017-01-19T15:51:09Z</dc:date>
    <item>
      <title>Computing Variance of Multiple Rows</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074720#M22492</link>
      <description>&lt;P&gt;I'm having trouble figuring out how to compute the variance of multiple rows in a Matrix.&lt;BR /&gt;
	&lt;BR /&gt;
	Suppose I have an M row by N column matrix X for which I need to compute N different variances, one for each row in a row-major (C-style) matrix.&lt;/P&gt;

&lt;P&gt;For a concrete example, suppose my matrix contains time series data containing "periods" observations per day for "days" days. I want to calculate the variance for each day's "periods" observations and have an array "vars" containing "days" variances (one for each day). Below is the code I've attempted to use but it only produces one variance (and the rest, zeroes).&lt;/P&gt;

&lt;PRE style="background-color:#002240;color:#839496;font-family:'Source Code Pro';font-size:15.0pt;"&gt;&lt;SPAN style="color:#808080;font-style:italic;"&gt;/// \brief computes one variance per day given a matrix of daily time series
&lt;/SPAN&gt;&lt;SPAN style="color:#808080;font-style:italic;"&gt;/// \param obsv The matrix containing the time series
&lt;/SPAN&gt;&lt;SPAN style="color:#808080;font-style:italic;"&gt;/// \param days Number of days in the matrix obsv
&lt;/SPAN&gt;&lt;SPAN style="color:#808080;font-style:italic;"&gt;/// \param periods Number of periods per day
&lt;/SPAN&gt;&lt;SPAN style="color:#808080;font-style:italic;"&gt;/// \param vars Output array for daily variances
&lt;/SPAN&gt;&lt;SPAN style="color:#b97300;"&gt;void &lt;/SPAN&gt;&lt;SPAN style="color:#be00c2;"&gt;daily_variances&lt;/SPAN&gt;(&lt;SPAN style="color:#b97300;"&gt;double &lt;/SPAN&gt;*&lt;SPAN style="color:#cccf9b;"&gt;obsv&lt;/SPAN&gt;, &lt;SPAN style="color:#b97300;"&gt;int &lt;/SPAN&gt;&lt;SPAN style="color:#cccf9b;"&gt;days&lt;/SPAN&gt;, &lt;SPAN style="color:#b97300;"&gt;int &lt;/SPAN&gt;&lt;SPAN style="color:#cccf9b;"&gt;periods&lt;/SPAN&gt;, &lt;SPAN style="color:#b97300;"&gt;double &lt;/SPAN&gt;*&lt;SPAN style="color:#cccf9b;"&gt;vars&lt;/SPAN&gt;) {
    &lt;SPAN style="color:#073642;background-color:#ccccff;"&gt;VSLSSTaskPtr&lt;/SPAN&gt;&lt;SPAN style="color:#073642;"&gt; &lt;/SPAN&gt;task;
    &lt;SPAN style="color:#b97300;"&gt;double &lt;/SPAN&gt;*w = &lt;SPAN style="color:#b97300;"&gt;nullptr&lt;/SPAN&gt;; &lt;SPAN style="color:#808080;font-style:italic;"&gt;//weights for VSL routine
&lt;/SPAN&gt;&lt;SPAN style="color:#808080;font-style:italic;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color:#e66262;"&gt;MKL_INT &lt;/SPAN&gt;dim, n, xstorage;
    dim = &lt;SPAN style="color:#cccf9b;"&gt;days&lt;/SPAN&gt;;
    n = &lt;SPAN style="color:#cccf9b;"&gt;periods&lt;/SPAN&gt;;
    xstorage = &lt;SPAN style="color:#e66262;"&gt;VSL_SS_MATRIX_STORAGE_ROWS&lt;/SPAN&gt;; &lt;SPAN style="color:#808080;font-style:italic;"&gt;//we're using C-style row-major matrices
&lt;/SPAN&gt;&lt;SPAN style="color:#808080;font-style:italic;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color:#b97300;"&gt;double &lt;/SPAN&gt;*means = &lt;SPAN style="color:#b97300;"&gt;static_cast&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="color:#b97300;"&gt;double &lt;/SPAN&gt;*&amp;gt;(&lt;SPAN style="color:#e66262;"&gt;mkl_malloc&lt;/SPAN&gt;((&lt;SPAN style="color:#8eb800;"&gt;size_t&lt;/SPAN&gt;) &lt;SPAN style="color:#cccf9b;"&gt;days&lt;/SPAN&gt;, &lt;SPAN style="color:#e66262;"&gt;64&lt;/SPAN&gt;));
    &lt;SPAN style="color:#b97300;"&gt;double &lt;/SPAN&gt;*raw2m = &lt;SPAN style="color:#b97300;"&gt;static_cast&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="color:#b97300;"&gt;double &lt;/SPAN&gt;*&amp;gt;(&lt;SPAN style="color:#e66262;"&gt;mkl_malloc&lt;/SPAN&gt;((&lt;SPAN style="color:#8eb800;"&gt;size_t&lt;/SPAN&gt;) &lt;SPAN style="color:#cccf9b;"&gt;days&lt;/SPAN&gt;, &lt;SPAN style="color:#e66262;"&gt;64&lt;/SPAN&gt;));
    &lt;SPAN style="color:#008080;"&gt;std&lt;/SPAN&gt;::&lt;SPAN style="color:#be00c2;"&gt;fill_n&lt;/SPAN&gt;(means, &lt;SPAN style="color:#cccf9b;"&gt;days&lt;/SPAN&gt;, &lt;SPAN style="color:#e66262;"&gt;0.0&lt;/SPAN&gt;);
    &lt;SPAN style="color:#008080;"&gt;std&lt;/SPAN&gt;::&lt;SPAN style="color:#be00c2;"&gt;fill_n&lt;/SPAN&gt;(raw2m, &lt;SPAN style="color:#cccf9b;"&gt;days&lt;/SPAN&gt;, &lt;SPAN style="color:#e66262;"&gt;0.0&lt;/SPAN&gt;);

    &lt;SPAN style="color:#b97300;"&gt;int &lt;/SPAN&gt;status = &lt;SPAN style="color:#be00c2;"&gt;vsldSSNewTask&lt;/SPAN&gt;(&amp;amp;task, &amp;amp;dim, &amp;amp;n, &amp;amp;xstorage, &lt;SPAN style="color:#cccf9b;"&gt;obsv&lt;/SPAN&gt;, w, &lt;SPAN style="color:#b97300;"&gt;nullptr&lt;/SPAN&gt;);
    &lt;SPAN style="color:#b97300;"&gt;if &lt;/SPAN&gt;(status != &lt;SPAN style="color:#e66262;"&gt;VSL_STATUS_OK&lt;/SPAN&gt;)
        &lt;SPAN style="color:#b97300;"&gt;throw &lt;/SPAN&gt;&lt;SPAN style="color:#008080;"&gt;std&lt;/SPAN&gt;::&lt;SPAN style="color:#be00c2;"&gt;logic_error&lt;/SPAN&gt;(&lt;SPAN style="color:#3b803c;"&gt;"MKL issue"&lt;/SPAN&gt;);
    status = &lt;SPAN style="color:#be00c2;"&gt;vsldSSEditMoments&lt;/SPAN&gt;(task, means, raw2m, &lt;SPAN style="color:#b97300;"&gt;nullptr&lt;/SPAN&gt;, &lt;SPAN style="color:#b97300;"&gt;nullptr&lt;/SPAN&gt;, &lt;SPAN style="color:#cccf9b;"&gt;vars&lt;/SPAN&gt;, &lt;SPAN style="color:#b97300;"&gt;nullptr&lt;/SPAN&gt;, &lt;SPAN style="color:#b97300;"&gt;nullptr&lt;/SPAN&gt;);
    &lt;SPAN style="color:#b97300;"&gt;if &lt;/SPAN&gt;(status != &lt;SPAN style="color:#e66262;"&gt;VSL_STATUS_OK&lt;/SPAN&gt;)
        &lt;SPAN style="color:#b97300;"&gt;throw &lt;/SPAN&gt;&lt;SPAN style="color:#008080;"&gt;std&lt;/SPAN&gt;::&lt;SPAN style="color:#be00c2;"&gt;logic_error&lt;/SPAN&gt;(&lt;SPAN style="color:#3b803c;"&gt;"MKL issue"&lt;/SPAN&gt;);
    status = &lt;SPAN style="color:#be00c2;"&gt;vsldSSCompute&lt;/SPAN&gt;(task, &lt;SPAN style="color:#e66262;"&gt;VSL_SS_2C_MOM&lt;/SPAN&gt;, &lt;SPAN style="color:#e66262;"&gt;VSL_SS_METHOD_1PASS&lt;/SPAN&gt;);
    &lt;SPAN style="color:#b97300;"&gt;if &lt;/SPAN&gt;(status != &lt;SPAN style="color:#e66262;"&gt;VSL_STATUS_OK&lt;/SPAN&gt;)
        &lt;SPAN style="color:#b97300;"&gt;throw &lt;/SPAN&gt;&lt;SPAN style="color:#008080;"&gt;std&lt;/SPAN&gt;::&lt;SPAN style="color:#be00c2;"&gt;logic_error&lt;/SPAN&gt;(&lt;SPAN style="color:#3b803c;"&gt;"MKL issue"&lt;/SPAN&gt;);
    &lt;SPAN style="color:#e66262;"&gt;mkl_free&lt;/SPAN&gt;(means);
    &lt;SPAN style="color:#e66262;"&gt;mkl_free&lt;/SPAN&gt;(raw2m);
    &lt;SPAN style="color:#be00c2;"&gt;vslSSDeleteTask&lt;/SPAN&gt;(&amp;amp;task);
}&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jan 2017 14:51:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074720#M22492</guid>
      <dc:creator>Alfredo_L_</dc:creator>
      <dc:date>2017-01-19T14:51:08Z</dc:date>
    </item>
    <item>
      <title>Hello Alfredo,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074721#M22493</link>
      <description>&lt;P&gt;Hello Alfredo,&lt;/P&gt;

&lt;P&gt;Clarify question.&lt;/P&gt;

&lt;P&gt;Does layout of your data match the following C array?&lt;/P&gt;

&lt;P&gt;double obsv[days][periods];&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 15:30:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074721#M22493</guid>
      <dc:creator>Ilya_B_Intel</dc:creator>
      <dc:date>2017-01-19T15:30:29Z</dc:date>
    </item>
    <item>
      <title>Quote:ILYA B. (Intel) wrote:</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074722#M22494</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;ILYA B. (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Hello Alfredo,&lt;/P&gt;

&lt;P&gt;Clarify question.&lt;/P&gt;

&lt;P&gt;Does layout of your data match the following C array?&lt;/P&gt;

&lt;P&gt;double obsv[days][periods];&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Correct. My matrix is in row-major format and not Fortran-style column-major format. So for instance, to access the n-th period of day "d" I would do obsv&lt;D&gt;&lt;N&gt;.&amp;nbsp;&lt;/N&gt;&lt;/D&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 15:35:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074722#M22494</guid>
      <dc:creator>Alfredo_L_</dc:creator>
      <dc:date>2017-01-19T15:35:24Z</dc:date>
    </item>
    <item>
      <title>In this case code looks ok to</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074723#M22495</link>
      <description>&lt;P&gt;In this case code looks ok to me. Do you see similar problems with means or 2nd order raw moments?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2017 15:51:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074723#M22495</guid>
      <dc:creator>Ilya_B_Intel</dc:creator>
      <dc:date>2017-01-19T15:51:09Z</dc:date>
    </item>
    <item>
      <title>Quote:ILYA B. (Intel) wrote:</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074724#M22496</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;ILYA B. (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;In this case code looks ok to me. Do you see similar problems with means or 2nd order raw moments?&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;So, I was passing the wrong value for "days" as verified by the debugger...&lt;/P&gt;

&lt;P&gt;*however*&lt;/P&gt;

&lt;P&gt;Now that I fixed that, I get the correct result ONLY if using "new" to allocate the mean and raw 2nd moment arrays. If I use mkl_malloc I get a segmentation fault. Any ideas?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 02:37:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074724#M22496</guid>
      <dc:creator>Alfredo_L_</dc:creator>
      <dc:date>2017-01-20T02:37:57Z</dc:date>
    </item>
    <item>
      <title>Do you mean using the code</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074725#M22497</link>
      <description>&lt;PRE style="font-size: 16.26px; color: rgb(96, 96, 96);"&gt;Do you mean using the code like below... You see seg fault when frees buffer for means?

    double *means = static_cast&amp;lt;double *&amp;gt;(mkl_malloc((size_t) days, 64));
    double *raw2m = static_cast&amp;lt;double *&amp;gt;(mkl_malloc((size_t) days, 64));
    .......
    mkl_free(means);
    mkl_free(raw2m);&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 04:45:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074725#M22497</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2017-01-20T04:45:28Z</dc:date>
    </item>
    <item>
      <title>Ah, yes.</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074726#M22498</link>
      <description>&lt;P&gt;Ah, yes.&lt;/P&gt;

&lt;P&gt;mkl_malloc allocates data with size in bytes, thus, correct code will be:&lt;/P&gt;

&lt;PRE style="font-size: 13.008px; color: rgb(96, 96, 96);"&gt;mkl_malloc(sizeof(double)*days, 64)&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2017 07:11:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074726#M22498</guid>
      <dc:creator>Ilya_B_Intel</dc:creator>
      <dc:date>2017-01-20T07:11:38Z</dc:date>
    </item>
    <item>
      <title>Quote:ILYA B. (Intel) wrote:</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074727#M22499</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;ILYA B. (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Ah, yes.&lt;/P&gt;

&lt;P&gt;mkl_malloc allocates data with size in bytes, thus, correct code will be:&lt;/P&gt;

&lt;PRE&gt;mkl_malloc(sizeof(double)*days, 64)&lt;/PRE&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Whoops... I can't believe I forgot that. That was indeed the issue.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2017 18:11:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Computing-Variance-of-Multiple-Rows/m-p/1074727#M22499</guid>
      <dc:creator>Alfredo_L_</dc:creator>
      <dc:date>2017-01-21T18:11:05Z</dc:date>
    </item>
  </channel>
</rss>

