next up previous
Next: Tests Up: Implementation Previous: Supported F90 intrinsics

Limitations

As we can not implement the kind as an argument, required by AINT, ANINT, INT, NINT, their overloaded functions simply do not accept this argument. They can transform only to the default kinds defined by dpk and ik.

A very serious limitation stems from the lack in FORTRAN 90 of user-defined elemental functions. An expression like y = SIN(x) where y, x are conformable arrays, is accepted by FORTRAN 90 if the array elements are of a built-in type. Unfortunately, this does not hold for user-defined types. The multitude of definitions that must be added to AUTO_DERIV in order to provide a similar behavior for them, would make the code very complicated. The user is, therefore, required either to make explicit the loop or loops implied in his/her code or, a better solution, to enhance deriv_class by adding to it only the exact instance of the function needed. This normally means that the programmer should copy the function accepting scalars, rename it, change the type of the arguments to make them arrays of the required rank, and add the function name to the public interface provided by the module.

A similar problem arises for intrinsic functions accepting arrays (SUM, PRODUCT, MAXLOC/MINLOC, and MAXVAL/MINVAL). AUTO_DERIV overloads these functions to accept arrays of rank-1 only of TYPE (func) elements. If the user wishes to apply any of the above functions to arrays of different rank, he/she should add to the module the appropriate version of the function with the dimensions of the array arguments altered.

FORTRAN does not provide functions a mechanism to accept variable number of arguments. Therefore, the implementation of overloaded functions to MAX, MIN is inherently incomplete. The number of arguments must be fixed, while the not overloaded versions can have arbitrary. deriv_class provides MAX/MIN that accept two or three arguments. If the user needs a MAX/MIN with more, the appropriate instance has to be added and overload MAX/MIN by including its name to the relevant interface.

Note, that in the implementation of MAX, MIN and MAXVAL, MINVAL we use MAXLOC, MINLOC; finding only the maximum/minimum value does not suffice. As MAXLOC, MINLOC do not accept the optional argument DIM in FORTRAN 90, the four functions above can not be implemented efficiently to accept it either; We chose not to support the optional argument in them.

A serious mathematical problem arises in cases where we have discontinuity or when 0/0 is encountered; for example, in abs(x) at x = 0, or when the derivatives of $\sqrt{f(x)}$ at x = 0 are required and f(0) = f'(0) = 0. Care was taken when only the denominator in a fraction, equals to zero; this case is avoided, unless the user in the code performs an illegal operation (which would show up even without using deriv_class). But ``undefined'' situations as the above, may appear in ACOS, ASIN, ATAN2, SQRT. In such cases, 0/0 is arbitrarily resolved to 0; admittedly this is not correct. The user should not depend on AUTO_DERIV in these occasions. Note, that even computing by other means the analytic expressions for the derivatives would lead to this problem. In such a situation, usually, the user code needs rethinking.


next up previous
Next: Tests Up: Implementation Previous: Supported F90 intrinsics
Stavros Farantos
1999-12-11