stdlib-js/stdlib

[RFC]: Add C implementations to base special math functions (tracking issue)

kgryte opened this issue ยท 32 comments

Description

This RFC proposes adding C implementations to all base special math functions. The purpose of this issue is to serve as a tracking issue for adding C implementations.

Packages

  • abs
  • abs2
  • abs2f
  • absf
  • acos
  • acosf
  • acosd
  • acosdf
  • acosh
  • acoshf
  • acot
  • acotf
  • acotd
  • acotdf
  • acoth
  • acothf
  • acovercos
  • acovercosf
  • acoversin
  • acoversinf
  • acsc
  • acscf
  • acscd
  • acscdf
  • acsch
  • acschf
  • ahavercos
  • ahavercosf
  • ahaversin
  • ahaversinf
  • asec
  • asecf
  • asecd
  • asecdf
  • asech
  • asechf
  • asin
  • asinf
  • asind
  • asindf
  • asinf
  • asinh
  • asinhf
  • atan
  • atanf
  • atan2
  • atan2f
  • atand
  • atandf
  • atanh
  • atanhf
  • avercos
  • avercosf
  • aversin
  • aversinf
  • bernoulli
  • bernoullif
  • besselj0
  • besselj0f
  • besselj1
  • besselj1f
  • bessely0
  • bessely0f
  • bessely1
  • bessely1f
  • beta
  • betaf
  • betainc
  • betaincf
  • betaincinv
  • betaincinvf
  • betaln
  • betalnf
  • binet
  • binetf
  • binomcoef
  • binomcoeff
  • binomcoefln
  • binomcoeflnf
  • boxcox
  • boxcoxf
  • boxcox1p
  • boxcox1pf
  • boxcox1pinv
  • boxcox1pinvf
  • boxcoxinv
  • boxcoxinvf
  • cabs
  • cabs2
  • cabs2f
  • cabsf
  • cbrt
  • cbrtf
  • cceil
  • cceilf
  • cceiln
  • cceilnf
  • ccis
  • ccisf
  • ceil
  • ceil10
  • ceil10f
  • ceil2
  • ceil2f
  • ceilb
  • ceilbf
  • ceilf
  • ceiln
  • ceilnf
  • ceilsd
  • ceilsdf
  • cexp
  • cexpf
  • cflipsign
  • cflipsignf
  • cfloor
  • cfloorf
  • cfloorn
  • cfloornf
  • cidentity
  • cidentityf
  • cinv
  • cinvf
  • clamp
  • clampf
  • copysign
  • copysignf
  • cos
  • cosf
  • cosd
  • cosdf
  • cosh
  • coshf
  • cosm1
  • cosm1f
  • cospi
  • cospif
  • cot
  • cotf
  • cotd
  • cotdf
  • coth
  • cothf
  • covercos
  • covercosf
  • coversin
  • coversinf
  • cphase
  • cphasef
  • cpolar
  • cpolarf
  • cround
  • croundf
  • croundn
  • croundnf
  • csc
  • cscf
  • cscd
  • cscdf
  • csch
  • cschf
  • csignum
  • csignumf
  • deg2rad
  • deg2radf
  • digamma
  • digammaf
  • dirac-delta
  • dirac-deltaf
  • dirichlet-eta
  • dirichlet-etaf
  • ellipe
  • ellipef
  • ellipj
  • ellipjf
  • ellipk
  • ellipkf
  • erf
  • erff
  • erfc
  • erfcf
  • erfcinv
  • erfcinvf
  • erfcx
  • erfcxf
  • erfinv
  • erfinvf
  • exp
  • expf
  • exp10
  • exp10f
  • exp2
  • exp2f
  • expit
  • expitf
  • expm1
  • expm1f
  • expm1rel
  • expm1relf
  • factorial
  • factorialf
  • factorial2
  • factorial2f
  • factorialln
  • factoriallnf
  • falling-factorial
  • falling-factorialf
  • fast/*
  • fibonacci
  • fibonaccif
  • fibonacci-index
  • fibonacci-indexf
  • flipsign
  • flipsignf
  • floor
  • floor10
  • floor10f
  • floor2
  • floor2f
  • floorb
  • floorbf
  • floorf
  • floorn
  • floornf
  • floorsd
  • floorsdf
  • fmod
  • fmodf
  • fresnel
  • fresnelf
  • fresnelc
  • fresnelcf
  • fresnels
  • fresnelsf
  • frexp
  • frexpf
  • gamma
  • gammaf
  • gamma-delta-ratio
  • gamma-delta-ratiof
  • gamma-lanczos-sum
  • gamma-lanczos-sumf
  • gamma-lanczos-sum-expg-scaled
  • gamma-lanczos-sum-expg-scaledf
  • gamma1pm1
  • gamma1pm1f
  • gammainc
  • gammaincf
  • gammaincinv
  • gammaincinvf
  • gammaln
  • gammalnf
  • gammasgn
  • gammasgnf
  • gcd
  • gcdf
  • hacovercos
  • hacovercosf
  • hacoversin
  • hacoversinf
  • havercos
  • havercosf
  • haversin
  • haversinf
  • heaviside
  • heavisidef
  • hypot
  • hypotf
  • identity
  • identityf
  • inv
  • invf
  • kernel-betainc
  • kernel-betaincf
  • kernel-betaincinv
  • kernel-betaincinvf
  • kernel-cos
  • kernel-cosf
  • kernel-sin
  • kernel-sinf
  • kernel-tan
  • kernel-tanf
  • kronecker-delta
  • kronecker-deltaf
  • labs
  • lcm
  • lcmf
  • ldexp
  • ldexpf
  • ln
  • lnf
  • log
  • logf
  • log10
  • log10f
  • log1mexp
  • log1mexpf
  • log1p
  • log1pf
  • log1pexp
  • log1pexpf
  • log1pmx
  • log1pmxf
  • log2
  • log2f
  • logaddexp
  • logaddexpf
  • logit
  • logitf
  • lucas
  • lucasf
  • max
  • maxf
  • maxabs
  • maxabsf
  • maxabsn
  • maxn
  • min
  • minf
  • minabs
  • minabsf
  • minabsn
  • minmax
  • minmaxf
  • minmaxabs
  • minmaxabsf
  • minmaxabsn
  • minmaxn
  • minn
  • modf
  • modff
  • nanmax
  • nanmaxf
  • nanmin
  • nanminf
  • negafibonacci
  • negafibonaccif
  • negalucas
  • negalucasf
  • nonfibonacci
  • nonfibonaccif
  • pdiff
  • pdifff
  • polygamma
  • polygammaf
  • pow
  • powf
  • powm1
  • powm1f
  • rad2deg
  • rad2degf
  • ramp
  • rampf
  • rcbrt
  • rcbrtf
  • rempio2
  • rempio2f
  • riemann-zeta
  • riemann-zetaf
  • rising-factorial
  • rising-factorialf
  • round
  • roundf
  • round10
  • round10f
  • round2
  • round2f
  • roundb
  • roundbf
  • roundn
  • roundnf
  • roundsd
  • roundsdf
  • rsqrt
  • rsqrtf
  • sec
  • secd
  • secdf
  • secf
  • sici
  • sicif
  • signum
  • signumf
  • sin
  • sinf
  • sinc
  • sincf
  • sincos
  • sincosd
  • sincosdf
  • sincosf
  • sincospi
  • sincospif
  • sinh
  • sinhf
  • sinpi
  • sinpif
  • spence
  • spencef
  • sqrt
  • sqrt1pm1
  • sqrt1pm1f
  • sqrtf
  • sqrtpi
  • sqrtpif
  • tan
  • tanf
  • tand
  • tandf
  • tanh
  • tanhf
  • tribonacci
  • tribonaccif
  • trigamma
  • trigammaf
  • trunc
  • trunc10
  • trunc10f
  • trunc2
  • trunc2f
  • truncb
  • truncbf
  • truncf
  • truncn
  • truncnf
  • truncsd
  • truncsdf
  • vercos
  • vercosf
  • versin
  • versinf
  • wrap
  • wrapf
  • xlog1py
  • xlog1pyf
  • xlogy
  • xlogyf

Related Issues

None.

Questions

No.

Other

No.

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.

@kgryte I would like to work on this.

@Pratik772846 I suggest picking one of the associated RFCs for updating a single package. This is a tracking issue.

@Pranavchiku As you've been managing a number of the RFCs and PRs, would you mind updating the OP to match the current state of implementations?

I am not sure if this can be closed now, reopening this.

@Pranavchiku Yeah, I think GitHub unfortunately auto-closes it when we have a PR where the opening comment includes "Fixes #649" or something of the sort. Thanks for opening again!

But I see that I accidentally included "Closes #649" in the merge commit message. Will avoid and see whether that solves it going forward.

No worries, we can open it anytime so that is fine. Updated tracker to latest main.

Small script, not sure if it traps all cases. There can be false negatives but no false positives.

set -ex

# iterate over all folder in <.../math/base/special/*>
for d in <path>; do
  # if the folder is a directory
  if [ -d "$d" ]; then
	# get the name of the folder
	folder=$(basename $d)
	# check if it has `manifest.json` file
	if [ -f "$d/manifest.json" ]; then
		# if it has `manifest.json` file, then open it as j_, lookup js_[confs][dependencies] and see if it has "@stdlib/math/base/napi/unary"
		# if it has "@stdlib/math/base/napi/unary" then add it to the `names.md`
		jq -r '.jsdoc.confs.dependencies["@stdlib/math/base/napi/unary"]' $d/manifest.json
		if [ $? -eq 0 ]; then
			echo "- [x] $folder" >> names.md
		else
			echo "- [ ] $folder" >> names.md
		fi
	else
		echo "- [ ] $folder" >> names.md
	fi
  fi
done

@Planeshifter You should always check the PR OP to ensure it properly links to issues and does not auto-close tracking issues. I often correct contributor PR OPs as they commonly include errors, including linking to incorrect issues or closing tracking issues.

Updated as per latest develop

kgryte commented

@gunjjoshi Would you mind updating the tracking issue with completed APIs? I believe rempio2, csc, and maybe others are finished.

kgryte commented

Would also be good to add relevant single-precision variants which have been, or still need to be, completed.

Yes @kgryte, I'll do that. But as this issue wasn't opened by me, I am unable to modify or edit this. Should I make a comment consisting of a list of the completed ones, and modifying that each time?

@kgryte The C implementations of the following functions have been done. They can be marked as completed now.

  • cos
  • cot
  • coversin
  • csc
  • exp2
  • fast
  • fibonacci-index
  • lcm
  • log10
  • negafibonacci
  • rempio2
  • round
  • sin
  • spence
  • tan

@gunjjoshi Marked as completed. ๐Ÿš€

kgryte commented

I updated the issue to include missing single-precision variants.

The following single-precision variants can also be marked as completed.

  • acosf
  • acotf
  • acscf
  • acscdf
  • asecdf
  • asecf
  • asindf
  • atanf
  • lnf
  • rad2degf
  • rcbrtf
kgryte commented

@gunjjoshi Updated!

kgryte commented

@gunjjoshi Looks like the tracking issue is missing nanmin and nanmax. There may be others which are missing.

@gunjjoshi Looks like the tracking issue is missing nanmin and nanmax. There may be others which are missing.

Added nanmin, nanmax and sec, along with their single-precision equivalents.

@Planeshifter It seems that this issue got closed automatically due to the Resolves #649 in #3076.

@gunjjoshi Is this issue still open to work on ?

@gunjjoshi Is this issue still open to work on ?

Yes, feel free to work on any of the packages which are unchecked, from the list.

@anandkaranubc Would you be willing to update the tracking issue list and check off those packages which have already been added/completed? Seems like it could be out-of-date atm, and we've been getting some duplicate PRs for existing functionality.

Iโ€™d like to work on some of the tasks mentioned here. Can someone guide me on how to get started? like to know:
Where should I add the C implementations?
existing implementations I can refer to?
What important details should I keep in mind while working on this task?
Any other guidance would also be helpful.

To be unchecked:

  • cabs2f
  • cabsf
  • cceilf
  • cflipsignf
  • cidentityf

To be checked:

  • atandf
  • ceilsd
  • cfloorf
  • cosm1
  • croundf
  • falling-factorial
  • negalucasf
  • negafibonaccif
  • riemann-zeta
  • xlogyf

To be modified (if "really" necessary):

  • kernel-sinf -> kernel-sindf
  • kernel-cosf -> kernel-cosdf
  • kernel-tanf -> kernel-tandf

To be updated:

  • rempio2f (removing the ?)

To be added:

  • sindf
  • cosdf
  • tandf
  • cscdf
  • secdf
  • cotdf
  • sincosdf

cc: @kgryte

Can someone guide me on how to get started?

@Girish-Garg, it would be a good idea to review the merged PRs for the packages that have already been checked above to get a good understanding. All of them (preferably the recent ones) serve as equally good reference PRs. Once you have a clear idea, you can start working on new implementations, (ideally) beginning with some standalone packages. You can get an initial understanding from the "Implementation Blueprint" in this issue.

Also, be mindful to avoid creating duplicate PRs for packages that already have open PRs.

Hi,
I would like to work on some of the tasks mentioned above.
Will be starting with ceil10f to start with.
Any guidance would be helpful

@kgryte @anandkaranubc i was working on kernel-sinf js and c implementation and came across that all test cases of c is skipping

Image

To troubleshoot, I added some try-catch blocks to check if native.js is being properly imported. I discovered that the issue lies with addon.js, which is failing to import addon.node. The problem seems to be caused by the #include "stdlib/math/base/napi/binary.h" in addon.c, which is not being imported properly and is throwing an error.

How should I proceed to resolve this issue?

Will be starting with ceil10f to start with.

ceil10f likely requires powf and log10f to be implemented first. Be careful about not choosing the implementations that are dependent on unimplemented functions.

How should I proceed to resolve this issue?

Could we sync about this in the Gitter channel? Just tag me there in your message.