Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@luxbock
Last active December 30, 2015 19:19
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 luxbock/7873465 to your computer and use it in GitHub Desktop.
Save luxbock/7873465 to your computer and use it in GitHub Desktop.
(extend-protocol mp/PExponent
Number
(element-pow [m exponent]
(Math/pow (.doubleValue m) (double exponent)))
Object
(element-pow [m exponent]
(let [x (double exponent)]
(mp/element-map m #(Math/pow (.doubleValue ^Number %) x)))))
(defprotocol PMatrixEquality
"Protocol for numerical array equality operations."
(matrix-equals [a b]
"Return true if a equals b, i.e. if a and b are have the same shape and all elements are equal.
Must use numerical value comparison on numbers (==) to account for matrices that may hold a mix of
numercial types (e.g. java.lang.Long and java.lang.Double). Implementations that only support doubles
should use Number.doubleValue() to get a numeric value to compare.
May throw an exception if the matrices are non-numeric"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment