Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn abstractOperation [operation]
  2.   (fn [a b] (mapv operation a b)))
  3.  
  4. (defn modifyLines [op neural m] (mapv (fn [curLine] (op curLine neural)) m))
  5.  
  6. ;; Vector operations
  7. (def v+ (abstractOperation +))
  8. (def v- (abstractOperation -))
  9. (def v* (abstractOperation *))
  10. (defn v*s [v s] (mapv (fn [xi] (* xi s)) v))
  11. (defn scalar [a b] (reduce + (v* a b)))
  12.  
  13. ;; Matrix operations
  14. (def m- (abstractOperation v-))
  15. (def m* (abstractOperation v*))
  16. (def m+ (abstractOperation v+))
  17. (defn m*s [m s] (modifyLines v*s s m))
  18. (defn m*v [m v] (modifyLines scalar v m))
  19. (defn transpose [m]
  20.   (apply mapv vector m))
  21.  
  22. (print (scalar [1 2 3] [4 5 6]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement