Skip to content

Einstein summation notation #376

Open
@brandongc

Description

@brandongc

NumPy has a convenient Einstein summation capability numpy.einsum. Any interest in an API which operated in a similar way? ie

program einstein_summation
  implicit none
  integer :: i,j,k,l
  real, dimension(3,4,5) :: A = reshape([(i, i=1,60,1)], [3,4,5])
  real, dimension(4,3,2) :: B = reshape([(i, i=1,24,1)], [4,3,2])
  real, dimension(5,2) :: C = 0.0

  ! proposed API
  !C = einsum("ijk, jil-> kl", A, B)

  ! instead of 
  do k=1,5
     do l=1,2
        do i=1,3
           do j=1,4
              C(k,l) = C(k,l) + A(i,j,k) * B(j,i,l)
           end do
        end do
     end do
  end do
end program einstein_summation

Optionals:

"optimize" optional argument from NumPy's API
i.e.

C = einsum("ijk, jil-> kl", A, B, optimize=.true.)

Comments:
High performance implementations could be realized with libraries such as cuTENSOR

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: algorithmssearching and sorting, merging, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions