Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created February 1, 2011 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/806027 to your computer and use it in GitHub Desktop.
Save sritchie/806027 to your computer and use it in GitHub Desktop.
(def
#^{:doc "Type object for a Java primitive float array."}
*float-array-type* (class (make-array Float/TYPE 0)))
(defmulti
#^{:doc "Converts argument into a Java float array. Argument may be
a File, or another byte array. If the argument is already
a float array, returns it."
:arglists '([arg])}
to-float-array type)
(defmethod to-float-array *float-array-type* [x] x)
(defmethod to-float-array String [^String str]
(to-float-array (io/as-file str)))
(defmethod to-float-array File [^File f]
(to-float-array (io/to-byte-array f)))
(defmethod to-float-array io/*byte-array-type* [^bytes b]
(-> b
java.nio.ByteBuffer/wrap
(.order java.nio.ByteOrder/LITTLE_ENDIAN)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment