Created
February 1, 2011 15:38
-
-
Save sritchie/806027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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