|
|
Up |
|
|
  |
Author: Pierre AsselinPierre Asselin Date: Oct 4, 2006 09:47
Sorry for the long post, I don't know how to make it more concise.
Let me see if I can explain what I'm trying to do... Consider a
subroutine to minimize a function of n variables,
subroutine minimize(Func, x)
real, dimension(:), intent(inout):: x
interface
real function Func(z)
real, dimension(:), intent(in):: z
end function Func
end interface
!
! Start calling Func(x) and use some clever
! algorithm to modify x until Func(x)
! reaches a minimum
end subroutine minimize
So I write the body of the minimizer, place it in a module, and
people can USE the module and minimize their own objective functions,
X= initial_guess
call minimize(my_function, X)
|
| Show full article (4.76Kb) |
|
| | 7 Comments |
|
  |
Author: beliavskybeliavsky Date: Oct 4, 2006 10:47
Pierre Asselin wrote:
> Sorry for the long post, I don't know how to make it more concise.
> Let me see if I can explain what I'm trying to do... Consider a
> subroutine to minimize a function of n variables,
>
> subroutine minimize(Func, x)
> real, dimension(:), intent(inout):: x
> interface
> real function Func(z)
> real, dimension(:), intent(in):: z
> end function Func
> end interface
> !
> ! Start calling Func(x) and use some clever
> ! algorithm to modify x until Func(x)
> ! reaches a minimum
> end subroutine minimize
>
> So I write the body of the minimizer, place it in a module, and
> people can USE the module and minimize their own objective functions, ...
|
| Show full article (2.39Kb) |
|
| | no comments |
|
  |
Author: nospamnospam Date: Oct 4, 2006 10:56
Pierre Asselin wrote:
...
> The trouble is, user functions invariably depends on other things
> (mathematical parameters) besides the argument X...
[good summary of the usual suggestions elided]
> Unfortunately Fortran 95 has no concept of a block
> of arbitrary data. The CLASS(*) of Fortran 2003 seems to fit the
> bill, but I don't have an F03 compiler.
There are multiple ways to do in in f2003. The class stuff is one.
Another way is "hidden" in the C interop stuff, although it has good
application completely unrelated to C. That way is to use the C_PTR
type. It is a C void pointer and can point to pretty much anything. (I
think it might be limitted to interoperable types, but that's not a
horrible restriction).
Part of why I mention it is that this might even be a candidate for f95,
in either of 2 ways.
1. Some f95 compilers implement the C interop stuff as an f95 extension.
Thus you might have that now.
|
| Show full article (3.11Kb) |
| no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Oct 5, 2006 01:39
> So "minimize" only need to know about one new assumed-shape
> integer array. The user function and the caller of
> "minimize" conspire as follows to exchange information:
>
> type fred
> ! arbitrarily complex data structures go here
> end type fred
>
> type(fred) my_params
>
> ...
>
> call minimize( &
> my_function, x, &
> TRANSFER(my_params, (/1/)) &
> )
>
> ...
>
> real function my_function(x, context) ...
|
| Show full article (2.33Kb) |
| no comments |
|
  |
Author: Jugoslav DujicJugoslav Dujic Date: Oct 5, 2006 01:50
Pierre Asselin wrote:
| Sorry for the long post, I don't know how to make it more concise.
| Let me see if I can explain what I'm trying to do... Consider a
| subroutine to minimize a function of n variables,
I suggested enhancing the language with a special type called
e.g. WHATEVER which would be type-compatible with pretty much
anything for the purpose of such data passing (kind of equivalent
of C void*). Obviously, that is pretty much emulable in F2003 with
derived classes, but there are no compilers...
Apart from the clumsy TRANSFER solution, I will offer a
non-standard one, but hopefully fairly portable. It relies on the
following assumptions:
* the varying-type argument you need is always a scalar
* compiler's internal representation of any scalar POINTER is
the same (and equivalent to C void*).
|
| Show full article (1.26Kb) |
| 1 Comment |
|
  |
Author: Jugoslav DujicJugoslav Dujic Date: Oct 5, 2006 02:05
Jugoslav Dujic wrote:
| Pierre Asselin wrote:
|| Sorry for the long post, I don't know how to make it more concise.
|| Let me see if I can explain what I'm trying to do... Consider a
|| subroutine to minimize a function of n variables,
|
| I suggested enhancing the language with a special type called
...
Sorry, the previous post went erroneously off my "Drafts" folder;
it (obviously) isn't completed. Later...
--
Jugoslav
___________
www.xeffort.com
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
|
| |
| no comments |
|
  |
Author: Pierre AsselinPierre Asselin Date: Oct 7, 2006 17:01
I'll reply to my own post and consolidate here.
Richard Maine wrote:
>> Pierre Asselin wrote:
>> 1) Is "A= TRANSFER( TRANSFER(A, (/1/)), A)" garanteed to be
>> a no-op ?
> The standard says yes. But I personally think that this "yes" overlooks
> some issues and is an internal inconsistency (aka error) in the
> standard.
Hmf. The standard says yes in two specific cases, neither of which
is the one I need. Otherwise, the standard says that the TRANSFER(...)
above has the same physical representation as A, whatever that
means. The term "physical representation" isn't defined anywhere
and the promise seems hollow to me.
>> 4) Can I TRANSFER and unpack a user-defined type with allocatable
>> components ?
|
| Show full article (4.69Kb) |
| 1 Comment |
|
  |
|
|
  |
Author: nospamnospam Date: Oct 7, 2006 21:13
> I'll reply to my own post and consolidate here.
>
> Richard Maine wrote:
>>> Pierre Asselin wrote:
>>> 4) Can I TRANSFER and unpack a user-defined type with allocatable...
|
| Show full article (1.55Kb) |
| no comments |
|
|