Skip to content

Hermitian() wrapper missing a GPU compatible iterator #586

Closed

Description

@abussy

The following reproducer code fails with LoadError: Scalar indexing is disallowed.:

using CUDA
using LinearAlgebra

A = CuArray(ones(Float32, 5, 5))

# This works
any(isnan, Symmetric(A))

# This does not
any(isnan, Hermitian(A))

It seems that some underlying function call tries explicit element access with the Hermitian() wrapper, but not with Symmetric(). I am not 100% sure whether that issue belongs here or in LinearAlgebra.

I get this issue with Julia version 1.10.8 (LTS) and 1.11.3 (current stable).

Activity

  1. cpmores commented on Apr 6, 2025

    @cpmores

    Seems that the optimized function 'any' cannot resolve Hermitian{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}.

    'any' in mapreduce.jl looks like:

    Base.any(f::Function, A::AnyGPUArray) = mapreduce(f, |, A)

    But Hermitian or Symmetric is a struct including UP or Down, which cannot go into this optimized function.

    If you use the data instead of the whole struct, any will work properly.

    using CUDA
    using LinearAlgebra
    
    A = CuArray(ones(Float32, 5, 5))
    
    # This works
    S = Symmetric(A)
    println(any(isnan, S.data))
    
    # This works
    H = Hermitian(A)
    println(any(isnan, H.data))
    
    
    B = CuArray(fill(NaN, 5, 5))
    # This works
    SB = Symmetric(B)
    println(any(isnan, SB.data))
    
    # This works
    HB = Hermitian(B)
    println(any(isnan, HB.data))
  2. changed the issue type fromtoon Oct 19, 2026
  3. added
    arraysThe array abstraction: broadcasting, mapreduce, indexing, views, generic linear algebra.
    and removed on Oct 19, 2026
  4. maleadt commented on Oct 19, 2026

    @maleadt
    Member

    Works on current GPUArrays and CUDA.jl, with correct results for both uplos:

    A = CuArray(ones(Float32, 5, 5))
    any(isnan, Hermitian(A))  # false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraysThe array abstraction: broadcasting, mapreduce, indexing, views, generic linear algebra.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions