- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
<p>I am trying some new things with Beta 2016 (W8.1, cygwin) and have several things working, including submodules, PDTs, and DTIO !
<p>I have encountered a couple of bugs and ICEs, which I have submitted, but this is a question.
<p>I am trying to extend operator (+) and assignment (=) with a PDT. Each seems to work (sort of) but not together. How do I declare the result of the operator extension so that it is compatible with the arguments (other than literal array sizes)? Here is what I have so far (sorry, I have no clue how to format this thing). I am going to try the whole thing again with allocatables, but I think the simpler case should work ???
<pre>
$ ifort addmatrix.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0 Beta Build 20150326
Copyright (C) 1985-2015 Intel Corporation. All rights reserved.
addmatrix.f90(67): error #6197: An assignment of different structure types is invalid.
c = a + b
---------^
compilation aborted for addmatrix.f90 (code 1)
</pre>
<pre>
module matrix_mod
implicit none
private
integer, parameter, public :: single = kind(0.0)
integer, parameter, public :: double = kind(0.0d0)
type, public :: matrix(rows, cols, k)
integer, len :: rows, cols
integer, kind :: k
real(kind = k), dimension(rows, cols) :: values
end type matrix
interface operator (+)
procedure single_add_matrix !, double_add_matrix
end interface
interface assignment (=)
procedure single_assign_matrix
end interface
public :: operator (+)
public :: assignment (=)
contains
function single_add_matrix(x, y) result (rm)
type (matrix(*, *, single)), intent(in) :: x, y
type (matrix(x%rows, x%cols, single)) :: rm
! type (matrix(1000, 200, single)) :: rm
if (x%rows /= y%rows .or. x%cols /= y%cols) then
rm%values = -huge(x%values)
else
rm%values = x%values + y%values
end if
end function single_add_matrix
subroutine single_assign_matrix(v, e)
type (matrix(*, *, single)), intent(in) :: e
type (matrix(*, *, single)), intent(out) :: v
print*, "in assign"
if (all(shape(v%values) == shape(e%values))) then
v%values = e%values
else
v%values = -huge(e%values)
end if
end subroutine single_assign_matrix
end module matrix_mod
</pre>
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This might be still an open issue in Intel Fortran as mentioned in this thread: https://software.intel.com/pt-br/forums/topic/536542
To get the syntax highlighting, use the "Code" link to paste your code:
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page