Skip to content

DOC: how to find your way in the code, for instance the dot function #15567

Open

Description

@tachukao

I've been trying to figure out how np.dot works for multi-dimensional arrays (dimension > 2). I couldn't quite locate where this is specified in the source code. I assume this is done in C with multiple calls to cblas gemm. Any pointers will be most appreciated!

Activity

  1. mattip commented on Feb 14, 2020

    @mattip
    Member

    Assuming you are using a BLAS backend, it is

    array_dot -> PyArray_MatrixProduct2, which creates an iterator and calls dot. That function is actually part of the descr, and is found as dot = PyArray_DESCR(out_buf)->f->dotfunc on line 993. So what is dotfunc ? It is a PyArray_DotFunc, defined by templated code in https://github.com/numpy/numpy/blob/v1.18.1/numpy/core/src/multiarray/arraytypes.c.src. For float32, float64, the function used is this one, for complex this one, and for ints the non-blas one. Then those functions are assigned to the correct slot in some more templated code. I have not show all of the variants in arraytypes.c.src, but this should get you started.

    While not truly an issue per-se, I think we should discuss adding a "how to browse the code" section to the documentation with this as an example, so I am changing the title and marking this "Documentation"

  2. changed the title [-]dot function source code[/-] [+]DOC: how to find your way in the code, for instance the dot function[/+] on Feb 14, 2020
  3. Kai-Striega commented on Jan 26, 2023

    @Kai-Striega
    Member

    Maybe the documentation should also link to this video?

  4. tachukao commented on Jan 26, 2023

    @tachukao
    Author

    thanks @mattip and @Kai-Striega for the pointers!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions