Re: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Galchin, Vasili
Thanks. Clause?

regards, Vasili

On Mon, Jun 9, 2008 at 12:54 AM, Bulat Ziganshin <[EMAIL PROTECTED]>
wrote:

> Hello Vasili,
>
> Monday, June 9, 2008, 6:17:14 AM, you wrote:
>
> 1. standard place to import FunPtr from is Foreign.Ptr, not System.Posix
> 2. FunPtr is exported as abstract type, without constructors. you
> can't construct values of this type directly. instead you should use
> "wrapper" generators as in the example that Clause has wrote. read it
> carefully :)
>
>
> > Hello,
>
> >  I am getting what is to me a mysterious error in a test case that I
> am writing:
> > [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell
> Setup.lhs build
> > Preprocessing executables for Test-1.0...
> >  Building Test-1.0...
> > [1 of 1] Compiling Main ( ./timer.hs,
> > dist/build/timer/timer-tmp/Main.o )
>
> > ./timer.hs:11:45: Not in scope: data constructor `FunPtr'
>
> > It seems like the compiler is complaining about the lack of FunPtr
> > in it's symbol table but System.Posix is imported:
> >
> > module Main where
>
> > import System.Posix
> > import Foreign
> > import Foreign.C
> > import Foreign.Ptr
>
> > main = do
>
> >  let event = Sigevent{sigevFunction=(FunPtr (notifyFunc))}
> << error here
> >
> >  timerId <- timerCreate Clock_Realtime Nothing
>
> >  timerDelete timerId
>
> >  return ()
>
> > notifyFunc :: Sigval -> IO ()
> > notifyFunc sigval = do
> >putStrLn "timer POP!!!"
> > return ()
>
> > I am probably looking right at the answer and not seeing it. ??
>
> > Thanks, Vasili
>
>
>
> >
>
>
> --
> Best regards,
>  Bulatmailto:[EMAIL PROTECTED]
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Package updates on haskell.org

2008-06-08 Thread Don Stewart
byorgey:
>On Thu, Jun 5, 2008 at 6:47 PM, Don Stewart <[EMAIL PROTECTED]> wrote:
> 
>  The HWN, which I'm sadly too busy to maintain now,
> 
>Does this imply that you're looking for someone to take over the HWN?  I'd
>be willing.

Yep, I've spoken with Brent. He's just starting his PhD, so a perfect
candidate to take over the weekly news. More announcements to follow.

Thanks for the offer ,  Brent!

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] Package updates on haskell.org

2008-06-08 Thread Bulat Ziganshin
Hello Brent,

Monday, June 9, 2008, 7:43:58 AM, you wrote:

>  The HWN, which I'm sadly too busy to maintain now,

> Does this imply that you're looking for someone to take over the HWN?  I'd be 
> willing.

it will be cool!


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Bulat Ziganshin
Hello Vasili,

Monday, June 9, 2008, 6:17:14 AM, you wrote:

1. standard place to import FunPtr from is Foreign.Ptr, not System.Posix
2. FunPtr is exported as abstract type, without constructors. you
can't construct values of this type directly. instead you should use
"wrapper" generators as in the example that Clause has wrote. read it
carefully :)


> Hello,

>  I am getting what is to me a mysterious error in a test case that I am 
> writing:
> [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell 
> Setup.lhs build
> Preprocessing executables for Test-1.0...
>  Building Test-1.0...
> [1 of 1] Compiling Main ( ./timer.hs,
> dist/build/timer/timer-tmp/Main.o )

> ./timer.hs:11:45: Not in scope: data constructor `FunPtr'

> It seems like the compiler is complaining about the lack of FunPtr
> in it's symbol table but System.Posix is imported:
>  
> module Main where

> import System.Posix
> import Foreign
> import Foreign.C
> import Foreign.Ptr

> main = do

>  let event = Sigevent{sigevFunction=(FunPtr (notifyFunc))}  << 
> error here
>  
>  timerId <- timerCreate Clock_Realtime Nothing

>  timerDelete timerId

>  return ()

> notifyFunc :: Sigval -> IO ()
> notifyFunc sigval = do
>    putStrLn "timer POP!!!"
>     return ()

> I am probably looking right at the answer and not seeing it. ??

> Thanks, Vasili



>   


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Fwd: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Galchin, Vasili
So Luke .. how do I go from (Sigval -> ()), i..e notifyFunc, to FunPtr using
the suggested data constructors?

On Sun, Jun 8, 2008 at 10:01 PM, Luke Palmer <[EMAIL PROTECTED]> wrote:

> 2008/6/8 Galchin, Vasili <[EMAIL PROTECTED]>:
> > Hello,
> >
> >  I am getting what is to me a mysterious error in a test case that I
> am
> > writing:
> > [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell
> > Setup.lhs build
> > Preprocessing executables for Test-1.0...
> > Building Test-1.0...
> > [1 of 1] Compiling Main ( ./timer.hs,
> > dist/build/timer/timer-tmp/Main.o )
> >
> > ./timer.hs:11:45: Not in scope: data constructor `FunPtr'
>
> There is a *type* called FunPtr in scope, but not a data constructor
> as you are using it.  That is, you could say:
>
>  foo :: FunPtr (Int -> IO ())
>
> That is, use the type called FunPtr, but you may not use a *function*
> called FunPtr, because it doesn't exist.  You need to use functions
> like nullFunPtr, castPtrToFunPtr, etc. to construct FunPtrs.
>
> Luke
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Package updates on haskell.org

2008-06-08 Thread Brent Yorgey
On Thu, Jun 5, 2008 at 6:47 PM, Don Stewart <[EMAIL PROTECTED]> wrote:

> The HWN, which I'm sadly too busy to maintain now,


Does this imply that you're looking for someone to take over the HWN?  I'd
be willing.

-Brent
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Galchin, Vasili
ah ..,. right ,. my bad.

Vasili

On Sun, Jun 8, 2008 at 10:01 PM, Luke Palmer <[EMAIL PROTECTED]> wrote:

> 2008/6/8 Galchin, Vasili <[EMAIL PROTECTED]>:
> > Hello,
> >
> >  I am getting what is to me a mysterious error in a test case that I
> am
> > writing:
> > [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell
> > Setup.lhs build
> > Preprocessing executables for Test-1.0...
> > Building Test-1.0...
> > [1 of 1] Compiling Main ( ./timer.hs,
> > dist/build/timer/timer-tmp/Main.o )
> >
> > ./timer.hs:11:45: Not in scope: data constructor `FunPtr'
>
> There is a *type* called FunPtr in scope, but not a data constructor
> as you are using it.  That is, you could say:
>
>  foo :: FunPtr (Int -> IO ())
>
> That is, use the type called FunPtr, but you may not use a *function*
> called FunPtr, because it doesn't exist.  You need to use functions
> like nullFunPtr, castPtrToFunPtr, etc. to construct FunPtrs.
>
> Luke
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Luke Palmer
2008/6/8 Galchin, Vasili <[EMAIL PROTECTED]>:
> Hello,
>
>  I am getting what is to me a mysterious error in a test case that I am
> writing:
> [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell
> Setup.lhs build
> Preprocessing executables for Test-1.0...
> Building Test-1.0...
> [1 of 1] Compiling Main ( ./timer.hs,
> dist/build/timer/timer-tmp/Main.o )
>
> ./timer.hs:11:45: Not in scope: data constructor `FunPtr'

There is a *type* called FunPtr in scope, but not a data constructor
as you are using it.  That is, you could say:

  foo :: FunPtr (Int -> IO ())

That is, use the type called FunPtr, but you may not use a *function*
called FunPtr, because it doesn't exist.  You need to use functions
like nullFunPtr, castPtrToFunPtr, etc. to construct FunPtrs.

Luke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] FunPtr error?

2008-06-08 Thread Galchin, Vasili
Hello,

 I am getting what is to me a mysterious error in a test case that I am
writing:
[EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell
Setup.lhs build
Preprocessing executables for Test-1.0...
Building Test-1.0...
[1 of 1] Compiling Main ( ./timer.hs,
dist/build/timer/timer-tmp/Main.o )

./timer.hs:11:45: Not in scope: data constructor `FunPtr'

It seems like the compiler is complaining about the lack of FunPtr in it's
symbol table but System.Posix is imported:

module Main where

import System.Posix
import Foreign
import Foreign.C
import Foreign.Ptr

main = do

 let event = Sigevent{sigevFunction=(FunPtr
(notifyFunc))}<< error here

 timerId <- timerCreate Clock_Realtime Nothing

 timerDelete timerId

 return ()

notifyFunc :: Sigval -> IO ()
notifyFunc sigval = do
   putStrLn "timer POP!!!"
   return ()

I am probably looking right at the answer and not seeing it. ??

Thanks, Vasili
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Vancouver Haskell users meeting

2008-06-08 Thread Ryan Dickie
Same deal but i'm in Ottawa for the summer. I'll be back around september.

--ryan

2008/6/6 Asumu Takikawa <[EMAIL PROTECTED]>:
> Hi. I'd be interested in a meeting like this, but unfortunately since
> UBC is done for winter term I'm out of Canada for the summer. If anyone
> organizes a meet-up come fall I'd happily attend.
>
> Cheers,
> AT
>
> On 12:48 Mon 02 Jun , Jon Strait wrote:
>>Anyone else here from Vancouver (Canada)?  I thought it would be great
>>to have a little informal get-together at a local cafe and share how
>>we're currently using Haskell, or really anything (problems,
>>comparisons, useful software tools, etc.) in relation to Haskell.
>>I'm scheduling a meeting for this Thursday, June 5th. for 7PM at
>>[1]Waazubee Cafe.  (At Commercial Dr. and 1st Ave.)
>>They have wireless internet access.  I'll get a table near the back,
>>bring my laptop, and will have a copy of Hudak's SOE book (the front
>>cover is impossible to miss) out on the table.
>>If anyone wants to meet, but this Thursday is not a good day for you,
>>let me know what days are better and we'll move the meeting.  If anyone
>>is sure that they will come this Thursday, you might let me know, so I
>>can have an idea about the resistance in changing the day, if needed.
>>Thanks,
>>Jon
>>
>> References
>>
>>1. http://www.waazubee.com/content/directions.php
>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFISL4aPVZMXBlgx7ERAv/OAJwP/1bfduqEa6bTBEaOV3420puRKACfU+Pa
> sZtx9R39ZlrrjUp8/zMlNhk=
> =+LbA
> -END PGP SIGNATURE-
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "sum" in hmatrix and blas?

2008-06-08 Thread Don Stewart

Problem solved. The Haskell loop now wins.

> > After reading don's blog, I tried to make a test with both
> > methods.  The code is very simple, as following
> > 
> > module Main where
> > import System
> > import Numeric.LinearAlgebra
> > 
> > vsum1 :: Vector Double -> Double
> > vsum1 v = constant 1 (dim v) <.> v
> > 
> > vsum2 :: Vector Double -> Double
> > vsum2 v = go (d - 1) 0
> > where
> >   d = dim v
> >   go :: Int -> Double -> Double
> >   go 0 s = s + (v @> 0)
> >   go !j !s = go (j - 1) (s + (v @> j))
> > 
> > 
> > mean :: Vector Double -> Double
> > mean v = vsum v / fromIntegral (dim v)
> > where vsum = vsum1
> > 
> > main :: IO ()
> > main = do
> >   fn:nrow:ncol:_ <- getArgs
> >   print . mean . flatten =<< fromFile fn (read nrow, read ncol)
> > 
> > Compile it with "-O2 -optc-O2", and run with a data set of
> > length 500.  The results are
> > 
> > with "vsum1":
> >  80,077,984 bytes allocated in the heap
> >   2,208 bytes copied during GC (scavenged)
> >  64 bytes copied during GC (not scavenged)
> >  40,894,464 bytes maximum residency (2 sample(s))
> >   %GC time   0.0%  (0.0% elapsed)
> >   Alloc rate35,235,448 bytes per MUT second
> > ./vsum1 huge 500 1  2.25s user 0.09s system 99% cpu 2.348 total
> > 
> > This is reasonable, exactly two copies of vector with size
> > of 40MB.
> > 
> > with "vsum2":
> > 560,743,120 bytes allocated in the heap
> >  19,160 bytes copied during GC (scavenged)
> >  15,920 bytes copied during GC (not scavenged)
> >  40,919,040 bytes maximum residency (2 sample(s))
> >   %GC time   0.3%  (0.3% elapsed)
> >   Alloc rate222,110,261 bytes per MUT second
> > ./mean2 huge 500 1  2.53s user 0.06s system 99% cpu 2.598 total
> > 
> > This is strange.  A lot of extra usage of heap?  Probably
> > because '@>' is not efficient?  So it looks like the
> > inner-product approach wins with a fairly margin.
  
> Looking at the core we get from vsum2, we see:
> 
> vsum2 compiles quite well
> 
>   $wgo_s1Nn :: Int# -> Double# -> Double#
> 
>   $wgo_s1Nn =
> \ (ww3_s1Mc :: Int#) (ww4_s1Mg :: Double#) ->
>   case ww3_s1Mc of ds_X17R {
> __DEFAULT ->
>   case Data.Packed.Internal.Vector.$wat
>  @ Double Foreign.Storable.$f9 ww_s1Ms ww1_s1Mu (I# 
> ds_X17R)
>   of { D# y_a1KQ ->
>   $wgo_s1Nn (-# ds_X17R 1) (+## ww4_s1Mg y_a1KQ)
>   };
> 0 -> +## ww4_s1Mg ww2_s1M7
>   };
> } in  $wgo_s1Nn (-# ww_s1Ms 1) 0.0
> 
> But note the return value from $wat is boxed, only to be immediately
> unboxed. That looks to be the source of the heap allocations.
> 
> Let's see if we can help that.

Ah, of course. The problem is the unsafePerformIO used to wrap up the
'peek'. This blocks the optimisations somewhat, after we unpack the Vector 
type.. 

So if we rewrite 'safeRead' to not use unsafePerformIO, but instead:

safeRead v = inlinePerformIO . withForeignPtr (fptr v)

inlinePerformIO (IO m) = case m realWorld# of (# _, r #) -> r

Along with this change to Vector:

data Vector t = V { dim  :: {-# UNPACK #-} !Int
  , fptr :: {-# UNPACK #-} !(ForeignPtr t)
  }

and some inlining for the bounds checks.
Following bytestrings, we see the performance go from, with a 180M input
file:

Goal:
vsum1:
$ ghc-core A.hs -optc-O2 -fvia-C  -fbang-patterns
$ time ./A data 4000 2500
0.727441161678

./A data 4000 2500  5.37s user 0.20s system 99% cpu 5.609 total
160,081,136 bytes allocated in the heap
155 Mb total memory in use

Before:
vsum2-old:

 $wgo_s1Ns =
\ (ww3_s1Me :: Int#) (ww4_s1Mi :: Double#) ->
  case ww3_s1Me of ds_X17Y {
__DEFAULT ->
  case Data.Packed.Internal.Vector.$wat
 @ Double Foreign.Storable.$f9 ww_s1Mu ww1_s1Mw (I# ds_X17Y)
  of wild1_a1Hg { D# y_a1Hi ->
  $wgo_s1Ns (-# ds_X17Y 1) (+## ww4_s1Mi y_a1Hi)
  };
0 -> +## ww4_s1Mi ww2_s1M9
  };
} in  $wgo_s1Ns (-# ww_s1Mu 1) 0.0
 
./A data 4000 2500 +RTS -sstderr 
0.72744115876

./A data 4000 2500 +RTS -sstderr  6.04s user 0.15s system 99% cpu 6.203 
total
1,121,416,400 bytes allocated in the heap
78 Mb total memory in use

After:
True ->
  case readDoubleOffAddr#
 @ RealWorld ww1_s1Nr ds_X180 realWorld#
  of wild2_a1HS { (# s2_a1HU, x_a1HV #) ->
  case touch# @ ForeignPtrContents ww2_s1Ns s2_a1HU
  of s_a1HG { __DEFAULT ->
  $wgo_s1Ok (-# ds_X180 1) (+## ww4_s1Ng x_a1HV)
  }

No needless boxing.

$ time ./A data 4000 2500 +RTS -sstderr  
./A data 4000 2500 +RTS -sstderr 
0.72744115876

./A data 4000 2500 +RTS -sstderr  5.41s user 0.10s system 99% cpu 5.548 
total
 80,071,072 bytes al

Re: [Haskell-cafe] Printing a random list

2008-06-08 Thread Ronald Guida
Bryan Catanzaro wrote:
> However, when I ran my random list generator, the interpreter had a stack
> overflow.  Here's my code again:
> ---
> module Main
>where
>  import IO
>  import Random
>
>  randomList :: Random a => a -> a-> [IO a]
>  randomList lbound ubound = randomRIO(lbound, ubound) : randomList
> lbound ubound
>
>
>  main = do
>myRandomList <- sequence(randomList (0::Int) 255)
>putStrLn(show(take 10 myRandomList))
> ---
>
> It seems that this code somehow tries to evaluate every element of the
> infinite list defined by randomList.

You are correct.

> Can you tell me why it is not lazily evaluating this list?

Whenever you use IO, there is a baton being passed along behind the
scenes.  The baton is called "RealWorld#" and it represents the fact
that interactions with global state and the outside world have to be
serialized.

In particular, whenever you use the global random number generator, a
global state variable has to be updated.  This has to be serialized,
thus the baton has to be passed along from one action to the next.

When you "sequence" a list of IO actions, you are effectively sending
the baton along that list, and you don't get it back until the end of
the list is reached.  Your code is sending the baton into an infinite
list of actions, never to be returned.

>  I can get around this by changing main to do this
> instead:
>
> ---
>  main = do
>myRandomList <- sequence(take 10 (randomList (0::Int) 255))
>putStrLn(show(myRandomList))
> ---

Now you are sending the baton into a list of only 10 actions.  The
baton comes back, and the program goes on.

If you don't know in advance how many random numbers you need, and if
you are satisfied with the global random number generator, then Don
Stewart's solution is a better approach.

Don Stewart wrote:
>   main = do
> g <- newStdGen
> print (take 10 (randomRs (0,255) g :: [Int]))

If you want to be able to reproduce the same sequence of random
numbers, for example for testing and debugging purposes, then you can
use mkStdGen to create your own random number generator, independent
of the global one.  The catch is that you will have to thread the
state of the random number generator through your code.  Once you
learn about monads (if you haven't already), you'll recognize that you
can use the State monad for your random number generator.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2008-06-08 Thread Xiao-Yong Jin
"Bryan O'Sullivan" <[EMAIL PROTECTED]> writes:

> Judah Jacobson wrote:
>
>> My preference is to use an autoconf script to solve that problem.
>> ("build-type: Configure" in the cabal file.)
>
> That approach would not work well for BLAS.  The various BLAS libraries
> have profoundly different performance characteristics, and you wouldn't
> want to get the wrong one for your system, if you had both installed.

Is the blas library linked statically?  It looks to me that
the binary is dynamically linked.

linux-vdso.so.1 =>  (0x7fff003fe000)
libgsl.so.0 => /usr/lib/libgsl.so.0 (0x2af4aa8cc000)
libblas.so.0 => /usr/lib/libblas.so.0 (0x2af4aac91000)
liblapack.so.0 => /usr/lib/liblapack.so.0 (0x2af4aaeb)
libutil.so.1 => /lib/libutil.so.1 (0x2af4ab612000)
libdl.so.2 => /lib/libdl.so.2 (0x2af4ab815000)
libm.so.6 => /lib/libm.so.6 (0x2af4aba19000)
libgmp.so.3 => /usr/lib/libgmp.so.3 (0x2af4abc9b000)
librt.so.1 => /lib/librt.so.1 (0x2af4abedb000)
libc.so.6 => /lib/libc.so.6 (0x2af4ac0e4000)
libgslcblas.so.0 => /usr/lib/libgslcblas.so.0 (0x2af4ac424000)
libgfortran.so.1 => 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/libgfortran.so.1 (0x2af4ac654000)
libatlas.so.0 => /usr/lib/libatlas.so.0 (0x2af4ac8eb000)
libpthread.so.0 => /lib/libpthread.so.0 (0x2af4ad123000)
libcblas.so.0 => /usr/lib/libcblas.so.0 (0x2af4ad33e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x2af4ad55d000)
/lib64/ld-linux-x86-64.so.2 (0x2af4aa6b)

And presumably the various BLAS implementations share
identical interface.  You can still change the library at
run-time with LD_LIBRARY_PATH.  Or am I missing something?

Xiao-Yong
-- 
c/*__o/*
<\ * (__
*/\  <
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "sum" in hmatrix and blas?

2008-06-08 Thread Don Stewart
Below are some notes on this for Simon PJ and Alberto.

In general, GHC is doing very well here, with only one small wibble preventing 
the 
recursive version running as fast as the C version.

xj2106:
> Alberto Ruiz <[EMAIL PROTECTED]> writes:
> 
> > My experience is that Haskell allocation time is very fast and usually
> > negligible in most non trivial matrix computations.
> >
> > A good thing about
> >
> > sum v = constant 1 (dim v) <.> v
> >
> > is that a constant vector is efficiently created internally (not from
> > an intermediate Haskell list), and the inner product will be computed
> > by the possibly optimized blas version available in your machine.
> >
> > You can also write simple definitions like the next one for the
> > average of the rows of a matrix as a simple vector-matrix product:
> >
> > mean m = w <> m
> > where w = constant k r
> >   r = rows m
> >   k = 1 / fromIntegral r
> >
> > I prefer high level "index free" matrix operations to C-like
> > code. Definitions are clearer, have less bugs, and are also more
> > efficient if you use optimized numerical libs.
> >
> > In any case, many algorithms can be solved by the recursive approach
> > described by Tomas.
> 
> After reading don's blog, I tried to make a test with both
> methods.  The code is very simple, as following
> 
> module Main where
> import System
> import Numeric.LinearAlgebra
> 
> vsum1 :: Vector Double -> Double
> vsum1 v = constant 1 (dim v) <.> v
> 
> vsum2 :: Vector Double -> Double
> vsum2 v = go (d - 1) 0
> where
>   d = dim v
>   go :: Int -> Double -> Double
>   go 0 s = s + (v @> 0)
>   go !j !s = go (j - 1) (s + (v @> j))
> 
> 
> mean :: Vector Double -> Double
> mean v = vsum v / fromIntegral (dim v)
> where vsum = vsum1
> 
> main :: IO ()
> main = do
>   fn:nrow:ncol:_ <- getArgs
>   print . mean . flatten =<< fromFile fn (read nrow, read ncol)
> 
> Compile it with "-O2 -optc-O2", and run with a data set of
> length 500.  The results are
> 
> with "vsum1":
>  80,077,984 bytes allocated in the heap
>   2,208 bytes copied during GC (scavenged)
>  64 bytes copied during GC (not scavenged)
>  40,894,464 bytes maximum residency (2 sample(s))
>   %GC time   0.0%  (0.0% elapsed)
>   Alloc rate35,235,448 bytes per MUT second
> ./vsum1 huge 500 1  2.25s user 0.09s system 99% cpu 2.348 total
> 
> This is reasonable, exactly two copies of vector with size
> of 40MB.
> 
> with "vsum2":
> 560,743,120 bytes allocated in the heap
>  19,160 bytes copied during GC (scavenged)
>  15,920 bytes copied during GC (not scavenged)
>  40,919,040 bytes maximum residency (2 sample(s))
>   %GC time   0.3%  (0.3% elapsed)
>   Alloc rate222,110,261 bytes per MUT second
> ./mean2 huge 500 1  2.53s user 0.06s system 99% cpu 2.598 total
> 
> This is strange.  A lot of extra usage of heap?  Probably
> because '@>' is not efficient?  So it looks like the
> inner-product approach wins with a fairly margin.

Yes, I'd suspect that @> isn't fully unlifted, so you get some heap
allocation on each index, each time around the loop? We'd have to look
at how @> was defined to spot why. 

I began with:

$ cabal install hmatrix

which failed, due to missing linking against gfortran and glscblas
Added those to the cabal file, and hmatrix was installed.

Looking at the core we get from vsum2, we see:

vsum2 compiles quite well

  $wgo_s1Nn :: Int# -> Double# -> Double#

  $wgo_s1Nn =
\ (ww3_s1Mc :: Int#) (ww4_s1Mg :: Double#) ->
  case ww3_s1Mc of ds_X17R {
__DEFAULT ->
  case Data.Packed.Internal.Vector.$wat
 @ Double Foreign.Storable.$f9 ww_s1Ms ww1_s1Mu (I# ds_X17R)
  of { D# y_a1KQ ->
  $wgo_s1Nn (-# ds_X17R 1) (+## ww4_s1Mg y_a1KQ)
  };
0 -> +## ww4_s1Mg ww2_s1M7
  };
} in  $wgo_s1Nn (-# ww_s1Ms 1) 0.0

But note the return value from $wat is boxed, only to be immediately
unboxed. That looks to be the source of the heap allocations.

Let's see if we can help that.

Vector is defined as:

data Vector t = V { dim  :: Int  -- ^ number of elements
  , fptr :: ForeignPtr t -- ^ foreign pointer to the 
memory block
  }

While a much better definition would be:

   data Vector t = V { dim  :: {-# UNPACK #-} !Int   -- ^ number of 
elements
 , fptr :: {-# UNPACK #-} !(ForeignPtr t)-- ^ foreign 
pointer to the memory block
 }
 
And we can add some inlining to at' and at.
That might be enough for GHC to see through to the D# boxing.

Now they're fully unfolded and specialised into our source program,

True ->
  case unsafeDupablePerformIO
 @ Double
 ((\ (eta1_a1KA :: State# RealWorld) ->
 case noD

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

2008-06-08 Thread Bryan O'Sullivan
Judah Jacobson wrote:

> My preference is to use an autoconf script to solve that problem.
> ("build-type: Configure" in the cabal file.)

That approach would not work well for BLAS.  The various BLAS libraries
have profoundly different performance characteristics, and you wouldn't
want to get the wrong one for your system, if you had both installed.

http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Printing a random list

2008-06-08 Thread Bryan Catanzaro
Thanks for the response, it does compile after I juggled some  
parentheses around.  And also I appreciate the pointer to the better  
way of making a random list.  So that problem is solved.


However, when I ran my random list generator, the interpreter had a  
stack overflow.  Here's my code again:

---
module Main
where
  import IO
  import Random

  randomList :: Random a => a -> a-> [IO a]
  randomList lbound ubound = randomRIO(lbound, ubound) :  
randomList lbound ubound



  main = do
myRandomList <- sequence(randomList (0::Int) 255)
putStrLn(show(take 10 myRandomList))
---

It seems that this code somehow tries to evaluate every element of the  
infinite list defined by randomList.  Can you tell me why it is not  
lazily evaluating this list?  I can get around this by changing main  
to do this instead:


---
  main = do
myRandomList <- sequence(take 10 (randomList (0::Int) 255))
putStrLn(show(myRandomList))
---

But I don't understand why sequence(randomList (0::Int) 255) actually  
tries to evaluate the entire infinite list, instead of just lazily  
defining a list with the proper types, that I evaluate later when I  
take elements from it.


Thanks for your help!

- bryan

On Jun 8, 2008, at 4:33 PM, Don Stewart wrote:


catanzar:

I'm just starting out with Haskell, and I could use some help.  I'm
trying to create a random list and print it out, which seems simple
enough, but has been giving me problems.  Here's what I have:

module Main
   where
 import IO
 import Random

 randomList :: Random a => a -> a-> [IO a]
 randomList lbound ubound = randomRIO(lbound, ubound) :
randomList lbound ubound


 main = do
   myRandomList <- sequence(randomList(0::Int 255))
   putStrLn(show(take(10 myRandomList)))



-

So, I have tried to make a randomList action which defines an  
infinite

random list, bounded by lbound and ubound.  It seems that to print
this, I need to convert between randomList, which is of type [IO a]  
to

something like IO [a], which is what sequence should do for me.  Then
I just want to print out the first 10 elements.

I'm currently getting the error "Only unit numeric type pattern is
valid", pointing to 0::Int 255 in the code.  I'm not sure what this
means.


Missing parenthesis around the (0 :: Int) type annotation.


I'm sure I'm looking at this the wrong way, since I'm new to Haskell
and haven't quite wrapped my head around it yet.  Maybe you can fix
the problem by showing me a more Haskell approach to creating a  
random

list and printing it...  =)



For lists, best to use the randomRs function,

   import System.Random

   main = do
   g <- newStdGen
   print (take 10 (randomRs (0,255) g :: [Int]))

Running it:

   $ runhaskell A.hs
   [11,90,187,119,240,57,241,52,143,86]

Cheers,
 Don


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "sum" in hmatrix and blas?

2008-06-08 Thread Xiao-Yong Jin
Alberto Ruiz <[EMAIL PROTECTED]> writes:

> My experience is that Haskell allocation time is very fast and usually
> negligible in most non trivial matrix computations.
>
> A good thing about
>
> sum v = constant 1 (dim v) <.> v
>
> is that a constant vector is efficiently created internally (not from
> an intermediate Haskell list), and the inner product will be computed
> by the possibly optimized blas version available in your machine.
>
> You can also write simple definitions like the next one for the
> average of the rows of a matrix as a simple vector-matrix product:
>
> mean m = w <> m
> where w = constant k r
>   r = rows m
>   k = 1 / fromIntegral r
>
> I prefer high level "index free" matrix operations to C-like
> code. Definitions are clearer, have less bugs, and are also more
> efficient if you use optimized numerical libs.
>
> In any case, many algorithms can be solved by the recursive approach
> described by Tomas.

After reading don's blog, I tried to make a test with both
methods.  The code is very simple, as following

module Main where
import System
import Numeric.LinearAlgebra

vsum1 :: Vector Double -> Double
vsum1 v = constant 1 (dim v) <.> v

vsum2 :: Vector Double -> Double
vsum2 v = go (d - 1) 0
where
  d = dim v
  go :: Int -> Double -> Double
  go 0 s = s + (v @> 0)
  go !j !s = go (j - 1) (s + (v @> j))


mean :: Vector Double -> Double
mean v = vsum v / fromIntegral (dim v)
where vsum = vsum1

main :: IO ()
main = do
  fn:nrow:ncol:_ <- getArgs
  print . mean . flatten =<< fromFile fn (read nrow, read ncol)

Compile it with "-O2 -optc-O2", and run with a data set of
length 500.  The results are

with "vsum1":
 80,077,984 bytes allocated in the heap
  2,208 bytes copied during GC (scavenged)
 64 bytes copied during GC (not scavenged)
 40,894,464 bytes maximum residency (2 sample(s))
  %GC time   0.0%  (0.0% elapsed)
  Alloc rate35,235,448 bytes per MUT second
./vsum1 huge 500 1  2.25s user 0.09s system 99% cpu 2.348 total

This is reasonable, exactly two copies of vector with size
of 40MB.

with "vsum2":
560,743,120 bytes allocated in the heap
 19,160 bytes copied during GC (scavenged)
 15,920 bytes copied during GC (not scavenged)
 40,919,040 bytes maximum residency (2 sample(s))
  %GC time   0.3%  (0.3% elapsed)
  Alloc rate222,110,261 bytes per MUT second
./mean2 huge 500 1  2.53s user 0.06s system 99% cpu 2.598 total

This is strange.  A lot of extra usage of heap?  Probably
because '@>' is not efficient?  So it looks like the
inner-product approach wins with a fairly margin.
-- 
c/*__o/*
<\ * (__
*/\  <
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Printing a random list

2008-06-08 Thread Don Stewart
catanzar:
> I'm just starting out with Haskell, and I could use some help.  I'm  
> trying to create a random list and print it out, which seems simple  
> enough, but has been giving me problems.  Here's what I have:
> 
> module Main
> where
>   import IO
>   import Random
> 
>   randomList :: Random a => a -> a-> [IO a]
>   randomList lbound ubound = randomRIO(lbound, ubound) :  
> randomList lbound ubound
> 
> 
>   main = do
> myRandomList <- sequence(randomList(0::Int 255))
> putStrLn(show(take(10 myRandomList)))
> 
> 
> 
> -
> 
> So, I have tried to make a randomList action which defines an infinite  
> random list, bounded by lbound and ubound.  It seems that to print  
> this, I need to convert between randomList, which is of type [IO a] to  
> something like IO [a], which is what sequence should do for me.  Then  
> I just want to print out the first 10 elements.
> 
> I'm currently getting the error "Only unit numeric type pattern is  
> valid", pointing to 0::Int 255 in the code.  I'm not sure what this  
> means.

Missing parenthesis around the (0 :: Int) type annotation.

> I'm sure I'm looking at this the wrong way, since I'm new to Haskell  
> and haven't quite wrapped my head around it yet.  Maybe you can fix  
> the problem by showing me a more Haskell approach to creating a random  
> list and printing it...  =)
> 

For lists, best to use the randomRs function,

import System.Random

main = do
g <- newStdGen
print (take 10 (randomRs (0,255) g :: [Int]))

Running it:

$ runhaskell A.hs
[11,90,187,119,240,57,241,52,143,86]

Cheers,
  Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Printing a random list

2008-06-08 Thread Bryan Catanzaro
I'm just starting out with Haskell, and I could use some help.  I'm  
trying to create a random list and print it out, which seems simple  
enough, but has been giving me problems.  Here's what I have:


module Main
where
  import IO
  import Random

  randomList :: Random a => a -> a-> [IO a]
  randomList lbound ubound = randomRIO(lbound, ubound) :  
randomList lbound ubound



  main = do
myRandomList <- sequence(randomList(0::Int 255))
putStrLn(show(take(10 myRandomList)))



-

So, I have tried to make a randomList action which defines an infinite  
random list, bounded by lbound and ubound.  It seems that to print  
this, I need to convert between randomList, which is of type [IO a] to  
something like IO [a], which is what sequence should do for me.  Then  
I just want to print out the first 10 elements.


I'm currently getting the error "Only unit numeric type pattern is  
valid", pointing to 0::Int 255 in the code.  I'm not sure what this  
means.


I'm sure I'm looking at this the wrong way, since I'm new to Haskell  
and haven't quite wrapped my head around it yet.  Maybe you can fix  
the problem by showing me a more Haskell approach to creating a random  
list and printing it...  =)


Thanks!

- bryan catanzaro

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Quick question for a slow program

2008-06-08 Thread Lanny Ripple
At least when I teased apart why the first one worked it looked
heap-like.  Each step of the foldr pulled off the smallest nonprime
and merged the next two lists guaranteeing that the next smallest
nonprime would be at the head of the next step.

Can't argue with results though.  The version you have up is about
twice as fast as the old one (if a bit harder to read).

  -ljr

apfelmus wrote:
> Lanny Ripple wrote:
>> The second prime generator on this page
>>
>>http://www.haskell.org/haskellwiki/Prime_numbers
>>
>> is quick and easy.  I keep it nearby for all those sudden attacks of
>> needing to solve yet another projecteuler problem.
> 
> The second prime sieve did not create an implicit heap as advertised.
> I've fixed that and also cleaned up the page a bit, moving this sieve to
> the section "Implicit Heap".
> 
> 
> Regards,
> apfelmus
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "sum" in hmatrix and blas?

2008-06-08 Thread Alberto Ruiz

Xiao-Yong Jin wrote:

Tomas Andersson <[EMAIL PROTECTED]> writes:

 You can never go wrong with a good old fashioned hand written tail recursion 
when you're in doubt, they are pretty much the closest thing to for-loops 
there is in haskell and should be easy to grok for Imperative programmers and 
usually produce really fast code.


sum vect = let d = dim vect
   in sum' (d - 1) 0
  where sum' 0 s = s + (vect @> 0)
sum' index s = sum' (index - 1) (s + (vect @> index))



Do I need the strict version of sum'?  Put something like

sum' a b | a `seq` b `seq` False = undefined

Or ghc will optimize it automatically?  I always don't know
when such optimization is useful.



 I don't know the hmatrix api very well, but if there is a function for 
computing the inner product between two vectors you could always do something 
like the following meta code:


sum v = innerProduct v <1,1,1,1,1,1>


I just doubt the efficiency here.  If v is a very large
vector, I guess the allocation time of that intermediate
vector [1,1..] is not small.  But it is just my guess.


My experience is that Haskell allocation time is very fast and usually 
negligible in most non trivial matrix computations.


A good thing about

sum v = constant 1 (dim v) <.> v

is that a constant vector is efficiently created internally (not from an 
intermediate Haskell list), and the inner product will be computed by 
the possibly optimized blas version available in your machine.


You can also write simple definitions like the next one for the average 
of the rows of a matrix as a simple vector-matrix product:


mean m = w <> m
where w = constant k r
  r = rows m
  k = 1 / fromIntegral r

I prefer high level "index free" matrix operations to C-like code. 
Definitions are clearer, have less bugs, and are also more efficient if 
you use optimized numerical libs.


In any case, many algorithms can be solved by the recursive approach 
described by Tomas.


Alberto



Xiao-Yong

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "sum" in hmatrix and blas?

2008-06-08 Thread Don Stewart
xj2106:
> Tomas Andersson <[EMAIL PROTECTED]> writes:
> 
> >  You can never go wrong with a good old fashioned hand written tail 
> > recursion 
> > when you're in doubt, they are pretty much the closest thing to for-loops 
> > there is in haskell and should be easy to grok for Imperative programmers 
> > and 
> > usually produce really fast code.
> >
> > sum vect = let d = dim vect
> >in sum' (d - 1) 0
> >   where sum' 0 s = s + (vect @> 0)
> > sum' index s = sum' (index - 1) (s + (vect @> index))
> >
> 
> Do I need the strict version of sum'?  Put something like
> 
> sum' a b | a `seq` b `seq` False = undefined
> 
> Or ghc will optimize it automatically?  I always don't know
> when such optimization is useful.

If you give a type annotation, so GHC can tell its an atomic type, like
Int or Double, 's' will be inferred as strict. But if in doubt, use bang
patterns:

{-# LANGUAGE BangPatterns #-}

sum vect = sum' (d-1) 0
where
d = dim vect

go :: Int -> Double -> Double   -- for example
go 0 s = s + (vect @> 0)
go !i !s = go (i-1) (s + (vect @> i))


See this recent post on understanding how these kind of loops are compiled,

http://cgi.cse.unsw.edu.au/~dons/blog/2008/05/16

The core for your loop should look very good, assuming @> is efficient.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2008-06-08 Thread Judah Jacobson
2008/6/6 Patrick Perry <[EMAIL PROTECTED]>:
>
> Apart from some warnings, the library compiles fine in my
> system.  But there is a minor issue about the library it
> links against when `./Setup test'.  I need to use `-lcblas'
> instead of `-lblas' to get it to link to correct libraries.
> I don't know other people's system.  But in my system,
> Gentoo Linux, I use blas library provided by atlas, and
> libblas.so is a fortran library and libcblas.so is for C.
>
> I don't know of a good way to get around this.  It seems like every system
> has a different convention for the location and name of the cblas libraries.
>  So, everyone has to edit the "extra-libraries" and the "extra-lib-dirs"
> field in the blas.cabal file.  Does anyone know of a better way of doing
> this?
>

My preference is to use an autoconf script to solve that problem.
("build-type: Configure" in the cabal file.)

For example, the editline and readline C libraries require termcap,
which may be linked using one of -lcurses, -ltermcap, etc.  The
Haskell packages have a configure script which checks which of
curses/termcap is available and outputs an editline.buildinfo file
with the extra-libraries field filled in.  That file is then used
automatically by cabal in the build and install phases.

See for example:
http://code.haskell.org/editline/editline.cabal
http://code.haskell.org/editline/configure.ac
http://code.haskell.org/editline/editline.buildinfo.in

There's also more information is in the Cabal manual:
http://haskell.org/cabal/release/latest/doc/users-guide/x30.html#system-dependent

Best,
-Judah
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "sum" in hmatrix and blas?

2008-06-08 Thread Xiao-Yong Jin
Tomas Andersson <[EMAIL PROTECTED]> writes:

>  You can never go wrong with a good old fashioned hand written tail recursion 
> when you're in doubt, they are pretty much the closest thing to for-loops 
> there is in haskell and should be easy to grok for Imperative programmers and 
> usually produce really fast code.
>
> sum vect = let d = dim vect
>in sum' (d - 1) 0
>   where sum' 0 s = s + (vect @> 0)
> sum' index s = sum' (index - 1) (s + (vect @> index))
>

Do I need the strict version of sum'?  Put something like

sum' a b | a `seq` b `seq` False = undefined

Or ghc will optimize it automatically?  I always don't know
when such optimization is useful.

>
>
>  I don't know the hmatrix api very well, but if there is a function for 
> computing the inner product between two vectors you could always do something 
> like the following meta code:
>
> sum v = innerProduct v <1,1,1,1,1,1>

I just doubt the efficiency here.  If v is a very large
vector, I guess the allocation time of that intermediate
vector [1,1..] is not small.  But it is just my guess.

Xiao-Yong
-- 
c/*__o/*
<\ * (__
*/\  <
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Quick question for a slow program

2008-06-08 Thread apfelmus

Lanny Ripple wrote:

The second prime generator on this page

   http://www.haskell.org/haskellwiki/Prime_numbers

is quick and easy.  I keep it nearby for all those sudden attacks of
needing to solve yet another projecteuler problem.


The second prime sieve did not create an implicit heap as advertised. 
I've fixed that and also cleaned up the page a bit, moving this sieve to 
the section "Implicit Heap".



Regards,
apfelmus

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Issues of the "mailto" link on the list archive page

2008-06-08 Thread Ian Lynagh
On Sat, Jun 07, 2008 at 10:21:13AM -0400, Xiao-Yong Jin wrote:
> 
> I had private conversation with Andrzej Jaworski about the
> fact that his reply to Alberto Ruiz's post is off thread.
> What he did was clicking on the "mailto" link beside the
> author's name on the list archive web page [1].
> 
> [1] http://www.haskell.org/pipermail/haskell-cafe/2008-June/044023.html
> 
> I am not quite sure about what this link is supposed to do.
> But, if it is meant for people to click and reply to the
> thread, it is not doing this correctly, as the "Subject" and
> "In-Reply-To" fields in the link are obtained from these
> fields in the head of current email.  It would be useful if
> the link shows "Subject" with an added "Re: " if there is
> not already one, and fill in the "in-Reply-To" field with
> the value from the "Message-Id" field of current email
> head.  An optional "Reference" field is informative for most
> of the email client, too.

If anyone knows how we can make mailman do this better, please let us
know.


Thanks
Ian

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.Map traversal.

2008-06-08 Thread Ian Lynagh

Hi Serguey,

On Sat, Jun 07, 2008 at 05:32:46PM +0400, Serguey Zefirov wrote:
> 
> So I propose to include those operations into next version of Data.Map.
> 
> If anyone could point me in the right direction I could do any necessary 
> modifications myself (just because I need it).

Please see http://www.haskell.org/haskellwiki/Library_submissions for
how to propose changes to the libraries.


Thanks
Ian

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "sum" in hmatrix and blas?

2008-06-08 Thread Tomas Andersson
Den Sunday 08 June 2008 00.45.01 skrev Xiao-Yong Jin:

> Any delightful idea to convert my mind from a C shaped one
> to a Haskell shaped one?
>

 You can never go wrong with a good old fashioned hand written tail recursion 
when you're in doubt, they are pretty much the closest thing to for-loops 
there is in haskell and should be easy to grok for Imperative programmers and 
usually produce really fast code.

sum vect = let d = dim vect
   in sum' (d - 1) 0
  where sum' 0 s = s + (vect @> 0)
sum' index s = sum' (index - 1) (s + (vect @> index))


 I don't know the hmatrix api very well, but if there is a function for 
computing the inner product between two vectors you could always do something 
like the following meta code:

sum v = innerProduct v <1,1,1,1,1,1>


> Best,
> Xiao-Yong


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Design your modules for qualified import

2008-06-08 Thread Johan Tibell
On Sat, Jun 7, 2008 at 3:03 PM, Dan Doel <[EMAIL PROTECTED]> wrote:
> On Friday 06 June 2008, Andrew Coppin wrote:
>> It's really quite frustrating that it is 100% impossible to write a
>> single function that will process lists, arrays, sets, maps, byte
>> strings, etc. You have to write several different versions. OK, so some
>> functions really don't make sense for a set because it's unordered, and
>> some functions don't make sense for a map, and so forth. But for
>> example, if I write some complicated algorithm that uses a list to store
>> data and I change that to a set instead, I now have to wade through the
>> function changing every operation from a list-op into a set-op. It's
>> really very annoying!
>
> It's not 100% impossible, depending on what exactly you're doing. For
> instance...
>
>  Set a, ByteStrings, Seq a, Map k a and [a] are Monoids
>  Set, Array i, Map k, Tree, Seq and [] are Foldable functors
>  Array i, Map k, Tree, Seq, Tree and [] are Traversable functors
>
> Those can get you lots of operations (folds, maps, unions...) although there
> may be gaps that could be filled (Foldable is sufficient to define null, for
> instance, but it isn't in Data.Foldable).

These do help in the case you want to traverse data structures that
share a set of properties (e.g. are Functors). However, it doesn't
address the problem of sharing an interface among Set, IntSet,
ByteSet, etc. In other words there's a need for a Set type class.
Hopefully type families will help us write such an interface and keep
it efficient.

Cheers,

Johan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Mersenne Build Problem

2008-06-08 Thread Dominic Steinitz
Bertram Felgenhauer  googlemail.com> writes:

> 
> The missing symbols are inlined functions. ghc 6.9 doesn't include the
> header files anymore when compiling via C. (The solution is to create
> C wrappers around those functions. I guess I'll whip up a patch.)
> 

Bertram,

Thanks. That's done the trick. I tried 0.1.1 and it works with 6.8 and 0.1.2 
works with 6.9.

It certainly is a lot faster than system.random.

Dominic.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe