-
Notifications
You must be signed in to change notification settings - Fork 9
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
Rich mime type rendering #10
Comments
nelson does not support exactly same overloading than Octave. It is something that I would like to change before 1.0. Currently, overloading is based on filename in nelson where is based on pathname for octave or matlab I attached a basic example to show how works overloading for double type for octave and nelson. extract zip, addpath and assign double or disp double variable in octave or nelson. octave, matlab or nelson allow to overload 'disp' and 'display' functions as matlab. For nelson part, we can use a macro or define a c++ builtin to access easier to raw values. We can certainly share a common part of code to format data and others stuffs. :) |
The part that could be common is the way in which the rich rendering of a "pure" Octave/Nelson/Matlab object can be defined. def _repr_mimebundle_(self, **kwargs):
return {
'text/plain': repr(self),
} The returned value is not JSON but nested Python dicts and lists which are trivially converted to JSON. If both xeus-nelson and xeus-octave agree which Octave/Nelson function has to be implemented and return a struct function bundle = _jupyter_repr_(obj)
bundle = struct(
"text/plain", tostring(obj)
)
end Then xeus-nelson and xeus-octave would both consume the resulting struct in their own way to convert it to JSON for the frontend. |
Hi all (developer of xeus-octave here), thank you for involving me, I definitely think this is a useful topic to discuss and standardise! Current approach in xeus-octaveAt the moment in This is easy, quite intuitive, very versatile and integrated. However is not standardised nor documented, so prone to breakages and arbitrary interpretations, and a bit hacky. Pros and cons of @SylvainCorlay proposalI actually really like the approach proposed here and thought about it in the past. The main reason I did not go for it from the beginning is that there is no way to display rich output on statements without semicolon, automatically, as octave by defaults invokes only the There are two cons as of now that I can identify:
The pros:
Other points
|
We could serialize the types, but the deserialization has to use a convention to convert the non-finite elements and it will have a cost. examples: A = [1, NaN, 2; Inf, 3, -Inf];
st = jupyter_repr(A);
jsonencode(st) ans =
'{"class":"double","dimensions":[2,3],"issparse":false,"isreal":true,"r":[1,"Inf","NaN",3,2,"-Inf"],"im":[]}' A = sparse(eye(3, 3) + i);
st = jupyter_repr(A);
jsonencode(st) ans =
'{"class":"double","dimensions":[3,3],"issparse":true,"isreal":false,"I":[1,2,3,1,2,3,1,2,3],"J":[1,1,1,2,2,2,3,3,3],"RV":[1,0,0,0,1,0,0,0,1],"IMV":[1,1,1,1,1,1,1,1,1]}' it is not optimal but it can works ugly jupyter_repr.m ;) |
A major next step for xeus-nelson to be really compelling would be to enable rich mime type rendering.
It would be interesting if the way to specify a representation for a custom type for xeus-nelson and xeus-octave was the same. (Presumably making use of it would require an explicit call to
disp
while xeus-nelson could tie deeper in the nelson AST to automatically display the last value of a cell like IPython.cc @JohanMabille @Hind-M @rapgenic @Nelson-numerical-software.
The text was updated successfully, but these errors were encountered: