- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a problem with user defined type-bound generic operators. The issue occurs when i use dotted string as an operator in UDTs. Here there is an example,
[fortran]
! 10/11/2012
module module_precision
integer, parameter :: sp = kind(1.0e0)
integer, parameter :: dp = kind(1.0d0)
end module module_precision
!====================================================================================
! 10/13/2012
module module_vector
use module_precision,only: wp => dp
implicit none
!====================================================================================
type,abstract :: type_vector_base
real(wp) :: x=0._wp
real(wp) :: y=0._wp
contains
procedure(interface_vector_vector_scalar_real_operator) ,deferred,private :: vector_dot_product
generic :: operator(.dp.)=>vector_dot_product
end type type_vector_base
!------------------------------------------------------------------------------------
type,extends(type_vector_base) :: type_vector_2d
contains
procedure,private :: vector_dot_product =>vector_dot_product_2d
end type type_vector_2d
!====================================================================================
abstract interface
function interface_vector_vector_scalar_real_operator(vector1,vector2) result(scalar_result)
import :: type_vector_base,wp
class(type_vector_base),intent(in) :: vector1
class(type_vector_base),intent(in) :: vector2
real(wp) :: scalar_result
end function interface_vector_vector_scalar_real_operator
!---------------------------------------
end interface
!====================================================================================
contains
!====================================================================================
function vector_dot_product_2d(vector1,vector2) result(scalar_result)
class(type_vector_2d) ,intent(in) :: vector1
class(type_vector_base),intent(in) :: vector2
real(wp):: scalar_result
! body
scalar_result=vector1%x*vector2%x+vector1%y*vector2%y
end function vector_dot_product_2d
!====================================================================================
end module module_vector
!====================================================================================
program test_dot_product
use module_vector
type(type_vector_2d) ::normal1,normal2
real(wp) :: res
res = normal1 .dp. normal2
end
[/fortran]
And the output is
------ Build started: Project: test mkl, Configuration: Debug|x64 ------
Compiling with Intel(R) Visual Fortran Compiler XE 13.0.1.119 [Intel(R) 64]...
test dp.f90
C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90(51): error #6866: Dotted string neither a defined operator nor a structure component [DP]
C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90(49): remark #7712: This variable has not been used. [NORMAL1]
C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90(49): remark #7712: This variable has not been used. [NORMAL2]
compilation aborted for C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\test dp.f90 (code 1)
Build log written to "file://C:\Users\Arash\University Activites\Thesis\test mkl\test mkl\x64\Debug\BuildLog.htm"
test mkl - 2 error(s), 0 warning(s)
---------------------- Done ----------------------
Any idea?
Best regards, Arash.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nothing jumps out at me as a problem in your code - I will investigate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have escalated this to development as issue DPD200240115 and will let you know what we find.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what happens if you...
module module_precision
integer, parameter :: sp = kind(1.0e0)
integer, parameter :: wasdp = kind(1.0d0)
end module module_precision
module module_vector
use module_precision,only: wp => wasdp
...
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That doesn't change anything - that was the first thing I tried.
If the operator is defined in the extended type, it works, but it should work the way it is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was also thinking along the same lines as Jim i.e., some conflict between the "dp" kind parameter and ".dp." operator.
If that's not an issue, then could it be that the vector_dot_product procedure associated with the ".dp." public operator should also be public instead of private?
Arash R., have you tried some other operator other than a dotted string? If not, can you try that out? Say the simple asterisk (*) which actually would make the code easier to read. Separately, your vector_dot_product_2d function specifies the class type_vector_2d for vector1 but type_vector_base for vector2 - is this intended? If yes, care to explain why? Your test program is inconsistent with the function specification, not that this has anything to do with your operator issue.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The arguments for the procedures are as required by the Fortran standard in this context. Removing PRIVATE doesn't change the beahvior.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I expect this bug to be fixed in Update 3 (end of March).
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page