stan-dev / stan-dev/math

Add vectorized variant for functions of complex variable, especially exp

Open
#3,138 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently, according to the guide https://mc-stan.org/docs/functions-reference/complex-valued_basic_functions.html it seems that basic arithmetic operators and pow are the only functions that accept complex vectors.

I am modelling some periodicities in data using Fourier series, and I find it the most compact (and computationally efficient) to express what I do in terms of complex numbers. However, it's not efficient to run a function over a matrix using a loop when there's autodiff.

The most striking case is the exp function, which is ubiquitous in complex analysis and I want to be able to run it elementwise over a vector or a matrix.

I figured out a possible workaround is to use pow(exp(1), z) which does work on vectorized z, but still I believe that exp is more fundamental than pow and it should be implemented, because the current state is confusing at best.

Of course then there are all the other functions which accept a real or complex scalar and accept vectorized real, but don't accept vectorized complex, which is inconsistent. This includes log and the trigonometric functions.

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 files or tests. Start with the complex-valued basic functions guide and the existing vectorized pow behavior, then trace how complex scalar functions interact with vector or matrix autodiff. Done should cover the requested vectorized exp behavior and clarify the broader consistency question for log and trigonometric functions.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.