Skip to content

Pretty print ndarrays when displayed as a return value in the stdlib REPL #368

Open
@kgryte

Description

@kgryte

Checklist

Please ensure the following tasks are completed before filing a bug report.

  • Read and understood the Code of Conduct.
  • 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.

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:

<ndarray>[ <contents> ]

or something like what is generated by ndarray#toString().

Actual Results

What are the actual results?

The following are the actual results:

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working.REPLIssue or pull request specific to the project REPL.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions