-
Notifications
You must be signed in to change notification settings - Fork 26
[RFC]: implement base special mathematical functions in JavaScript and C #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @anandkaranubc for your proposal! A few questions:
|
I would add that these variadic functions should not have C implementations at all. Less of a need in C. |
Thanks @Planeshifter for the review and feedback!
Sorry for the confusion. Ideally, I would like to complete both
I completely agree and had a similar concern. If it's about implementing That said, right now I’m trying to slowly pick off all the low-hanging fruits so I can gain more leverage on the tougher ones. cc: @kgryte |
Thanks for writing this proposal, @anandkaranubc! Some comments:
|
Thanks for the review and feedback, @gunjjoshi!
I have inlined them now.
Oops! Thanks, I’ve fixed the wording now.
Context: While implementing functions for the Bradford distribution, I noticed some significant differences between the results of our So, I believe the main goal here isn't necessarily to fix something, but rather to do a spot check to confirm whether there have been any changes in the latest upstream implementations. |
Final submission PDF: Proposal_GSOC_KaranAnand.pdf |
This project aims to implement and enhance base special mathematical functions in JavaScript and C for stdlib. The goal is to complete missing C implementations for existing double-precision packages, develop new single-precision versions, and ensure consistency, accuracy, and IEEE 754 compliance. Deliverables include multiple function implementations, added constants, improved test coverage, and documentation updates. These enhancements will make math functions in stdlib faster, more robust, and more accessible for developers across platforms. This is the proposal summary I intend to write, for the official GSOC proposal. Open to feedback if it needs improvement. |
That works for me. |
Seems great. Best of luck, @anandkaranubc! |
Full name
Karan Anand
University status
Yes
University name
University of British Columbia
University program
Combined Major in Computer Science & Math
Expected graduation
April, 2026
Short biography
I'm a third-year undergraduate student at the University of British Columbia (UBC) Vancouver, pursuing a combined major in Computer Science and Math. I’ve always been fascinated by the intersection of math and computing, particularly in numerical computing, machine learning and high-performance software. Academically, I’ve maintained strong performance and have been recognized on the Dean’s Honour List.
Currently, I work as an Undergraduate Teaching Assistant for Differential Calculus, Data Structures and Algorithms (in C++), and Introduction to Data Science (in R), helping students with everything from integrals to debugging pointers. I’m also an Undergraduate Research Assistant, comparing model performance in Julia and JAX to see which one wins the speed race.
Previously, I’ve interned at Seaspan and UBC Emerging Media Lab, working on 3D visualizations and AR/VR. I love hackathons, both as a participant and as a mentor/judge, and have had the chance to work on some exciting projects along the way.
I have experience with JavaScript, Typescript, Julia, R, C/C++ and Python, and I’ve used React for web development and JAX for numerical computing and machine learning. In short, I enjoy building cool things, solving tricky problems, and occasionally breaking my own code just to fix it again.
Timezone
Pacific Daylight Time
Contact details
email: [email protected], github:anandkaranubc
Platform
Mac
Editor
I prefer VS Code because it's lightweight, fast, and has great support for multiple languages. The built-in Git integration, debugging tools, extensions support and customization options make it my go-to editor.
Programming experience
I have experience in programming and have worked on various projects using different technologies. Here are a few:
These projects helped me learn about web development, AI/ML, and blockchain technology.
JavaScript experience
I have worked with JavaScript on several projects, including web apps using React, Three.js, and Node.js. I enjoy how flexible and dynamic JavaScript is. It makes building interactive web applications fun!
My favourite feature? Asynchronous programming (async/await) because it makes handling API calls and background tasks smooth. (Bye-bye to callback hell!)
My least favourite? Type coercion. While it's a powerful feature that allows for flexible and dynamic code, it sometimes tries too hard to interpret intent, leading to unexpected behaviour.
That said, the good definitely outweighs the bad.
Node.js experience
I have experience using Node.js to build backend services and APIs with Express.js, handling authentication and database connections. In one project, I built a backend system to fetch and process geolocation location data from a web service, managing large datasets efficiently. I have also worked on designing REST API endpoints for querying and filtering data.
C/Fortran experience
I have experience with C, thanks to a CS course I took, working on memory management, data structures, and system programming. I’ve implemented a simulated cache system with optimized replacement policies and worked on Y86 assembly for pipeline optimization.
I don’t have experience with Fortran, but if needed, I’m ready to learn!
Interest in stdlib
What interests me about stdlib is its commitment to building a fast and comprehensive standard library for numerical and scientific computing on the web, which has been clearly reflected in office hours and the Gitter channel. I've always wondered, while looking at different mathematical equations and algorithms, how they are actually implemented. stdlib provided me with the stage where I could see and experience that firsthand, and on top of it, even contribute to it by learning the same level of attention to detail. I really enjoy the textbook-to-practical experience it offers.
One feature I find particularly exciting is its extensive collection of mathematical and statistical functions, along with its vast support for Pseudo-Random Number Generators (PRNGs). It's great to have access to well-designed utilities all in one place.
On a personal level, stdlib holds a special place for me as my first ever open-source contribution. The journey, coupled with the support I received, made the experience deeply meaningful and continues to inspire me to contribute more in the future.
Version control
Yes
Contributions to stdlib
Merged Work
I have contributed multiple pull requests that have been successfully merged. My main work has been in the
math/base/special
andstats/base/dists
namespaces (Merged PRs). This includes:stats/base/dists
like #5280, #5326, etc.Open Work
I currently have open pull requests that are under review, mostly focused on mathematical functions, distributions, and overall improvements to stdlib. Open PRs
Issues Created
I have also raised issues related to improvements, missing features, and potential fixes. Created Issues
Code Reviews
I have helped in code reviews, largely revolving around refactoring random value generation in
stats/base/dists
andmath/base/special
. Linkstdlib showcase
Link
Goals
The goal of this project is to complete as much work as possible in the following areas, focusing on
math/base/special
.Main Goals:
Supporting Goals:
cabs2f
,cabsf
, etc.maxabn
,maxn
, etc., if needed.ln
,log1p
, etc.).math/base/special
as much as possible.math/base/special
andstats/base/dists
(if time permits).The main and supporting goals can be worked on independently and in parallel, with the main goals taking priority.
Why this project?
I've always been curious about how mathematical functions and algorithms are actually implemented under the hood. stdlib gave me the perfect opportunity to not just see it but also contribute to it. When I implemented the Gaussian hypergeometric function (
hyp2f1
), it was an eye-opening experience, seeing a function go from a textbook definition to a real, working implementation felt incredibly rewarding. (I promise this is the last time I’m bringing uphyp2f1
… maybe)What excites me most about this project is the chance to bridge the gap between theory and practice. stdlib provides a structured way to write efficient, well-tested numerical computing tools, and I love how it balances performance with clarity. The idea of working on JS/C implementations, precision improvements, and IEEE compliance excites me because it's about making math more accurate, reliable, and accessible for developers.
Also, there’s something really satisfying about writing code that makes scientific computing smoother for everyone. It’s like leaving behind a well-optimized trail for others to follow, and I would be proud to be a tiny part of that!
Qualifications
I have worked on
math/base/special
in stdlib, gaining experience in implementing and improving mathematical functions. I have taken courses in numerical computing, algorithms, software construction, and hardware systems, giving me a strong academic background and the ability to handle complex problems in this project. As a teaching/research assistant, I have improved my debugging, documentation, and problem-solving skills, making me well-prepared to contribute to stdlib.Prior art
This area has been widely explored, not just in stdlib's math/base/special, which is being tracked in issue #649, but also in other well-known libraries like Cephes, FreeBSD, Go, Boost, Julia, FDlibm, SLATEC, and SciPy. For single-precision implementations, we can also take inspiration from stdlib's existing double-precision versions in
math/base/special
.There are also important standards like IEEE 754 for floating-point arithmetic and C99 for complex-number arithmetic, which provide useful guidelines for accuracy and implementation.
Commitment
I am all in for this project as a full-time, large project (350-hour commitment) and don’t mind going beyond that if needed. I will dedicate ~30-40 hours per week to the project, focusing on steady progress, well-structured/sized pull requests, and thorough testing.
I am also holding a summer research position, but I have successfully managed multiple responsibilities in the past, including academics, teaching/research assistant roles, and open-source contributions. This experience ensures that my GSoC commitment will not be impacted. I am confident in my ability to effectively balance both, keeping my work for stdlib at an equal priority with my research.
Before GSoC officially begins, I will focus on refining my proposal, improving my showcase, and putting out some first standalone implementations that align with the project goals. After GSoC, I plan to stay involved, addressing any remaining work and contributing further.
Schedule
Implementation Blueprint
To guide the implementation process, I will reference and follow the structured progression outlined in two key documents:
These documents will be used throughout the project (and potentially beyond) to ensure a clear and efficient development roadmap.
Additional Notes
For double precision functions, the focus will be on adding missing C implementations to existing JS implementations. To ensure consistency and correctness, I will follow the same upstream implementations that were used in the JS versions.
For single precision functions, the plan is to mostly refer to the same upstream library that was used for its respective double precision counterpart. If a direct upstream implementation is not available, I will scout implementations from well-established libraries, including:
Thanks to Gunj's GSoC Issue #41 for providing key insights and references.
Schedule
Assuming a 12 week schedule,
Community Bonding Period (Weeks C1-C3):
Weeks C1:
This period will be dedicated to connecting with mentors and fellow participants to better understand the overall goals and expectations for GSOC. These discussions will also serve as an eye-opener for me, helping to identify areas of the codebase that I am less familiar with and expanding my knowledge.
Since I have some familiarity with the
math/base/special
module, I will start implementing after consulting with my mentors, to ensure I am heading in the right direction. I will begin with low-hanging fruits by adding the missing addons for complex number packages:cabs2f
cabsf
cceilf
cflipsignf
cidentityf
Additionally, I will implement the missing C implementations for the following functions:
bessely1
ellipj
heaviside
heavisidef
minmax
Week C2:
I will focus on implementing the C versions of:
gammainc
gammaincinv
Week C3:
The focus will be on:
kernel-betainc
betainc
(potentially)Development Period:
Week 1,2: Completion of Phase 0
Week 3: Completion of Phase 1
Week 4, 5: Nearing the complete wrap-up of Phase 2
Week 6: (midterm) Completion of Phase 2, with time to gather feedback on my development process, contributions, and areas for improvement.
Week 7, 8: Completion of Phase 3
Week 9, 10: Completion of Phase 4
Week 11, 12: Nearing the complete wrap-up of Phase 5 (potentially)
Final Week: Submission of the project, along with the creation of an issue/tracking issue to document any remaining tasks. Lastly, gathering feedback and guidance to reflect on the development process and plan for future improvements.
Notes:
kernel-betainc
,betainc
,kernel-betaincinv
, andbetaincinv
. If these need to be prioritized, it will likely require adjustments to the timeline and a reallocation of focus, probably pushing Phase 5 to a later stage.Thank you for taking the time to read my proposal!
Related issues
Of course, they are everywhere:
GSoC Issue #34
Issue #649
Issue #365
Checklist
[RFC]:
and succinctly describes your proposal.The text was updated successfully, but these errors were encountered: