Pretty print ndarrays when displayed as a return value in the stdlib REPL
- Vorherrschende Sprache
- JavaScript
- Sterne
- 6k
- Forks
- 1.3k
- Ø Merge
- 1 T. 3 Std.
- Gemergte PRs (30 T.)
- 611
Beschreibung
## Checklist
> Please ensure the following tasks are completed before filing a bug report.
- [x] Read and understood the [Code of Conduct][code-of-conduct].
- [x] Searched for existing issues and pull requests.
## Description
> Description of the issue.
Encountered the issue when creating an `ndarray` in the REPL. Currently, when displaying an `ndarray` as a return value, the following is shown:
```
In [1]: var x = array( [[1,1],[1,1]])
Out[1]: ndarray {
_byteLength: 32,
_buffer: Float64Array(4) [ 1, 1, 1, 1 ],
_length: 4,
_offset: 0,
_order: 'row-major',
_shape: [ 2, 2 ],
_strides: [ 2, 1 ],
_iterationOrder: 1,
_flags: { ROW_MAJOR_CONTIGUOUS: true, COLUMN_MAJOR_CONTIGUOUS: false }
}
```
Preferably, the REPL would not display "private" (underscore prefixed properties). These properties seem to be inherited from the base `ndarray` class. They are not set as non-enumerable properties for performance reasons.
When setting as non-enumerable in the non-"base" `ndarray` constructor, there was a non-negligible performance impact which subsequently affected downstream usage of `ndarrays`. This was documented [here](https://github.com/stdlib-js/stdlib/commit/1b9aea2de4575f5e1207f5ab375a264e807fe3e5).
In general, return value representation should be standardized across the stdlib REPL. Possibly by implementing a custom `inspect` method which is invoked prior to displaying the return value in the REPL, similar to the built-in Node.js REPL.
## Related Issues
> Does this issue have any related issues?
No.
## Questions
> Any questions for reviewers?
No.
## Other
> Any other information relevant to this issue? This may include screenshots, references, stack traces, sample output, and/or implementation notes.
#### Reproduction
> What steps are required to reproduce the unexpected output?
In order to reproduce this bug, do the following:
- launch the stdlib REPL
- create an ndarray and do not silence output
#### Expected Results
> What are the expected results?
The following results are expected:
```text
[ ]
```
or something like what is generated by `ndarray#toString()`.
#### Actual Results
> What are the actual results?
The following are the actual results:
```text
(see above)
```
#### Environments
> What environments are affected (e.g., `Node v0.4.x`, `Chrome`, `IE 11`)? If Node.js, include the `npm` version, operating system, and any other potentially relevant platform information.
The following environments are affected:
- all environments which might care about property enumerability.
[code-of-conduct]: https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.