Re: [Haskell-cafe] Acquiring a random set of a specific size (w/o dups) from a range of Ints

2011-06-14 Thread Patrick Perry
There are time/space tradeoffs in sampling without replacement. The version in monte-carlo takes space O(n) and time O(k), for all k. I chose this algorithm instead of a streaming algorithm, with takes space O(k) and time O(n). If k is much less than n, you can improve a bit. Here is a

Re: [Haskell-cafe] Acquiring a random set of a specific size (w/o dups) from a range of Ints

2011-06-14 Thread Patrick Perry
Correction: the version in monte-carlo takes time O(n), but it only consumes k random numbers. The streaming algorithm consumes n random numbers. On Jun 14, 2011, at 12:04 PM, Patrick Perry wrote: There are time/space tradeoffs in sampling without replacement. The version in monte-carlo

[Haskell-cafe] ANN: ieee754 version 0.7.1

2010-09-20 Thread Patrick Perry
Upon popular request, I've renamed the ieee package to ieee754. The new hackage page is http://hackage.haskell.org/package/ieee754 . On Sep 19, 2010, at 11:16 PM, Conrad Parker wrote: On 20 September 2010 11:18, Patrick Perry patpe...@gmail.com wrote: Given that IEEE is actually

[Haskell-cafe] ANN: ieee version 0.7

2010-09-19 Thread Patrick Perry
ieee is a Haskell library for dealing with IEEE floating numbers. It was originally written to make testing with floating point values less painful. The library provides an approximate equality type class, AEq, with approximate equality operator ~==. One property of ~== is that nearby floating

Re: [Haskell-cafe] ANN: ieee version 0.7

2010-09-19 Thread Patrick Perry
Given that IEEE is actually a standards body and they have many standards, wouldn't it be more appropriate to call this library ieee754? If it seems important to people, I'd be happy to change the name. I'm not religious about these things. Will it clutter up hackage, though? Patrick

Re: [Haskell-cafe] ANN: ieee version 0.7

2010-09-19 Thread Patrick Perry
con...@metadecks.org wrote: On 20 September 2010 11:18, Patrick Perry patpe...@gmail.com wrote: Given that IEEE is actually a standards body and they have many standards, wouldn't it be more appropriate to call this library ieee754? If it seems important to people, I'd be happy to change

Re: [Haskell-cafe] ANN: ieee version 0.7

2010-09-19 Thread Patrick Perry
I needed real IEEE754 binary support for round-trip parsing, where (for example) maintaining the particular bit pattern of a NaN is important. For 99% of people, the unsafe method will work fine. How does a C-style cast not preserve the bit pattern of a NaN? Again, sorry if this is a stupid

[Haskell-cafe] ANN: monte-carlo version 0.3

