Skip to content

Conversation

@jumerckx
Copy link
Collaborator

@jumerckx jumerckx commented Dec 3, 2025

An operation is defined for each function listed here: https://specialfunctions.juliamath.org/stable/functions_overview/#Bessel-Functions

For now, all function arguments are mapped onto operation operands, as opposed to constant attributes.
Some of the variants are special cases of more general ones:

besselj(nu,z)   # Bessel function of the first kind of order nu at z

besselj0(z)     # besselj(0,z)
besselj1(z)     # besselj(1,z)

@jumerckx jumerckx self-assigned this Dec 3, 2025
);
}

def BesselJ0 : EnzymeXLA_Op<"special.besselj0", [Pure, SameOperandsAndResultType, Elementwise]> {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason for us to specialize j0 here? If we have the same implementation it lowers into anyways, no need for now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I imagined those might have custom approximation lowerings but I'm not sure about that. Will see if I can find something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for one, mpfr seems to have separate implementations for the different bessels https://github.com/JuliaMath/SpecialFunctions.jl/blob/1743a8b7ac1565213e87de418765c594720929b6/src/bessel.jl#L682C1-L709C4
I'm not sure yet what the lowering in stablehlo would look like.

Copy link
Member

Choose a reason for hiding this comment

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

in julia right now it just looks like they call custom c library functinos [which we can't do ourselves here anyways]

Copy link
Member

Choose a reason for hiding this comment

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

id probably just start with the more general one, and add the specialized one if we find a lowering for it later

@jumerckx
Copy link
Collaborator Author

jumerckx commented Dec 3, 2025

SameOperandsAndResultType I'll have to change this as some arguments can be complex.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

EnzymeJAX Benchmarks

Benchmark suite Current: 45e39ae Previous: 7054610 Ratio
scatter_sum / JaX / cpu / Primal 0.000004400375899967912 s 0.000004342221499973675 s 1.01
scatter_sum / JaXPipe / cpu / Primal 0.000004491189899999881 s 0.000004368584500025463 s 1.03
scatter_sum / JaX / tpu / Primal 0.0001501408806 s 0.0001383197025999 s 1.09
scatter_sum / JaXPipe / tpu / Primal 0.0001491218746999 s 0.0001325478068999 s 1.13

This comment was automatically generated by workflow using github-action-benchmark.

The order can be a different type (for example an integer)
@jumerckx
Copy link
Collaborator Author

jumerckx commented Dec 4, 2025

The ops seem to be working, I've got them hooked up to Reactant locally.

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.

3 participants