A length-1 R vector is marshalled as a scalar, so a one-dimensional IVP is rejected with a message about the wrong argument

Open
#382 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
r, rust
Domain
api, backend

Research direction

Start by tracing how the R binding marshals numeric vectors in value_new, then inspect argument validation for num_ode_dopri5 and num_ode_rk4_adaptive. The report shows array(x, dim = 1) works around the issue, but leaves open whether to preserve length-1 vectors as tensors or correct argument error reporting; confirm the intended behavior with maintainers before changing it.

Written by the indexing model from the issue text.

Description

area/api-bindings good first issue help wanted kind/contract severity/4-minor

A length-1 numeric vector becomes a scalar Float, so a one-dimensional IVP — the commonest ODE there is — cannot be passed to num_ode_dopri5 / num_ode_rk4_adaptive in the obvious way, and the error blames an argument the caller never wrote.

library(rssn)
s <- rssn_session()
value_kind(value_new(c(1), s))              # "float"
value_kind(value_new(array(1, dim = 1), s)) # "tensor"
value_kind(value_new(c(1, 2), s))           # "tensor"

f <- function(t, y) -y

call_value("num_ode_dopri5", 0, 1, c(1), 1e-6, 1e-6, 0.1, 1000, f, session = s)
# Error: argument 2 has type Float, expected Tensor<Float[E], 1>

call_value("num_ode_dopri5", 0, 1, array(1, dim = 1), 1e-6, 1e-6, 0.1, 1000, f, session = s)
# ok

c(1, 2) is a tensor and c(1) is a scalar, so the kind depends only on the length, and the message then refers to "argument 2" — which is t1, the second parameter, while the offending value is the third (y0). A caller reading the error looks at the wrong argument.

The same applies to every operator whose signature asks for Tensor<_, 1>: c(1) is silently demoted before the call is made, so the shape check can never see it.

Expected: keep a length-1 vector a rank-1 tensor (a dim attribute already does it, so the information is there when the caller supplies it), or report the mismatch against the argument that actually failed, naming the workaround (array(x, dim = 1)).

rssn 0.3.0, R 4.6.2 binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
14h 51m
Merged PRs (30d)
29

Getting set up

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.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.