Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix a function positional argument to a callable. Stand-in replacement for `Base.Fix`.

License

NotificationsYou must be signed in to change notification settings

JuliaFunctional/FixFunctionArgument.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusPackage versionPackage dependenciesCoveragePkgEvalAqua

A Julia package for fixing a given positional argument to a given callable. Intended as a straight improvement upon and stand-in replacement forBase.Fix (includingBase.Fix1 andBase.Fix2).

Provided functionality

The package exports the following bindings:

  • Fix

  • Fix1

  • Fix2

The usage is the same as with theBase counterparts.

Motivation

Base.Fix fails to be a zero-cost abstraction when the provided callable or the provided argument to fix are types.Fix handles that case as expected:

julia>sizeof(Base.Fix1(convert, Float32))8julia>using FixFunctionArgumentjulia>sizeof(Fix1(convert, Float32))0

Here is a more concrete, albeit artificial, example of a performance difference betweenFix andBase.Fix.

# calls `f` eight timesfunctioniterated_function_8(f::Func, x)where {Func}    f= f f    f= f f    f= f ff(x)end# like `identity`, but should not inline@noinlinefunctionidentity_noinline(x)    xend# only does calling, for benchmarking call/stack overheadfunctionidentity_noinline_iterated(x)iterated_function_8(identity_noinline, x)endusing BenchmarkTools, FixFunctionArgumentx=Fix1(convert, Float32)y= Base.Fix1(convert, Float32)@btimeidentity_noinline_iterated($x)#  1.292 ns (0 allocations: 0 bytes)@btimeidentity_noinline_iterated($y)# 16.222 ns (1 allocation: 16 bytes)@code_typedidentity_noinline_iterated(x)# shows that the entire call gets constant folded away

Interpretation: forFix, unlike forBase.Fix, theidentity_noinline_iterated call has zero cost, because the entire call gets constant folded away.

About

Fix a function positional argument to a callable. Stand-in replacement for `Base.Fix`.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp