Skip to content

Commit bf08f6e

Browse files
committed
Make x param in example of tutorial a bit more useful
1 parent 77cb855 commit bf08f6e

1 file changed

Lines changed: 64 additions & 64 deletions

File tree

doc/getting_started/tutorials/03.lazyarray-udf-kernels.ipynb

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
},
2323
{
2424
"cell_type": "code",
25-
"execution_count": 1,
2625
"id": "4743791e5436aa04",
2726
"metadata": {
2827
"ExecuteTime": {
29-
"end_time": "2026-02-16T05:32:35.309530Z",
30-
"start_time": "2026-02-16T05:32:35.071164Z"
28+
"end_time": "2026-02-16T05:46:57.649941Z",
29+
"start_time": "2026-02-16T05:46:57.358347Z"
3130
}
3231
},
33-
"outputs": [],
3432
"source": [
3533
"import numpy as np\n",
3634
"\n",
3735
"import blosc2"
38-
]
36+
],
37+
"outputs": [],
38+
"execution_count": 1
3939
},
4040
{
4141
"cell_type": "markdown",
@@ -49,79 +49,65 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 2,
5352
"id": "8926a0c21237fef3",
5453
"metadata": {
5554
"ExecuteTime": {
56-
"end_time": "2026-02-16T05:32:35.322622Z",
57-
"start_time": "2026-02-16T05:32:35.311059Z"
55+
"end_time": "2026-02-16T05:46:57.677192Z",
56+
"start_time": "2026-02-16T05:46:57.660322Z"
5857
}
5958
},
60-
"outputs": [],
6159
"source": [
6260
"@blosc2.dsl_kernel\n",
6361
"def kernel_index_ramp(x):\n",
6462
" # _i* and _n* are reserved DSL index/shape symbols, so disable linter warnings\n",
65-
" return _i0 * _n1 + _i1 # noqa: F821"
66-
]
63+
" return x + _i0 * _n1 + _i1 # noqa: F821"
64+
],
65+
"outputs": [],
66+
"execution_count": 2
6767
},
6868
{
6969
"cell_type": "code",
70-
"execution_count": 3,
7170
"id": "fbe9cb59a4515c9c",
7271
"metadata": {
7372
"ExecuteTime": {
74-
"end_time": "2026-02-16T05:32:35.365979Z",
75-
"start_time": "2026-02-16T05:32:35.333433Z"
73+
"end_time": "2026-02-16T05:46:57.700393Z",
74+
"start_time": "2026-02-16T05:46:57.678344Z"
7675
}
7776
},
77+
"source": [
78+
"shape = (5, 10)\n",
79+
"x = blosc2.ones(shape, dtype=np.float32)\n",
80+
"expr = blosc2.lazyudf(kernel_index_ramp, (x,), dtype=np.float32)\n",
81+
"res = expr[:]\n",
82+
"res"
83+
],
7884
"outputs": [
7985
{
8086
"data": {
8187
"text/plain": [
82-
"array([[ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.],\n",
83-
" [10., 11., 12., 13., 14., 15., 16., 17., 18., 19.],\n",
84-
" [20., 21., 22., 23., 24., 25., 26., 27., 28., 29.],\n",
85-
" [30., 31., 32., 33., 34., 35., 36., 37., 38., 39.],\n",
86-
" [40., 41., 42., 43., 44., 45., 46., 47., 48., 49.]], dtype=float32)"
88+
"array([[ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.],\n",
89+
" [11., 12., 13., 14., 15., 16., 17., 18., 19., 20.],\n",
90+
" [21., 22., 23., 24., 25., 26., 27., 28., 29., 30.],\n",
91+
" [31., 32., 33., 34., 35., 36., 37., 38., 39., 40.],\n",
92+
" [41., 42., 43., 44., 45., 46., 47., 48., 49., 50.]], dtype=float32)"
8793
]
8894
},
8995
"execution_count": 3,
9096
"metadata": {},
9197
"output_type": "execute_result"
9298
}
9399
],
94-
"source": [
95-
"shape = (5, 10)\n",
96-
"x = blosc2.zeros(shape, dtype=np.float32)\n",
97-
"expr = blosc2.lazyudf(kernel_index_ramp, (x,), dtype=np.float32)\n",
98-
"res = expr[:]\n",
99-
"res"
100-
]
100+
"execution_count": 3
101101
},
102102
{
103103
"cell_type": "code",
104-
"execution_count": 4,
105104
"id": "3bcf440eef3435f4",
106105
"metadata": {
107106
"ExecuteTime": {
108-
"end_time": "2026-02-16T05:32:36.250173Z",
109-
"start_time": "2026-02-16T05:32:36.234923Z"
107+
"end_time": "2026-02-16T05:46:58.627822Z",
108+
"start_time": "2026-02-16T05:46:58.610389Z"
110109
}
111110
},
112-
"outputs": [
113-
{
114-
"data": {
115-
"text/plain": [
116-
"array([[ 0., 1., 2., 3., 4.],\n",
117-
" [10., 11., 12., 13., 14.]], dtype=float32)"
118-
]
119-
},
120-
"execution_count": 4,
121-
"metadata": {},
122-
"output_type": "execute_result"
123-
}
124-
],
125111
"source": [
126112
"# Optional: request miniexpr JIT backend for this DSL kernel\n",
127113
"expr_jit = blosc2.lazyudf(\n",
@@ -133,7 +119,21 @@
133119
")\n",
134120
"res_jit = expr_jit.compute()\n",
135121
"res_jit[:2, :5]"
136-
]
122+
],
123+
"outputs": [
124+
{
125+
"data": {
126+
"text/plain": [
127+
"array([[ 1., 2., 3., 4., 5.],\n",
128+
" [11., 12., 13., 14., 15.]], dtype=float32)"
129+
]
130+
},
131+
"execution_count": 4,
132+
"metadata": {},
133+
"output_type": "execute_result"
134+
}
135+
],
136+
"execution_count": 4
137137
},
138138
{
139139
"cell_type": "markdown",
@@ -147,20 +147,23 @@
147147
},
148148
{
149149
"cell_type": "code",
150-
"execution_count": 5,
151150
"id": "e408f3ced12bb48e",
152151
"metadata": {
153152
"ExecuteTime": {
154-
"end_time": "2026-02-16T05:32:36.435536Z",
155-
"start_time": "2026-02-16T05:32:36.402775Z"
153+
"end_time": "2026-02-16T05:46:58.791626Z",
154+
"start_time": "2026-02-16T05:46:58.683662Z"
156155
}
157156
},
157+
"source": [
158+
"report_ok = blosc2.validate_dsl(kernel_index_ramp)\n",
159+
"report_ok"
160+
],
158161
"outputs": [
159162
{
160163
"data": {
161164
"text/plain": [
162165
"{'valid': True,\n",
163-
" 'dsl_source': 'def kernel_index_ramp(x):\\n # _i* and _n* are reserved DSL index/shape symbols, so disable linter warnings\\n return _i0 * _n1 + _i1 # noqa: F821',\n",
166+
" 'dsl_source': 'def kernel_index_ramp(x):\\n # _i* and _n* are reserved DSL index/shape symbols, so disable linter warnings\\n return x + _i0 * _n1 + _i1 # noqa: F821',\n",
164167
" 'input_names': ['x'],\n",
165168
" 'error': None}"
166169
]
@@ -170,10 +173,7 @@
170173
"output_type": "execute_result"
171174
}
172175
],
173-
"source": [
174-
"report_ok = blosc2.validate_dsl(kernel_index_ramp)\n",
175-
"report_ok"
176-
]
176+
"execution_count": 5
177177
},
178178
{
179179
"cell_type": "markdown",
@@ -188,14 +188,23 @@
188188
},
189189
{
190190
"cell_type": "code",
191-
"execution_count": 6,
192191
"id": "2cfb6d28ee3cf2d8",
193192
"metadata": {
194193
"ExecuteTime": {
195-
"end_time": "2026-02-16T05:32:36.497700Z",
196-
"start_time": "2026-02-16T05:32:36.475885Z"
194+
"end_time": "2026-02-16T05:46:58.840100Z",
195+
"start_time": "2026-02-16T05:46:58.818859Z"
197196
}
198197
},
198+
"source": [
199+
"@blosc2.dsl_kernel\n",
200+
"def kernel_invalid_ternary(x):\n",
201+
" return 1 if x else 0\n",
202+
"\n",
203+
"\n",
204+
"report_bad = blosc2.validate_dsl(kernel_invalid_ternary)\n",
205+
"print(report_bad[\"valid\"])\n",
206+
"print(report_bad[\"error\"])"
207+
],
199208
"outputs": [
200209
{
201210
"name": "stdout",
@@ -213,16 +222,7 @@
213222
]
214223
}
215224
],
216-
"source": [
217-
"@blosc2.dsl_kernel\n",
218-
"def kernel_invalid_ternary(x):\n",
219-
" return 1 if x else 0\n",
220-
"\n",
221-
"\n",
222-
"report_bad = blosc2.validate_dsl(kernel_invalid_ternary)\n",
223-
"print(report_bad[\"valid\"])\n",
224-
"print(report_bad[\"error\"])"
225-
]
225+
"execution_count": 6
226226
},
227227
{
228228
"cell_type": "markdown",

0 commit comments

Comments
 (0)