<p>I give set_size solution a try, it work.</p>

<pre><code>void Impute(const arma::Mat&lt;T&gt;&amp; input,
              arma::Mat&lt;T&gt;&amp; output,
              const T&amp; mappedValue,
              const size_t dimension,
              const bool columnMajor = true)
  {    
    output.set_size(input.n_rows, input.n_cols);
    Impute(output, mappedValue, dimension, columnMajor);
  }
</code></pre>

<p>Impute like this</p>

<pre><code>CustomImputation&lt;double&gt; customStrategy(99); // convert missing vals to 99.
  Imputer&lt;double,
          DatasetMapper&lt;MissingPolicy&gt;,
          CustomImputation&lt;double&gt;&gt; imputer(info, customStrategy);
  output = input;
  imputer.Impute(input, output, "a", 0); // convert a -&gt; 99 for dimension 0
</code></pre>

<p>This should avoid the redundant copy. Maybe we could remove the api with output? Keep the api with one input? I could handle this part after merged.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/pull/694#issuecomment-234279295">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJ4bFHAC_HJMZoIlDhpZJCFoaOthTDbSks5qX4gzgaJpZM4I07W-">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFEL4zfSvmOSX_-MaP3przg68uYfiks5qX4gzgaJpZM4I07W-.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/694#issuecomment-234279295"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>