Skip to content

feat: add protocol support to stats/base/range #5779

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

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from

Conversation

jalajk3004
Copy link
Contributor

Resolves #5679

Description

What is the purpose of this pull request?

This pull request:

  • Refactor and add protocol support

Related Issues

Does this pull request have any related issues?

This pull request:

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.

No.

Checklist

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


@stdlib-js/reviewers

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
---
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. Good First PR A pull request resolving a Good First Issue. labels Mar 4, 2025
@jalajk3004
Copy link
Contributor Author

@kgryte I have submitted a pull request addressing issue #5679, and I would love to contribute further to resolving this issue completely. I would appreciate your guidance on any necessary improvements or changes required to get this PR merged.

Please let me know how I can assist in the process. Looking forward to your feedback.

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: failed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: passed
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Mar 9, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/range $\color{red}309/313$
$\color{green}+98.72\%$
$\color{red}33/36$
$\color{green}+91.67\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{red}309/313$
$\color{green}+98.72\%$

The above coverage report was generated for the changes in this PR.

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
@kgryte kgryte changed the title RFC: refactor and add protocol support to stats/base/range feat: add protocol support to stats/base/range Mar 12, 2025
Comment on lines 130 to 132
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float64Array = require( '@stdlib/array/float64' );
var linspace = require( '@stdlib/array/base/linspace' );
Copy link
Member

Choose a reason for hiding this comment

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

Use @stdlib/random/array/discrete-uniform.

Comment on lines 138 to 139
x = linspace(-50, 50, 10);
x = x.map(round);
Copy link
Member

Choose a reason for hiding this comment

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

This will then become

Suggested change
x = linspace(-50, 50, 10);
x = x.map(round);
x = discreteUniform( 10, -50, 50, {
'dtype': 'float64'
});

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var linspace = require( '@stdlib/array/base/linspace' );
Copy link
Member

Choose a reason for hiding this comment

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

Use @stdlib/random/array/uniform, rather than linspace.

@@ -22,6 +22,7 @@

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var linspace = require( '@stdlib/array/linspace' );
Copy link
Member

Choose a reason for hiding this comment

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

Same comment.

@@ -1,92 +1,124 @@
{{alias}}( N, x, strideX )
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{{alias}}( N, x, strideX )
{{alias}}( N, x, strideX )

The `N` and stride parameters determine which elements in the strided
array are accessed at runtime.


Copy link
Member

Choose a reason for hiding this comment

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

Suggested change


Indexing is relative to the first index. To introduce an offset, use a typed
array view.
The `N` and stride parameters determine which elements in the strided
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look properly wrapped at 80 chars.

Parameters
----------

Copy link
Member

Choose a reason for hiding this comment

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

Why are you adding all these blank lines? Please remove and follow our REPL text style guide.


Returns
-------

Copy link
Member

Choose a reason for hiding this comment

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

Why?

// Standard Usage:
> var x = [ 1.0, -2.0, 2.0 ];
> {{alias}}( x.length, x, 1 )
4.0

// Using `N` and `stride` parameters:

Copy link
Member

Choose a reason for hiding this comment

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

You need to go through and remove all these stray lines. Please study other repl.txt files.

for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( (randu()*100.0) - 50.0 );
}
var x = linspace(-50, 50, 10);
Copy link
Member

Choose a reason for hiding this comment

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

This should be updated to match any future changes to the README.

return NaN;
}
if ( N === 1 || stride === 0 ) {
const v = get( x, 0 );
Copy link
Member

Choose a reason for hiding this comment

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

We use ES5. All of this ES6+ usage needs to be changed. Please study the conventions in other files.

* // returns 6.0
*/
function range( N, x, stride, offset ) {
function range( N, x, strideX, offsetX ) {
var obj = arraylike2object( x );
Copy link
Member

Choose a reason for hiding this comment

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

This is not what we want. Please study other implementations. Accessing directly in data is precisely what we want to avoid if x is an accessor array. That is the entire point of accessors.js.

@@ -21,7 +21,8 @@
// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
Copy link
Member

Choose a reason for hiding this comment

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

This is no longer used.


x = [ -3.0, -2.0, -1.0, 1.0, 2.0, 3.0 ];
v = range( x.length, toAccessorArray( x ), 1, 0 );
t.ok(isnan(v), 'returns expected value');
Copy link
Member

Choose a reason for hiding this comment

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

All these tests are obviously wrong. We shouldn't be returning NaN.


v = range( 4, toAccessorArray( x ), 2, 0 );

t.ok(isnan(v), 'returns expected value');
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Mar 12, 2025
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

Left an initial round of comments. The implementation is currently wrong and the tests obviously so. I suggest doing a close study of other packages which have accessor protocol support to better understand what is desired.

* See the License for the specific language governing permissions and
* limitations under the License.
*/
* @license Apache-2.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @license Apache-2.0
* @license Apache-2.0

@jalajk3004 Hey the license should not be tempered with here. Hence the CI error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @Neerajpathak07, Error is solved.
But I am still facing the problem with Repl
image

Copy link
Contributor

Choose a reason for hiding this comment

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

well that's because the expected and the returned values do not match. Check your implementation once again and do go through the repl.txt file to see if everything is in-line.

Signed-off-by: Athan <kgryte@gmail.com>
@kgryte kgryte removed the Needs Changes Pull request which needs changes before being merged. label Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First PR A pull request resolving a Good First Issue. Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: refactor and add protocol support to stats/base/range
4 participants