From olefc at daimi.au.dk  Mon Jan  2 14:05:43 2006
From: olefc at daimi.au.dk (Ole F. Christensen)
Date: Mon, 02 Jan 2006 14:05:43 +0100
Subject: [Rd] R crash with complex matrix algebra when using EISPACK=TRUE
Message-ID: <43B92527.4040003@daimi.au.dk>


Dear subscribers of R-devel

I am experiencing that R crashes (further details are given below) in
some complex matrix calculations when EISPACK=TRUE has been specified in 
eigen().
I discovered the behaviour some months ago just after the
release of R-2.2.0, and it has been lying on my desk since.
I apologise for not having nailed the problem down to a simple function 
call, but I thought I should better report the problem now
instead of waiting.
My hope is that someone will either spot the cause
of the crash in a minute, or otherwise provide some help for me to
investigate further. 


## The code :


source("http://www.daimi.au.dk/~olefc/TEST/fct.R")
source("http://www.daimi.au.dk/~olefc/TEST/parm.crash.R")

for(l.v in 1:4){
  for(r.v in 1:4){
    for(l.x in 1:4){
      for(r.x in 1:4){
        hvad <- 
inhomoWmat.complex(subst.ratematrix(parm.same.str.sym$Gamma[,,l.v,r.v]),subst.ratematrix(parm.same.str.sym$Gamma[,,l.x,r.x]), 
EISPACK=TRUE)
        print(c(l.v,r.v,l.x,r.x))
      }
    }
  }
}


## gives

[1] 1 1 1 1
[1] 1 1 1 2
[1] 1 1 1 3
[1] 1 1 1 4
[1] 1 1 2 1
Segmentation fault



### whereas the code seems to work fine when EISPACK=FALSE :


source("http://www.daimi.au.dk/~olefc/TEST/fct.R")
source("http://www.daimi.au.dk/~olefc/TEST/parm.crash.R")

for(l.v in 1:4){
  for(r.v in 1:4){
    for(l.x in 1:4){
      for(r.x in 1:4){
        hvad <- 
inhomoWmat.complex(subst.ratematrix(parm.same.str.sym$Gamma[,,l.v,r.v]),subst.ratematrix(parm.same.str.sym$Gamma[,,l.x,r.x]), 
EISPACK=FALSE)
        print(c(l.v,r.v,l.x,r.x))
      }
    }
  }
}

## works fine.


## There is some randomness in how and when the crash happens.
## The crash is either :

Segmentation fault

#

*** glibc detected *** double free or corruption (!prev): 0x08aa7298
    ***

# or

*** glibc detected *** free(): invalid pointer: 0x082bfd20 ***



## Seen on R-2.2-1 and  R-2.2-0 .
## Not seen in R-2.1.1 !
## I haven't investiated whether it happens on Windows also.


### A few details on the matrix calculations :
The eigenvalue decomposition is done on 4 * 4 matrices where the rows 
sum to 0.
The matrices may be on the edge of not being complex diagonalizable.


version
         _
platform i686-pc-linux-gnu
arch     i686
os       linux-gnu
system   i686, linux-gnu
status
major    2
minor    2.1
year     2005
month    12
day      20
svn rev  36812
language R


Thanks in advance of any help.

Ole Christensen

-- 
Ole F. Christensen
BiRC - Bioinformatics Research Center
University of Aarhus



[Rd] R crash with complex matrix algebra when using EISPACK=TRUE
Ole F. Christensen