-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross Product #457
Comments
There is a blog-post by @jacobwilliams on this function: http://degenerateconic.com/old-school/ I would be happy to drop the assertion and simply document the size of the arguments should be 3. Since it is a low-level function that might be called hundreds of times I think we don't want an error check. |
@ivan-pi Thanks for sharing your idea. I agree that the assertion would lower the efficiency of |
Having a preprocessor warning block would be one way, but I really think the cross-product should be a pure function to benefit from compiler inlining. With the debug build in fpm or CMake we already have Do you have any suggestion for an interface to deal with the cross-product of a vector field, e.g. to solve the shallow water equations on a sphere:
Alternatively, I might decide to use a different memory layout:
|
I just wanted to add that requests for cross product have appeared previously on both comp.lang.fortran and StackExchange. |
Hello, I tried to implement
cross_product
function as a component oflinalg
module. And a brief description is presented below. If we can have an agreement on the interface ofcross_product
, I will create a pull request.Cross Product
Overview
Cross product is a binary operation on two vectors in
space, denoted by
. The result of
is a vector that is perpendicular to both
and
. Let
,
, and
being the orthonormal basis vectors in
space,
and
can be represented by the following expressions


has a determinant form:

Then
API
error stop
when thesize
ofa
orb
is not equal to 3.Discussion
I think the vectors
a
andb
should be passed as assumed-shape array. There is no need to explicitly definea
andb
as fixed-size array, i.e.real, intent(in) :: a(3), b(3)
. Compilers are not able to check whether the size is reasonable at compile-time since in many cases, allocatable arrays are used. Therefore, the assertion for array size is placed in the body ofcross_product
function, whereerror_stop
is called. As a result,cross_product
is no longer a pure function.Based on the above discussion and consideration of simplicity, I chose an analogous way to Julia to implement
cross_product
.Reference Implementations
The text was updated successfully, but these errors were encountered: