Shimuuar / vecvec

0 stars 1 forks source link

Compare Functionality against hmatrix #13

Open idontgetoutmuch opened 1 year ago

idontgetoutmuch commented 1 year ago

I have this which I hope will give me an environment in which to create an executable document comparing functionality (and also speed)

let
  myHaskellPackageOverlay = self: super: {
    myHaskellPackages = super.haskell.packages.ghc943.override {
      overrides = hself: hsuper: rec {
        vecvec-classes = hself.callCabal2nixWithOptions "vecvec-classes" (builtins.fetchGit {
          url = "https://github.com/Shimuuar/vecvec.git";
          rev = "d20ee2a555ead8062bc117b3c6a5affb17758671";
        }) "--subpath vecvec-classes" { };
        vecvec-hmatrix = hself.callCabal2nixWithOptions "vecvec-hmatrix" (builtins.fetchGit {
          url = "https://github.com/Shimuuar/vecvec.git";
          rev = "d20ee2a555ead8062bc117b3c6a5affb17758671";
        }) "--subpath vecvec-hmatrix" { };
        vecvec-lapack = hself.callCabal2nixWithOptions "vecvec-lapack" (builtins.fetchGit {
          url = "https://github.com/Shimuuar/vecvec.git";
          rev = "d20ee2a555ead8062bc117b3c6a5affb17758671";
        }) "--subpath vecvec-lapack" { };
        vecvec-lapack-ffi = hself.callCabal2nixWithOptions "vecvec-lapack-ffi" (builtins.fetchGit {
          url = "https://github.com/Shimuuar/vecvec.git";
          rev = "d20ee2a555ead8062bc117b3c6a5affb17758671";
        }) "--subpath vecvec-lapack-ffi" { lapacke = super.lapack; };
        vecvec-lorentz = super.haskell.lib.dontCheck (hself.callCabal2nixWithOptions "vecvec-lorentz" (builtins.fetchGit {
          url = "https://github.com/Shimuuar/vecvec.git";
          rev = "d20ee2a555ead8062bc117b3c6a5affb17758671";
        }) "--subpath vecvec-lorentz" { });
        vector = super.haskell.lib.dontCheck (hself.callHackage "vector" "0.13.0.0" {});
        doctest = hself.callCabal2nixWithOptions "doctest" (builtins.fetchGit {
          url = "https://github.com/sol/doctest.git";
          rev = "95db1e1c01becd5b784624e466774863b605b7e3";
        }) "" { };
      };
    };
  };

  pkgs   = import <nixpkgs> { inherit config overlays; };
  config = {};
  overlays = [ myHaskellPackageOverlay ];

  pkgs_hask = pkgs.myHaskellPackages.ghcWithPackages (p: with p; [
    hmatrix
    vector
    fixed-vector
    vecvec-classes
    vecvec-hmatrix
    vecvec-lapack
    vecvec-lapack-ffi
    vecvec-lorentz
  ]);
in
pkgs.mkShell {
  buildInputs = with pkgs; [
    openblasCompat
    lapack
    pkgs_hask
  ];
  shellHook = ''
    export LD_LIBRARY_PATH=${pkgs.openblasCompat}/lib''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
    '';
}
Shimuuar commented 1 year ago

Yeah. It works for me. Although you may want to factor out builtins.fetchGit {...} and add pkgs.haskell.lib.dontCheck. vecvec pull in quite a bit of testing dependencies. It's one time expense though.

Benchmarks would be marvelous! It's sort of thing that one should have but I usually too lazy to write. I except that they should behave same for large matrices. They use same libraries after all. Small size may demonstrate difference in overhead on haskell side. Also Vec should be slightly slower that plain storable vectors since it has stride which adds cost to operations.