Skip to content

Lookup: fill Eigen types with NaN - #3892

Merged
jl-wynen merged 2 commits into
mainfrom
lookup-vec-oob
Apr 28, 2026
Merged

jl-wynen merged 2 commits into
mainfrom
lookup-vec-oob

Conversation

@jl-wynen

Copy link
Copy Markdown
Member

Fixes #3860

Comment thread lib/dataset/bins.cpp
Variable fill = fill_value.value_or(zero_like(function.data()));
Variable fill =
fill_value
.or_else([&] { return std::optional{zero_like(function.data())}; })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this change does? I did not follow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an optimisation. The old code always constructed the default value zero_like(function.data())). The new code only does that when no value is provided. (Using C++23's or_else)

Comment thread tests/lookup_test.py Outdated
sc.testing.assert_identical(sc.lookup(da)(var), expected)


def test_histogram_default_fill_value_vector() -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test Matrix3d and Affine3d?
Is it easy to just parametrize?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I parametrized the test. But we don't even support transformations in lookup. That is not part of this PR, so should I remove the fill value support for Matrix3d and Affine3d again?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I remove the fill value support for Matrix3d and Affine3d again?

I don't mind either way

Comment thread tests/lookup_test.py
assert sc.identical(sc.lookup(da, mode='previous', fill_value=fill)(var), expected)


def test_previous_vector() -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems unrelated to the 0 vs nan behaviour, but increases test coverage, right?

Comment thread tests/lookup_test.py

var = sc.array(dims=['event'], values=[-1, 2])
expected = sc.empty(dims=['event'], shape=[2], dtype=dtype)
expected.values[...] = fill # sc.full does not work for vector3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc.full does not work for vector3

Should we open an issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jl-wynen
jl-wynen enabled auto-merge April 28, 2026 11:29
@jl-wynen
jl-wynen merged commit 749733d into main Apr 28, 2026
4 checks passed
@jl-wynen
jl-wynen deleted the lookup-vec-oob branch April 28, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lookup fills vectors with 0

2 participants