Matrix exponential of a `1×1` `JLSparseMatrixCSC` fails with scalar indexing both disabled and enabled

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
57/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
julia
领域
backend

调研方向

The reported stack traces point to src/host/sparse.jl:216 and, with scalar indexing disabled, src/host/indexing.jl:50. Start by reading those paths and the sparse matrix exponential dispatch for JLSparseMatrixCSC; reproduce with the provided 1×1 Float32 example under both scalar-indexing settings. Done when exp(a) returns approximately 1.868246 with scalar indexing disabled.

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

描述

Description

Calling exp(a) on a 1×1 Float32 sparse matrix fails on JLArrays under both scalar-indexing settings. With allowscalar(false), it raises a scalar-indexing error. With allowscalar(true), it reaches a missing constructor for JLSparseMatrixCSC{Float32, Int64}. CUDA returns the same matrix exponential in both runs.

Reproduction

Run the following script in a fresh Julia process with the packages listed below and a CUDA-capable GPU. The second iteration enables scalar indexing to expose the next failure.

using CUDA, JLArrays
using JLArrays: JLSparseMatrixCSC
using CUDA.cuSPARSE: CuSparseMatrixCSC
using SparseArrays: sparse
using GPUArrays: allowscalar

for enabled in (false, true)
    println("allowscalar(", enabled, "):")
    allowscalar(enabled)
    for (backend, array) in (("JLArrays", JLSparseMatrixCSC), ("CUDA", CuSparseMatrixCSC))
        try
            a = array(sparse(Float32[0.625]))
            result = exp(a)
            println(backend, ": ", Array(result))
        catch err
            println(backend, ": ", first(eachsplit(sprint(showerror, err), '\n')))
        end
    end
end

Observed output

allowscalar(false):
JLArrays: Scalar indexing is disallowed.
CUDA: Float32[1.8682458;;]

allowscalar(true):
JLArrays: MethodError: no method matching JLSparseMatrixCSC{Float32, Int64}(::SparseArrays.SparseMatrixCSC{Float32, Int64})
CUDA: Float32[1.8682458;;]

Expected behavior

For this 1×1 matrix, the only entry in the matrix exponential should be approximately 1.868246, the exponential of 0.625. I would expect the JLArrays sparse implementation to compute this value with scalar indexing disabled.

Additional context

Both input constructors succeeded under both settings. The resulting matrices had types JLSparseMatrixCSC{Float32, Int64} and CuSparseMatrixCSC{Float32, Int32}, each with size (1, 1).

Both JLArrays exceptions arose inside exp(a), before the copy to the host. In GPUArrays.jl 12.3.0, both stack traces point to src/host/sparse.jl:216. With scalar indexing disabled, the stack also includes getindex at src/host/indexing.jl:50. With it enabled, the exception identifies a host SparseMatrixCSC{Float32, Int64} as the argument to the missing constructor.

Environment

  • Julia 1.13.4 on Debian GNU/Linux 13 (x86_64, Docker)
  • GPUArrays.jl 12.3.0, JLArrays.jl 0.5.0, CUDA.jl 6.5.1
  • JLArrays CPU device: Intel Core i7-11700
  • CUDA device: NVIDIA GeForce RTX 4090, CUDA runtime 12.9.0, NVIDIA driver 595.99.02
主要语言
Julia
星标
462
派生
109
平均合并
4 天 11 小时
30 天内合并 PR
26

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

JuliaGPU/GPUArrays.jl 的其他 Issue

查看 JuliaGPU/GPUArrays.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 发到你的邮箱

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