|
22 | 22 | }, |
23 | 23 | { |
24 | 24 | "cell_type": "code", |
25 | | - "execution_count": 1, |
26 | 25 | "id": "4743791e5436aa04", |
27 | 26 | "metadata": { |
28 | 27 | "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" |
31 | 30 | } |
32 | 31 | }, |
33 | | - "outputs": [], |
34 | 32 | "source": [ |
35 | 33 | "import numpy as np\n", |
36 | 34 | "\n", |
37 | 35 | "import blosc2" |
38 | | - ] |
| 36 | + ], |
| 37 | + "outputs": [], |
| 38 | + "execution_count": 1 |
39 | 39 | }, |
40 | 40 | { |
41 | 41 | "cell_type": "markdown", |
|
49 | 49 | }, |
50 | 50 | { |
51 | 51 | "cell_type": "code", |
52 | | - "execution_count": 2, |
53 | 52 | "id": "8926a0c21237fef3", |
54 | 53 | "metadata": { |
55 | 54 | "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" |
58 | 57 | } |
59 | 58 | }, |
60 | | - "outputs": [], |
61 | 59 | "source": [ |
62 | 60 | "@blosc2.dsl_kernel\n", |
63 | 61 | "def kernel_index_ramp(x):\n", |
64 | 62 | " # _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 |
67 | 67 | }, |
68 | 68 | { |
69 | 69 | "cell_type": "code", |
70 | | - "execution_count": 3, |
71 | 70 | "id": "fbe9cb59a4515c9c", |
72 | 71 | "metadata": { |
73 | 72 | "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" |
76 | 75 | } |
77 | 76 | }, |
| 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 | + ], |
78 | 84 | "outputs": [ |
79 | 85 | { |
80 | 86 | "data": { |
81 | 87 | "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)" |
87 | 93 | ] |
88 | 94 | }, |
89 | 95 | "execution_count": 3, |
90 | 96 | "metadata": {}, |
91 | 97 | "output_type": "execute_result" |
92 | 98 | } |
93 | 99 | ], |
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 |
101 | 101 | }, |
102 | 102 | { |
103 | 103 | "cell_type": "code", |
104 | | - "execution_count": 4, |
105 | 104 | "id": "3bcf440eef3435f4", |
106 | 105 | "metadata": { |
107 | 106 | "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" |
110 | 109 | } |
111 | 110 | }, |
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 | | - ], |
125 | 111 | "source": [ |
126 | 112 | "# Optional: request miniexpr JIT backend for this DSL kernel\n", |
127 | 113 | "expr_jit = blosc2.lazyudf(\n", |
|
133 | 119 | ")\n", |
134 | 120 | "res_jit = expr_jit.compute()\n", |
135 | 121 | "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 |
137 | 137 | }, |
138 | 138 | { |
139 | 139 | "cell_type": "markdown", |
|
147 | 147 | }, |
148 | 148 | { |
149 | 149 | "cell_type": "code", |
150 | | - "execution_count": 5, |
151 | 150 | "id": "e408f3ced12bb48e", |
152 | 151 | "metadata": { |
153 | 152 | "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" |
156 | 155 | } |
157 | 156 | }, |
| 157 | + "source": [ |
| 158 | + "report_ok = blosc2.validate_dsl(kernel_index_ramp)\n", |
| 159 | + "report_ok" |
| 160 | + ], |
158 | 161 | "outputs": [ |
159 | 162 | { |
160 | 163 | "data": { |
161 | 164 | "text/plain": [ |
162 | 165 | "{'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", |
164 | 167 | " 'input_names': ['x'],\n", |
165 | 168 | " 'error': None}" |
166 | 169 | ] |
|
170 | 173 | "output_type": "execute_result" |
171 | 174 | } |
172 | 175 | ], |
173 | | - "source": [ |
174 | | - "report_ok = blosc2.validate_dsl(kernel_index_ramp)\n", |
175 | | - "report_ok" |
176 | | - ] |
| 176 | + "execution_count": 5 |
177 | 177 | }, |
178 | 178 | { |
179 | 179 | "cell_type": "markdown", |
|
188 | 188 | }, |
189 | 189 | { |
190 | 190 | "cell_type": "code", |
191 | | - "execution_count": 6, |
192 | 191 | "id": "2cfb6d28ee3cf2d8", |
193 | 192 | "metadata": { |
194 | 193 | "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" |
197 | 196 | } |
198 | 197 | }, |
| 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 | + ], |
199 | 208 | "outputs": [ |
200 | 209 | { |
201 | 210 | "name": "stdout", |
|
213 | 222 | ] |
214 | 223 | } |
215 | 224 | ], |
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 |
226 | 226 | }, |
227 | 227 | { |
228 | 228 | "cell_type": "markdown", |
|
0 commit comments