Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two different types of array to consider:</p> <ul> <li><code>[D</code> is a <strong>primitive</strong> double array, equivalent to Java <code>double[]</code></li> <li><code>[Ljava.lang.Double;</code> is an array of <code>Double</code> <strong>references</strong>, equivalent to Java <code>Double[]</code>.</li> </ul> <p>(the odd notation is because this is the internal representation of these types in Java bytecode... it's a bit odd that this gets exposed in Clojure but you just have to live with it)</p> <p>Because these are different types, they are treated differently with Clojure protocols.</p> <p>The primitive double arrays usually offer better performance, assuming you stick to primitive double operations and avoid any unnecessary boxing. You can think of the primitive arrays as an array of unboxed values, and the reference arrays as an array of boxed values.</p> <p>The main reason to use the reference arrays are if your values are already boxed when you receive them, and/or if you plan to pass them to other functions or collections that require boxed values. In this case, it is inefficient to unbox the doubles and then box them again, so it can be sensible to leave them in boxed form.</p> <p>FWIW, there are several libraries that make it easy to do things with double arrays. In particular you should check out <a href="https://github.com/prismatic/hiphip" rel="noreferrer">HipHip</a> (specialised array operations), <a href="https://github.com/mikera/core.matrix" rel="noreferrer">core.matrix</a> (supports vector/matrix operations on many types including double arrays) and <a href="https://github.com/mikera/vectorz-clj" rel="noreferrer">vectorz-clj</a> (works with core.matrix, wraps double arrays as general purpose vectors)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload