-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support buffers/DataView in props
This allows us to send numpy arrays efficiently. Before, a buffer (from the Python side) was transformed into a empty object, now it is a DataView object.
- Loading branch information
1 parent
b48b045
commit 4998292
Showing
3 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import numpy as np | ||
import playwright.sync_api | ||
from IPython.display import display | ||
|
||
import ipyreact | ||
|
||
code = """ | ||
import {Button} from '@mui/material'; | ||
import * as React from "react"; | ||
export default function({floatArrayDataView}) { | ||
const floatArray = new Float32Array(floatArrayDataView.buffer); | ||
console.log({floatArray, floatArrayDataView}); | ||
return <div>{`v:${floatArray[0]}`}</div> | ||
}; | ||
""" | ||
|
||
|
||
def test_material_ui(solara_test, assert_solara_snapshot, page_session: playwright.sync_api.Page): | ||
class SerializeTest(ipyreact.ReactWidget): | ||
_esm = code | ||
|
||
ar = np.array([42.0], dtype=np.float32) | ||
b = SerializeTest(props={"floatArrayDataView": memoryview(ar)}) | ||
display(b) | ||
|
||
page_session.locator("text=42").wait_for() |