stan-dev / stan-dev/math

tensor product

Open
#543 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature good first issue new function
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Summary:

From @betanalpha
C_{ij} = sum{m, n = 1}^{N} A_{imn} B_{jmn}

Description:

In Stan code:

matrix tensor_product(matrix[] A, matrix[] B) {
  matrix[size(A), size(B)] C;
  for (j in 1:J)
    for (i in 1:I)
      c[i, j] = sum(A[i] .* B[j]);
  return c;
}

with calling:

matrix[M, N] A[I];
matrix[M, N] B[J];
matrix[I, J] C = tensor_product(A, B);

We could write analytic derivatives for sum(matrix .* matrix) to cut down on memory usage. I don't know if we can piggyback on any of the Eigen tensor operations to make it more efficient. Lots of memory blocking issues here in how to do that sum and elementwise product efficiently.

Current Version:

v2.15.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository files, tests, or entry points. Start by locating the Stan tensor_product pattern and the relevant Eigen or automatic-differentiation operations; done would require an agreed implementation with analytic derivatives plus evidence that memory use and performance improve.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.