failed Send inference with ndarray v0.17 and uom 0.38

未关闭
#1,617 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust
领域
data

调研方向

Reproduce the minimal example in src/main.rs with Rust 1.98.1, uom 0.38, and ndarray 0.17.2, then compare the result with ndarray 0.16. Read the reported rust-lang/rust issue #162558 alongside ndarray's async and Send-related behavior; done means identifying whether the regression belongs to ndarray or rustc and documenting or fixing the confirmed cause.

由索引模型根据 Issue 内容生成。

描述

I'm running into a compile error using an Array2uom::si::f64::Length from inside an async function.
Please note this did work with ndarray v0.16.

  • rust 1.98.1
  • uom v0.38
  • ndarray v0.17.2 (NOTE - v0.16 seems to work)

The problem can be isolated into the following minimal example, which I would expect to compile:

use uom::si::f64::Length;
use uom::ConstZero;
use ndarray::Array2;

fn assert_send<T: Send>(_t: T) {}

fn main() {
    assert_send(check());
}

async fn check() {
    let lengths: Array2<Length> = Array2::from_elem((2, 3), Length::ZERO);
    std::future::pending::<()>().await;
    println!("{}", lengths[(0, 0)].get::<uom::si::length::meter>());
}

This produces the following compiler error message:

error[E0308]: mismatched types
 --> src/main.rs:8:5
  |
8 |     assert_send(check());
  |     ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected struct `Quantity<..., ..., f64>`
             found struct `Quantity<..., ..., f64>`
note: the lifetime requirement is introduced here
 --> src/main.rs:5:19
  |
5 | fn assert_send<T: Send>(_t: T) {}
  |                   ^^^^

Since it is not clear to me if the problem is on the ndarray or the rustc side I also reported it to rust-lang/rust (#162558).
I have a workaround wrapping the Array2 into a newtype with a at(&self,usize,usize)->Length fn and using that to obtain Length quantities inside the async fn. This comes from a bigger project though (https://github.com/ODIN-fire/odin-rs) where such workarounds are clearly suboptimal since it is highly async.

主要语言
Rust
星标
4.3k
派生
391
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-ndarray/ndarray 的其他 Issue

查看 rust-ndarray/ndarray 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。