Skip to content

feat: add iter/cartesian-product #1399

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

Closed
wants to merge 8 commits into from
Closed

feat: add iter/cartesian-product #1399

wants to merge 8 commits into from

Conversation

shubhexists
Copy link
Contributor

Resolves #1335

Description

What is the purpose of this pull request?

This pull request:

  • Adds implementation of iterator equivalent of cartesian-product

Related Issues

Does this pull request have any related issues?

#1335

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

TESTS

Screenshot from 2024-02-27 19-25-03

BENCHMARKS
Screenshot from 2024-02-27 19-24-47

EXAMPLES
Screenshot from 2024-02-27 19-24-36

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@maniksharma17
Copy link
Contributor

maniksharma17 commented Feb 27, 2024

@shubhexists hey, I cannot seem to run benchmark.js on the feat I added (@stdlib/utils/parse-ndjson) #1394 . I'm getting this error. I have debug in node_modules as well as in package.json. Did you encounter it too?
image

@shubhexists shubhexists mentioned this pull request Feb 27, 2024
1 task
@steff456 steff456 self-requested a review February 28, 2024 18:20
Copy link
Contributor

@steff456 steff456 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shubhexists, thanks for opening this PR!

I left some comments in this PR to get this approved, please let me know if you have any further question about any of them :)

iterCartesianProduct( [ 1, 2, 3 ], [ 4, 5, 6 ] ); // $ExpectType Iterator
}

// The compiler throws an error if the function is provided a first argument which is not array-like...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a case for string, boolean, null and undefined to both arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not resolved yet, I meant we need to add the case for these dtypes for the error cases rather than the correct case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not resolved

@shubhexists
Copy link
Contributor Author

shubhexists commented Feb 28, 2024

Hi @steff456 , my idea of using linspace and zeroTo was that the iterCartesianProduct function takes in an Array instead of an Iterator, as mentioned in the Issue.
Since, randu returns an Iterator object, I would eventually have to run a while loop to collect all it's values into an Array.

What are your opinions?

@shubhexists shubhexists requested a review from steff456 February 29, 2024 15:43
@Planeshifter Planeshifter changed the title feat: add @stdlib/iter/cartesian-product feat: add iter/cartesian-product Mar 3, 2024
@steff456
Copy link
Contributor

steff456 commented Mar 6, 2024

@shubhexists you are right, let's leave the examples with linspace

Copy link
Contributor

@steff456 steff456 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes @shubhexists, there are still a couple of tiny fixes before this PR is ready!

iterCartesianProduct( [ 1, 2, 3 ], [ 4, 5, 6 ] ); // $ExpectType Iterator
}

// The compiler throws an error if the function is provided a first argument which is not array-like...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not resolved yet, I meant we need to add the case for these dtypes for the error cases rather than the correct case

@steff456 steff456 added JavaScript Issue involves or relates to JavaScript. Needs Changes Pull request which needs changes before being merged. labels Mar 6, 2024
shubhexists and others added 3 commits March 7, 2024 01:44
Co-authored-by: Stephannie Jimenez Gacha <steff456@users.noreply.github.com>
Signed-off-by: Shubham <shubh622005@gmail.com>
@shubhexists
Copy link
Contributor Author

@steff456 Kindly have a look now

Copy link
Contributor

@steff456 steff456 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a minor change for this PR to be ready.

iterCartesianProduct( [ 1, 2, 3 ], [ 4, 5, 6 ] ); // $ExpectType Iterator
}

// The compiler throws an error if the function is provided a first argument which is not array-like...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not resolved

iterCartesianProduct( 2, [ 4, 5, 6 ] ); // $ExpectError
iterCartesianProduct( false, [ 4, 5, 6 ] ); // $ExpectError
iterCartesianProduct( true, [ 4, 5, 6 ] ); // $ExpectError
iterCartesianProduct( {}, [ 4, 5, 6 ] ); // $ExpectError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous comment meant to add cases where the first argument is string, boolean, null and undefined

Suggested change
iterCartesianProduct( {}, [ 4, 5, 6 ] ); // $ExpectError
iterCartesianProduct( {}, [ 4, 5, 6 ] ); // $ExpectError
iterCartesianProduct( 'a', [ 4, 5, 6 ] ); // $ExpectError
iterCartesianProduct( null, [ 4, 5, 6 ] ); // $ExpectError
iterCartesianProduct( undefined, [ 4, 5, 6 ] ); // $ExpectError

Please do the same for the other test cases.

@kgryte kgryte added Feature Issue or pull request for adding a new feature. Utilities Issue or pull request concerning general utilities. and removed JavaScript Issue involves or relates to JavaScript. labels Mar 20, 2024
@shubhexists shubhexists closed this by deleting the head repository Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. Utilities Issue or pull request concerning general utilities.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add @stdlib/iter/cartesian-product
4 participants