-
Notifications
You must be signed in to change notification settings - Fork 640
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
feat(math): Add distribution functions. #2774
Conversation
math/distributions.ts
Outdated
n: number, | ||
options: RangeOptions = BASE_RANGE_OPTIONS, | ||
): number[] { | ||
if (typeof n !== "number" || n <= 0 || !Number.isInteger(n)) return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should throw TypeError instead of returning empty array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it throw a TypeError in the latest commit.
@retraigo Do you have any image about the scope of |
Finding math-related JS/TS code on the internet is a really tedious process. There are only a few math-related modules like mathjs out there. Having a standard, third-party-dependency-free math module for Deno would be great. It could support any math-related stuff that makes sense to do in JavaScript like,
But IMO it shouldn't contain math that operates on a large amount of data (like regression analysis, matrices, etc). Not because they're a bad feature, but they'd be making devs choose them over actually performant third-party modules that use native code. |
Co-authored-by: Yoshiya Hinosawa <[email protected]>
The CI is looking pretty red after the last set of changes. |
Deno.test({ | ||
name: "Negative, zero, non-integer value of n returns an empty array.", | ||
fn() { | ||
assertEquals(uniformRange(-10, { min: 1, max: 10 }).length, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this now should use assertThrows
to check it throws TypeError
@retraigo Thanks for many suggestions!
Is it like ndarrays in numpy? What does stricter version mean?
Can you elaborate? What is the use case of this?
This sounds like common needs for math calculation to me.
There's
I agree with this. We shouldn't compete with/re-invent something like tensorflow.js |
|
We discussed this PR internally, and we are worried about the scope of |
I'm going to close this per #2774 (comment), but please do create a module on |
This PR adds two functions under the
math
module.uniformRange
generates an array of numbers uniformly distributed between a range in ascending order.normalDistribution
generates an array of numbers normally distributed around a mean in random order.Tests have been written under the
distributions_test.ts
file.