Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cross Product #457

Open
Open
Labels
ideaProposition of an idea and opening an issue to discuss it topic: mathematicslinear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ...
@St-Maxwell

Description

Hello, I tried to implement cross_product function as a component of linalg module. And a brief description is presented below. If we can have an agreement on the interface of cross_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


Then has a determinant form:

API

interface
 function cross_product(a, b) result(c)
 real, intent(in) :: a(:)
 real, intent(in) :: b(:)
 real :: c(3)
 end function
end interface

error stop when the size of a or b is not equal to 3.

Discussion

I think the vectors a and b should be passed as assumed-shape array. There is no need to explicitly define a and b 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 of cross_product function, where error_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaProposition of an idea and opening an issue to discuss it topic: mathematicslinear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /