Skip to content

Commit 15bd08f

Browse files
testing Eigen/xtensor/numpy inter-op (WIP) (#6)
* add Eigen * make it compile * fix * add packaging * pocketpy prime is slower, 3.7s vs. 2.5s * 1. Mobile line numbers fix: - Changed .line-numbers from fixed width: 50px to min-width: 36px — narrower on small screens, still grows if needed - Reduced padding from 10px 8px 10px 5px to 10px 6px 10px 4px to save horizontal space - Removed the problematic height: 100% (now set dynamically by JS to match editor) 2. Textarea auto-resize: - Removed hardcoded min-height: 400px from both .editor-container and #editor - Added max-height: 90vh on .editor-container to cap the overall height - New autoResizeEditor() function calculates height based on line count: - Minimum: 3 lines (~79px) - Maximum: 60% of viewport height - When content exceeds max, the editor scrolls with line numbers synced - Removed the MutationObserver (unnecessary — input event + initial call covers all cases) - Auto-resize triggers on input and window resize This way, if the code is short (e.g. 5 lines), the editor will be compact and the output area below will be visible. If the code is long, it caps at 90vh with scrolling. * 编译通过,运行正常。现在走的是完整的 Eigen-pybind11-numpy 链路: - pybind11/eigen.h 做 Eigen::Ref<> / Eigen::Vector3d 和 numpy array 的 seamless 自动转换 - LineSegment 构造函数直接接收 Eigen::Vector3d,pybind11 自动从 numpy 转换 - rdp / rdp_mask 用 Eigen::Ref<const RowVectors> 直接零拷贝引用 numpy 数据 * test rdp * fix --------- Co-authored-by: tang zhixiong <zhixiong.tang@momenta.ai>
1 parent d601fb7 commit 15bd08f

File tree

13 files changed

+94445
-42
lines changed

13 files changed

+94445
-42
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ set(PK_BUILD_MODULE_LZ4 ON)
4747
set(PK_BUILD_STATIC_LIB ON)
4848
add_subdirectory(pocketpy ${CMAKE_CURRENT_BINARY_DIR}/__pocketpy__)
4949

50-
include_directories(SYSTEM pocketpy/include include)
50+
include_directories(SYSTEM include)
5151

5252
# Control xtensor warnings (OFF by default)
5353
option(SHOW_XTENSOR_WARNINGS "Show warnings from xtensor" OFF)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clean:
1212

1313
PYTHON ?= python3
1414
build:
15-
$(PYTHON) -m pip install scikit_build_core pyproject_metadata pathspec pybind11
15+
$(PYTHON) -m pip install scikit_build_core pyproject_metadata pathspec 'pybind11>=2.12,<3'
1616
CMAKE_BUILD_PARALLEL_LEVEL=$(NUM_JOB) $(PYTHON) -m pip install --no-build-isolation -Ceditable.rebuild=true -Cbuild-dir=build -ve.
1717
python_install:
1818
$(PYTHON) -m pip install . --verbose

docs/index.html

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
.editor-container {
1717
display: flex;
1818
width: 100%;
19-
min-height: 400px;
2019
background-color: #282a36;
2120
border: 1px solid #444;
2221
border-radius: 6px;
2322
position: relative;
23+
max-height: 90vh;
24+
overflow: hidden;
2425
}
2526
.line-numbers {
26-
width: 50px;
27-
padding: 10px 8px 10px 5px;
27+
min-width: 36px;
28+
padding: 10px 6px 10px 4px;
2829
background-color: #1e1e1e;
2930
color: #858585;
3031
text-align: right;
@@ -33,15 +34,12 @@
3334
line-height: 1.4;
3435
border-right: 1px solid #444;
3536
user-select: none;
36-
overflow-y: hidden;
37-
overflow-x: hidden;
38-
height: 100%;
37+
overflow: hidden;
3938
box-sizing: border-box;
4039
white-space: pre;
4140
}
4241
#editor {
4342
flex: 1;
44-
min-height: 400px;
4543
background-color: #282a36;
4644
color: #f8f8f2;
4745
border: none;
@@ -52,6 +50,7 @@
5250
tab-size: 4;
5351
resize: none;
5452
outline: none;
53+
overflow-y: auto;
5554
}
5655
#run-btn {
5756
margin-top: 8px;
@@ -126,49 +125,47 @@ <h1>pocket-numpy</h1>
126125
document.getElementById('line-numbers').textContent = lineNumbers;
127126
}
128127

128+
// Auto-resize editor: min 3 lines, max 60vh
129+
function autoResizeEditor() {
130+
var lineHeight = 14 * 1.4; // font-size * line-height
131+
var padding = 20; // top + bottom padding
132+
var lineCount = editorEl.value.split('\n').length;
133+
var minLines = 3;
134+
var maxPx = window.innerHeight * 0.6;
135+
var desiredHeight = Math.max(lineCount, minLines) * lineHeight + padding;
136+
var finalHeight = Math.min(desiredHeight, maxPx);
137+
editorEl.style.height = finalHeight + 'px';
138+
var lineNumEl = document.getElementById('line-numbers');
139+
lineNumEl.style.height = finalHeight + 'px';
140+
// If content overflows, enable scroll sync
141+
if (desiredHeight > maxPx) {
142+
editorEl.style.overflowY = 'auto';
143+
lineNumEl.style.overflowY = 'hidden';
144+
} else {
145+
editorEl.style.overflowY = 'hidden';
146+
lineNumEl.style.overflowY = 'hidden';
147+
}
148+
}
149+
129150
// Update line numbers on input and scroll
130151
editorEl.addEventListener('input', function() {
131152
updateLineNumbers();
132-
syncLineNumbersHeight();
153+
autoResizeEditor();
133154
});
134-
155+
135156
editorEl.addEventListener('scroll', function() {
136157
document.getElementById('line-numbers').scrollTop = this.scrollTop;
137158
});
138159

139-
// Ensure line numbers height matches editor height
140-
function syncLineNumbersHeight() {
141-
var editorHeight = editorEl.scrollHeight;
142-
document.getElementById('line-numbers').style.height = editorHeight + 'px';
143-
}
144-
145-
// Initial line numbers and height sync
160+
// Initial line numbers and auto-resize
146161
updateLineNumbers();
147-
syncLineNumbersHeight();
162+
autoResizeEditor();
148163

149-
// Sync height on window resize
164+
// Re-calc on window resize
150165
window.addEventListener('resize', function() {
151-
setTimeout(syncLineNumbersHeight, 100);
152-
});
153-
154-
// Monitor editor changes for better synchronization
155-
var observer = new MutationObserver(function() {
156-
setTimeout(function() {
157-
updateLineNumbers();
158-
syncLineNumbersHeight();
159-
}, 10);
166+
setTimeout(autoResizeEditor, 100);
160167
});
161168

162-
// Observe changes to editor
163-
if (window.MutationObserver) {
164-
observer.observe(editorEl, {
165-
attributes: true,
166-
childList: true,
167-
characterData: true,
168-
subtree: true
169-
});
170-
}
171-
172169
function runCode() {
173170
if (!ready) return;
174171
outputEl.textContent = '';

0 commit comments

Comments
 (0)