Silverfrost Forums

Welcome to our forums

MATMUL bug

3 Jun 2015 1:14 (Edited: 15 Jun 2015 10:01) #16407

This is a simplified version of a bug reported by AntonioGJerez in http://forums.silverfrost.com/viewtopic.php?p=18250#18250 . FTN95 7.10 gives wrong results when MATMUL is invoked with a single-precision complex argument and a double-precision real argument. Here is an example in which MATMUL is used to evaluate the outer product of vectors B and C, where B is represented as a 2 X 1 double-precision matrix and C as a 1 X 2 single-precision complex matrix. The bug does not occur if B is made single-precision.

program MatmulBug
implicit none
double precision B(2,1) 
complex C(1,2) 
!
B=dble(reshape((/1.,2./),(/2,1/))) 
C=cmplx(reshape((/1.,3./),(/1,2/))) 
!
write(*,*)'B = ',B
write(*,*)'C = ',C
write(*,*)'B X C = ',matmul(B,C) 

end program

FTN95 gives the product as (in usual Fortran 2-D array order) [(0,1.875), (0,3.75), (0,2.125), (0,4.25)], instead of the correct result, [(1,0), (2,0), (3,0), (6,0)].

[P.S., 15 June 2015: This bug is also present in FTN95-7.20]

3 Jun 2015 2:42 #16410

Thanks for the feedback. I have logged this for investigation.

3 Jun 2015 11:39 #16416

Hello,

This is another simple example of conversion from real*8 to complex that doesn´t work (and no warning or error is displayed)

regards

  program bug3

  COMPLEX A(4,4)
  REAL*8 B(4,4)
  
  PRINT*,'This runs ok'
  B=RESHAPE((/1.d0,0.d0,0.d0,0.d0, 0.d0,1.d0,0.d0,0.d0,0.d0,0.d0,1.d0,0.d0, 0.d0,0.d0,0.d0,1.d0/),(/4,4/))               
  print*,B
  print*,CMPLX(B)
  PRINT*
  PRINT*,'This doesn´t run ok'      
  print*,CMPLX(RESHAPE((/1.d0,0.d0,0.d0,0.d0, 0.d0,1.d0,0.d0,0.d0,0.d0,0.d0,1.d0,0.d0, 0.d0,0.d0,0.d0,1.d0/),(/4,4/)))     
  PRINT*
  PRINT*,'This doesn´t run ok'
  A=CMPLX(RESHAPE((/1.d0,0.d0,0.d0,0.d0, 0.d0,1.d0,0.d0,0.d0,0.d0,0.d0,1.d0,0.d0, 0.d0,0.d0,0.d0,1.d0/),(/4,4/))) 
  print*,A      
  
  end program
4 Jun 2015 5:08 #16419

Thanks. I have logged this also.

24 May 2016 11:39 #17510

The MATMUL bug has now been fixed for the next release.

24 May 2016 1:01 #17511

Using CMPLX on a RESHAPEd REAL array does not work at the moment. Pending a fix you could write...

COMPLEX A(4,4) 
A=RESHAPE((/1.0,..../),(/4,4/))

That is, remove the call to CMPLX and allow the type conversion to take place across the assignment.

12 Mar 2019 10:01 #23345

The two bugs illustrated in AntonioGJerez's code have been fixed for the next release of FTN95.

Please login to reply.