Skip to content

Bug: normalize fails with TypeError (boolean check in __normalize!) #316

Description

@bdrhill

Problem

LinearAlgebra.normalize fails with TypeError due to a boolean check in __normalize!.

MWE

using SparseConnectivityTracer
using LinearAlgebra

detector = TracerSparsityDetector()

# This fails
jacobian_sparsity(x -> normalize(x), [3.0, 4.0], detector)
# TypeError: non-boolean (GradientTracer...) used in boolean context

# Manual implementation works
jacobian_sparsity(x -> x / norm(x), [3.0, 4.0], detector)
# OK: nnz=4

Root cause

LinearAlgebra.__normalize! at generic.jl:2010 uses a boolean check (likely iszero on the norm).

Workaround

Use manual implementation x / norm(x) or TracerLocalSparsityDetector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent 🤖Agentically generated issuearrayFeatures regarding array overloadsnew overloadsA new method on tracers is required by a user.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions