<p dir="auto">The current implementation of <code class="notranslate">Matrix</code> on a CholeskyPivoted object returns the wrong result if the factorization is of low rank.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="A = randn(3,1)
B = A*A'
C = cholesky(B, Val(true), tol = 1e-8, check=false)"><pre class="notranslate">A <span class="pl-k">=</span> <span class="pl-c1">randn</span>(<span class="pl-c1">3</span>,<span class="pl-c1">1</span>)
B <span class="pl-k">=</span> A<span class="pl-k">*</span>A<span class="pl-k">'</span>
C <span class="pl-k">=</span> <span class="pl-c1">cholesky</span>(B, <span class="pl-c1">Val</span>(<span class="pl-c1">true</span>), tol <span class="pl-k">=</span> <span class="pl-c1">1e-8</span>, check<span class="pl-k">=</span><span class="pl-c1">false</span>)</pre></div>
<p dir="auto">Then B != Matrix(C).</p>
<p dir="auto">If we instead defined</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function Matrix(C::CholeskyPivoted)
    ip = invperm(C.p)
    U = C.U[1:C.rank, ip]
    U'U
end"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">Matrix</span>(C<span class="pl-k">::</span><span class="pl-c1">CholeskyPivoted</span>)
    ip <span class="pl-k">=</span> <span class="pl-c1">invperm</span>(C<span class="pl-k">.</span>p)
    U <span class="pl-k">=</span> C<span class="pl-k">.</span>U[<span class="pl-c1">1</span><span class="pl-k">:</span>C<span class="pl-k">.</span>rank, ip]
    U<span class="pl-k">'</span>U
<span class="pl-k">end</span></pre></div>
<p dir="auto">We would get the correct result. Other functions, like <code class="notranslate">det</code> already implement the correct behavior in this case, by using the <code class="notranslate">rank</code> field. Therefore, I think this change would make the behavior consistent for low rank factorizations.</p>
<p dir="auto">I am trying to call gmtime from &lt;time.h&gt;.<br>
The expected return struct can be modelled according to the following type:<br>
<code class="notranslate">type Date sec::Int min::Int hour::Int mday::Int mon::Int year::Int wday::Int yday::Int isdst::Int end</code></p>
<p dir="auto">Calling  <code class="notranslate">ccall(:gmtime, Ptr{Date}, (Ptr{Int32},), &amp;t)</code> returns a pointer of the right type. But I have found no way to convert the pointer back to the original type.</p>
<p dir="auto">base/pointer.jl has a function for converting objects to pointers, but not the other way around. This is essential for interacting with c-code, though.</p>