Skip to content

astrozot/SLEEFMath.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SLEEFMath

Build Status Coverage

This package provides two main functionalities:

  • a macro @sleefmath that works similarly to @fastmath: it transform an mathematical expression into a faster version based on the SLEEFPirates;

  • a set of differentiation rules based on ChainRules and also working with ForwardDiff.

How it works

A call to @sleefmath expr generates a transformed version of the expression, which calls functions that may violate strict IEEE semantics and use the SLEEFPirates package. This allows the compiler to use SIMD instructions and other optimizations that would not be possible with strict IEEE semantics.

This macro is effective only within loops or broadcasted expressions. If used in for loops, it often requires the use of @simd ivdep for loops and @inbounds to be effective. For broadcasted expressions, it is often convenient to use @.. from the FastBroadcast package.

Examples

julia> @sleefmath exp(sin(3.0))
1.151562836514535

julia> xs = rand(10^6); ys = similar(xs);

julia> using BenchmarkTools, FastBroadcast

julia> @btime @.. $ys = @sleefmath exp(sin($xs));
  3.708 ms (0 allocations: 0 bytes)

julia> @btime @.. $ys = exp(sin($xs));
  10.265 ms (0 allocations: 0 bytes)

julia> @btime (@simd ivdep for n  eachindex($xs); @inbounds $ys[n] = @sleefmath exp(sin($xs[n])); end);
  3.719 ms (0 allocations: 0 bytes)

Limitation

The current version of this package implements real-valued mathematical functions based on the SLEEF library. Future versions will also implement functions with complex arguments.

About

A public interface to the SLEEFPirates library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages