Skip to content

Commit 7eeaa0f

Browse files
author
Mahdi Dibaiee
committed
initial commit, hmatrix
0 parents  commit 7eeaa0f

File tree

11 files changed

+1588
-0
lines changed

11 files changed

+1588
-0
lines changed

Diff for: .gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#### joe made this: http://goel.io/joe
2+
#### haskell ####
3+
dist
4+
dist-*
5+
cabal-dev
6+
*.o
7+
*.hi
8+
*.chi
9+
*.chs.h
10+
*.dyn_o
11+
*.dyn_hi
12+
.hpc
13+
.hsenv
14+
.cabal-sandbox/
15+
cabal.sandbox.config
16+
*.prof
17+
*.aux
18+
*.hp
19+
*.eventlog
20+
.stack-work/
21+
cabal.project.local
22+
.HTF/
23+

Diff for: LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright Author name here (c) 2016
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Author name here nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
numeric-libs-overview
2+
=====================
3+
4+
An overview of different Haskell numeric libraries. This is intended to be a place to compare different numeric libraries
5+
by their ease of use, performance and more.
6+
7+
_Pull requests are welcome if you want to add a library!_
8+
9+
These overviews include:
10+
* Benchmarks
11+
* Example code
12+
* Links to hackage, github and the homepage if available
13+
14+
Libraries
15+
=========
16+
17+
hmatrix
18+
-------
19+
hmatrix is a linear algebra library and matrix computations.
20+
21+
**Example code**:
22+
```haskell
23+
24+
-- Creating matrices
25+
let x = (2><2) [0..3] :: Matrix Double
26+
27+
x -- [ 0.0, 1.0
28+
-- , 2.0, 3.0 ]
29+
30+
let y = fromLists [[0, 1], [2, 3]] :: Matrix Double
31+
32+
-- Random matrices
33+
34+
r <- randn 2 3
35+
r -- [ 0.7764496757867578, 1.246311658930589, -0.684233085372455
36+
-- , -2.540045307941425, -0.20975584071908912, -9.039537343065803e-3 ]
37+
38+
-- Matrix multiplication
39+
40+
x <> y -- [ 2.0, 3.0
41+
-- , 6.0, 11.0 ]
42+
43+
-- Transpose
44+
45+
tr x -- [ 0.0, 2.0
46+
-- , 1.0, 3.0 ]
47+
48+
-- Matrix slicing
49+
r ?? (All, Take 2) -- [ 0.7764496757867578, 1.246311658930589
50+
-- , -2.540045307941425, -0.20975584071908912 ]
51+
52+
-- SVD
53+
54+
(u, s, v) = svd r
55+
56+
-- Mapping over matrices
57+
58+
cmap ((+ 2) . (*2)) x -- [ 2.0, 4.0
59+
-- , 6.0, 8.0 ]
60+
61+
-- Flatten
62+
63+
flatten x -- [0.0, 1.0, 2.0, 3.0]
64+
```
65+
66+
[**Benchmarks**]()
67+
68+
**Links**: [Hackage](http://hackage.haskell.org/package/hmatrix) [GitHub](https://github.com/albertoruiz/hmatrix) . [Homepage](http://dis.um.es/~alberto/hmatrix/hmatrix.html)
69+
70+
Contribution
71+
============
72+
* Benchmarks are written using [criterion](http://hackage.haskell.org/package/criterion)
73+
* Please try to write an example code that matches format of the others and presets the same set of functionalities if available

Diff for: Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

Diff for: app/Main.hs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Lib
4+
5+
main :: IO ()
6+
main = someFunc

Diff for: app/hmatrix.hs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Criterion.Main
2+
import Numeric.LinearAlgebra
3+
4+
n = 10 :: Int
5+
main = defaultMain [
6+
bench "matrix creation" $ w (\_ -> fromLists sampleList :: Matrix Double),
7+
bench "random matrix generation" $ whnfIO (randn n n),
8+
bench "matrix multiplication" $ w (\_ -> sampleDiag <> sampleDiag),
9+
bench "matrix slicing" $ whnf (\n -> sampleDiag ?? (Take (n - 1), Take (n - 1))) n,
10+
11+
bench "scalar multiplication" $ whnf (\n -> sampleDiag * (fromIntegral n)) n,
12+
13+
bench "matrix-vector addition" $ w (\_ -> sampleDiag + sampleDiag),
14+
15+
bench "transpose" $ w (\_ -> tr sampleDiag),
16+
17+
bench "eigenvalues" $ w (\_ -> eigenvalues sampleDiag),
18+
bench "singularValues" $ w (\_ -> singularValues sampleDiag),
19+
20+
bench "svd" $ w (\_ -> svd sampleDiag),
21+
bench "thin svd" $ w (\_ -> thinSVD sampleDiag),
22+
23+
bench "nullspace" $ w (\_ -> nullspace sampleDiag),
24+
bench "orthogonal" $ w (\_ -> orth sampleDiag),
25+
26+
bench "determinant" $ w (\_ -> det sampleDiag)
27+
]
28+
where
29+
w f = f `whnf` 0
30+
sampleList = replicate n $ replicate n 1
31+
sampleDiag = diagl [1..fromIntegral n]

Diff for: benchmarks/hmatrix.html

+1,306
Large diffs are not rendered by default.

Diff for: numeric-libs-overview.cabal

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: numeric-libs-overview
2+
version: 0.1.0.0
3+
synopsis: benchmark/review numeric libraries
4+
description: Benchmark and review of different numeric libraries of Haskell
5+
homepage: https://github.com/mdibaiee/numeric-libs-overview#readme
6+
license: GPL-3
7+
license-file: LICENSE
8+
author: Mahdi Dibaiee
9+
maintainer: [email protected]
10+
copyright: 2016 Mahdi Dibaiee
11+
category: Benchmark, Data Science, Numeric
12+
build-type: Simple
13+
-- extra-source-files:
14+
cabal-version: >=1.10
15+
16+
library
17+
hs-source-dirs: src
18+
exposed-modules: Lib
19+
build-depends: base >= 4.7 && < 5
20+
default-language: Haskell2010
21+
22+
executable hmatrix
23+
hs-source-dirs: app
24+
main-is: hmatrix.hs
25+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
26+
build-depends: base
27+
, numeric-libs-overview
28+
, hmatrix
29+
, criterion
30+
default-language: Haskell2010
31+
32+
test-suite numeric-libs-overview-test
33+
type: exitcode-stdio-1.0
34+
hs-source-dirs: test
35+
main-is: Spec.hs
36+
build-depends: base
37+
, numeric-libs-overview
38+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
39+
default-language: Haskell2010
40+
41+
source-repository head
42+
type: git
43+
location: https://github.com/mdibaiee/numeric-libs-overview

Diff for: src/Lib.hs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Lib
2+
( someFunc
3+
) where
4+
5+
someFunc :: IO ()
6+
someFunc = putStrLn "someFunc"

Diff for: stack.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file was automatically generated by 'stack init'
2+
#
3+
# Some commonly used options have been documented as comments in this file.
4+
# For advanced use and comprehensive documentation of the format, please see:
5+
# http://docs.haskellstack.org/en/stable/yaml_configuration/
6+
7+
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8+
# A snapshot resolver dictates the compiler version and the set of packages
9+
# to be used for project dependencies. For example:
10+
#
11+
# resolver: lts-3.5
12+
# resolver: nightly-2015-09-21
13+
# resolver: ghc-7.10.2
14+
# resolver: ghcjs-0.1.0_ghc-7.10.2
15+
# resolver:
16+
# name: custom-snapshot
17+
# location: "./custom-snapshot.yaml"
18+
resolver: lts-7.2
19+
20+
# User packages to be built.
21+
# Various formats can be used as shown in the example below.
22+
#
23+
# packages:
24+
# - some-directory
25+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
26+
# - location:
27+
# git: https://github.com/commercialhaskell/stack.git
28+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
29+
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
30+
# extra-dep: true
31+
# subdirs:
32+
# - auto-update
33+
# - wai
34+
#
35+
# A package marked 'extra-dep: true' will only be built if demanded by a
36+
# non-dependency (i.e. a user package), and its test suites and benchmarks
37+
# will not be run. This is useful for tweaking upstream packages.
38+
packages:
39+
- '.'
40+
# Dependency packages to be pulled from upstream that are not in the resolver
41+
# (e.g., acme-missiles-0.3)
42+
extra-deps: []
43+
44+
# Override default flag values for local packages and extra-deps
45+
flags: {}
46+
47+
# Extra package databases containing global packages
48+
extra-package-dbs: []
49+
50+
# Control whether we use the GHC we find on the path
51+
# system-ghc: true
52+
#
53+
# Require a specific version of stack, using version ranges
54+
# require-stack-version: -any # Default
55+
# require-stack-version: ">=1.1"
56+
#
57+
# Override the architecture used by stack, especially useful on Windows
58+
# arch: i386
59+
# arch: x86_64
60+
#
61+
# Extra directories used by stack for building
62+
# extra-include-dirs: [/path/to/dir]
63+
# extra-lib-dirs: [/path/to/dir]
64+
#
65+
# Allow a newer minor version of GHC than the snapshot specifies
66+
# compiler-check: newer-minor

Diff for: test/Spec.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main :: IO ()
2+
main = putStrLn "Test suite not yet implemented"

0 commit comments

Comments
 (0)