2010-09-16 Thread Patrick Perry
monte-carlo is a haskell library providing a monad and associated monad transformer for computing with quasi-random numbers. It provides a high-level interface to the distributions supported by the GNU Scientific Library (currently just uniform, normal, exponential, Poisson, Levy, but others

[Haskell-cafe] QuickCheck2 question

2009-10-12 Thread Patrick Perry
I'm having some trouble with QuickCheck2 and Control.Applicative. Specifically, I have the following functions (slightly simplified): copyVector :: IOVector - Vector - IO () freezeVector :: IOVector - IO (Vector) I have a test, part of which looks like monadicIO $ do run $

[Haskell-cafe] fast Eucl. dist. - Haskell vs C

2009-05-19 Thread Patrick Perry
Hi Kenneth, I wrote a benchmark similar to yours using the haskell blas library I wrote (latest version is on github at http://github.com/patperry/blas/tree/master , an older version is on hackage). The pure Haskell implementation is not very good, and the problem seems to be repeated

[Haskell-cafe] Re: Matrices

2009-04-19 Thread Patrick Perry
Hi Cetin, This is probably the easiest way: (m - es)^2/es listMatrix (2,2) [0.6163270413689804,0.600918865334756,0.33217626255600896,0.3238718559921087 ] This will create 2 temporary arrays. Alternatively, let res = listMatrix (shape m) [ (o-e)^2 / e | o - colElems m | e - colElems

Re: [Haskell-cafe] hmatrix, Windows and GCC

2009-01-28 Thread Patrick Perry
Well, I guess I am not the only one! This blog show exactly what I am looking for! http://quantile95.com/2008/10/31/ann-blas-bindings-for-haskell-version-06/ If you're looking to implement other linear algebra algorithms in Haskell, there's enough at http://github.com/patperry/lapack

[Haskell-cafe] Question about allocaArray and friends

2009-01-22 Thread Patrick Perry
In C, if you try to alloca too much memory, then the stack gets overwritten and bad things happen. Does GHC exhibit the same behavior with allocaArray and the like? Is there a way to find out how much is safe to allocate? Thanks in advance for the help, Patrick

[Haskell-cafe] ANN: monad-interleave 0.1

2009-01-15 Thread Patrick Perry
My two favorite functions in Haskell are unsafeInterleaveIO and unsafeInterleaveST. I'm surprised there isn't a type class for them. I just fixed this by adding the monad-interleave package to hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/monad-interleave The

Re: [Haskell-cafe] Question about touchForeignPtr

2009-01-12 Thread Patrick Perry
Thanks for your help, Duncan. On Jan 12, 2009, at 6:10 AM, Duncan Coutts wrote: Do the (ForeignPtr e) and the (Ptr e) point to the same thing? They appear to be related because you dereference p but touch f. It used to be the ForeignPtr was slower to dereference than a Ptr and so caching

[Haskell-cafe] Question about touchForeignPtr

2009-01-11 Thread Patrick Perry
I have the following code: IOVector n e = IOVector !ConjEnum !Int (ForeignPtr e)! (Ptr e)! Int! newtype Vector n e = IOVector n e unsafeAtVector :: Vector n e - Int - e unsafeAtVector (Vector (IOVector c _ f p inc)) i = let g = if c == Conj then conjugate else id in inlinePerformIO $

[Haskell-cafe] ANN: Haskell BLAS bindings version 0.7

2009-01-10 Thread Patrick Perry
New version! The blas package is a set of bindings to the BLAS (Basic Linear Algebra Subprograms) library. On Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/blas-0.7 What's new: * Get rid of most functional dependencies in favor of type families. There is one

[Haskell-cafe] ANN: Haskell BLAS bindings version 0.7

2009-01-10 Thread Patrick Perry
Here's the haddock documentation; I'm not sure if Hackage honors {-# OPTIONS_HADDOCK hide #-} when it displays the exposed modules: http://quantile95.com/blas/ Patrick ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] ANN: Haskell BLAS bindings version 0.7

2009-01-10 Thread Patrick Perry
Hi David, The problem is with Hackage, not with haddock. Patrick On Jan 10, 2009, at 3:38 AM, David Waern wrote: 2009/1/10 Patrick Perry patpe...@stanford.edu: Here's the haddock documentation; I'm not sure if Hackage honors {-# OPTIONS_HADDOCK hide #-} when it displays the exposed modules

Re: [Haskell-cafe] ANN: Haskell BLAS bindings version 0.7

2009-01-10 Thread Patrick Perry
The reason I want to expose modules but hide the documentation is because there are a lot of unsafeX functions I want to provide access to, but which 99% of users don't care about. The array library does the same thing. Patrick ___

Re: [Haskell-cafe] ANN: Haskell BLAS bindings version 0.7

2009-01-10 Thread Patrick Perry
(for whom you are providing access) will still have a possibility to do so. 2009/1/10 Patrick Perry patpe...@stanford.edu: The reason I want to expose modules but hide the documentation is because there are a lot of unsafeX functions I want to provide access to, but which 99% of users don't care

[Haskell-cafe] ANN: monte-carlo-0.2, gsl-random-0.2.3

2008-12-31 Thread Patrick Perry
I've released a new version of the monte-carlo packages for haskell. Here are the highlights for monte-carlo: Changes in 0.2: * More general type class, MonadMC, which allows all the functions to work in both MC and MCT monads. * Functions to sample from discrete distributions. *

[Haskell-cafe] How to think about this? (profiling)

2008-12-16 Thread Patrick Perry
I agree with everyone else who has said that the better solution is Lemmih's. It is simple, fast, and does not use much memory. On the other hand, here is a more faithful implementation of what you were trying to write. To use mutable arrays, you need to work in either the IO or the ST

[Haskell-cafe] unsafeThawByteArray#

2008-12-11 Thread Patrick Perry
I've noticed that there is no longer an unsafeThawByteArray# function in GHC.Prim. Looking through the darcs history, I found a patch with description: [project @ 2000-03-13 12:11:43 by simonmar] simonmar**2313121144 Remove unsafeThawByteArray# primop (which was a no-op), and use

[Haskell-cafe] ANN: permutation-0.2

2008-12-07 Thread Patrick Perry
Hi Everyone, I've uploaded a new version of the permutation library to hackage. Here is the package description: This library includes data types for storing permutations. It implements pure and impure types, the latter which can be modified in-place. The main utility of the

[Haskell-cafe] Re: Statically dimension-checked hmatrix

2008-11-18 Thread Patrick Perry
What is the situation regarding statically dimension-checked linear algebra libraries? It seems that Frederik Eaton was working on one in 2006 (see the paper Statically typed linear algebra in Haskell), and he produced the Vectro library from this, based on GSLHaskell. Are there any more

[Haskell-cafe] ANN: blas version 0.6

2008-11-01 Thread Patrick Perry
New version of BLAS bindings out. Now with support for the ST monad! This breaks backwards compatibility, unfortunately. More info (and some sample code) here: http://quantile95.com/2008/10/31/ann-blas-bindings-for-haskell-version-06/ Also, if you want to help, please let me know. There

[Haskell-cafe] ANN: gsl-random 0.1 and monte-carlo-0.1

2008-08-28 Thread Patrick Perry
Hi everyone, I've started on bindings for the random number generators and random distributions provided by the gsl. The package is available here: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/gsl-random I've also written a monad and transformer for doing monte carlo

Re: [Haskell-cafe] ANN: gsl-random 0.1 and monte-carlo-0.1

2008-08-28 Thread Patrick Perry
Thanks for the heads up, Don. I fixed the file in version 0.1.1. I also changed the default CBLAS to the one that comes with the GSL. Anyone who cares at all about performance will want to configure the package to use the best CBLAS on their system. If this is ATLAS, make sure you pass

Re: [Haskell-cafe] Bug with QuickCheck 1.1 and GHC 6.8.2

2008-08-14 Thread Patrick Perry
' _ - rands r2 n' Patrick On Aug 14, 2008, at 2:17 AM, Johan Tibell wrote: On Thu, Aug 14, 2008 at 1:58 AM, Patrick Perry [EMAIL PROTECTED] wrote: variant :: Int - Gen a - Gen a variant v (Gen m) = Gen (\n r - m n (rands r !! v')) where v' = abs (v+1) `mod` 1 rands r0 = r1

Re: [Haskell-cafe] Bug with QuickCheck 1.1 and GHC 6.8.2

2008-08-14 Thread Patrick Perry
in r4' Patrick On Aug 14, 2008, at 4:57 AM, Johan Tibell wrote: On Thu, Aug 14, 2008 at 12:15 PM, Patrick Perry [EMAIL PROTECTED] wrote: Actually, a much better solution is: variant :: Int - Gen a - Gen a variant v (Gen m) = Gen (\n r - m n (rands r v)) where rands r0 0 = r0

[Haskell-cafe] Bug with QuickCheck 1.1 and GHC 6.8.2

2008-08-13 Thread Patrick Perry
I'm running into problems with generating an arbitrary function of type Double - Double. Specifically, the following code: {-# LANGUAGE PatternSignatures #-} import Test.QuickCheck import Text.Show.Functions prop_ok (f :: Double - Double) = f (-5.5) `seq` True prop_bug (f :: Double -

Re: [Haskell-cafe] Bug with QuickCheck 1.1 and GHC 6.8.2

2008-08-13 Thread Patrick Perry
The bug is in the variant function in QuickCheck. I replaced variant :: Int - Gen a - Gen a variant v (Gen m) = Gen (\n r - m n (rands r !! (v+1)) where rands r0 = r1 : rands r2 where (r1, r2) = split r0 with variant :: Int - Gen a - Gen a variant v (Gen m) = Gen (\n r - m n (rands r !!

[Haskell-cafe] ANN: BLAS bindings for haskell, version 0.5

2008-08-11 Thread Patrick Perry
Hey everyone, I've put together a new release of the Haskell BLAS bindings, now available on hackage. Here are the new features: * Add Banded matrix data type, as well as Tri Banded and Herm Banded. * Add support for trapezoidal dense matrices (Tri Matrix (m,n) e, where m is not the same

[Haskell-cafe] Re: blas bindings, why are they so much slower the C?

2008-07-24 Thread Patrick Perry
Last month Anatoly Yakovenko published some disturbing numbers about the Haskell BLAS bindings I wrote being significantly slower than using plain C. I wanted to let everyone know that I've closed the performance gap, and now for doing ten million dot products, the overhead for using

Re: [Haskell-cafe] Re: blas bindings, why are they so much slower the C?

2008-07-24 Thread Patrick Perry
Yeah, I think that's where most of the performance gains came from. I also added a re-write rule for unsafeGet dot (since it doesn't matter if the arguments are conjugated or not if the vectors are real) that shaved off about a tenth of a second. Patrick On Jul 24, 2008, at 4:26 PM,

Re: [Haskell-cafe] BLAS Solve Example

2008-07-22 Thread Patrick Perry
Sorry Darrin, the BLAS library only includes matrix multiplication and solving triangular systems. To solve a general system, you would need to use LAPACK, but there aren't any bindings for that library yet. I would suggest you take a look at the hmatrix package, which includes a lot

[Haskell-cafe] ANN: blas-0.4.1

2008-06-11 Thread Patrick Perry
There were a few hiccups in the release of 0.4, so this version is to make installation go a little smoother for people. There are now installation instructions (the INSTALL file) and configuration settings for some common CBLAS (ATLAS, MKL, vecLib, GSL). The default is now to assume

[Haskell-cafe] ANN: ieee-0.2

2008-06-11 Thread Patrick Perry
ieee is a library that provides approximate comparison of floating point numbers based, NaN-aware minimum and maximum, and a type class for approximate comparisons. This version fixes a bug in the comparison implementation for Maybe.

[Haskell-cafe] Re: Patrick Perry's BLAS package

2008-06-06 Thread Patrick Perry
Wow, thanks for noticing, Alberto! For anyone interested, I put up a formal announcement describing the bindings a little bit here: http://quantile95.com/ I just registered the domain yesterday, so it may take a few days to resolve the DNS magic. Here's the text of the announcement: I’m