Created
March 16, 2012 08:21
-
-
Save Dubhead/2049097 to your computer and use it in GitHub Desktop.
matrix product in Pure
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
% pure -i | |
Pure 0.52 (x86_64-unknown-linux-gnu) Copyright (c) 2008-2012 by Albert Graef | |
(Type 'help' for help, 'help copying' for license information.) | |
Loaded prelude from /usr/local/lib/pure/prelude.pure. | |
> sum = foldl (+) 0; | |
> dot x::matrix y::matrix = sum $ zipwith (*) (rowvector x) (rowvector y); | |
> x::matrix * y::matrix = {dot u v | u = rows x; v = cols y}; | |
> a = {1, 2, 3; 1, 2, 3; 1, 2, 3}; | |
> b = {1, 2, 3, 4; 1, 2, 3, 4; 1, 2, 3, 4}; | |
> a * b; | |
{6,12,18,24;6,12,18,24;6,12,18,24} | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment