stan-dev / stan-dev/math

add is_even and is_odd here and to Stan

Open
#3,349 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I would rather write is_odd(n) than n % 2 == 1 or more obscure n % 2.. Same for is_even(n) vs. n % 2 == 0 or more obscurely !(n % 2).

This is about the simplest pair of functions to add because they don't need overloads for different scalar types and don't have derivatives.

It would be great if they could be vectorized over arrays of any shape to return an array of the same shape with 0/1 values based on whether each element is odd or not.

This should then be added to the Stan language and doc.

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

Start by locating the existing Stan Math function implementations and the Stan language documentation entry points. Add is_even and is_odd for scalars and array inputs, then verify that each returns same-shaped 0/1 results and that both functions are documented and available in Stan.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend, documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.