|
25 | 25 | "source": [ |
26 | 26 | "## Operands as arrays of different shape\n", |
27 | 27 | "\n", |
28 | | - "We will now create the operands, using different shape for each of them, just for flexing the broadcasting capabilities of lazy expressions." |
| 28 | + "We will now create the operands, using a different shape for each of them, in order to flex the broadcasting capabilities of lazy expressions." |
29 | 29 | ] |
30 | 30 | }, |
31 | 31 | { |
|
77 | 77 | "source": [ |
78 | 78 | "## Creating, saving and loading a lazy expression\n", |
79 | 79 | "\n", |
80 | | - "First, let's build a string expression that sums the contents of array `a` and operates with the values of `b` by `c`. In this context, creating a string version of the expression is critical; otherwise, reductions should be computed eagerly.\n", |
| 80 | + "First, let's build a string expression that sums the contents of array `a` and performs a multiplication with `b` and `c`. In this context, creating a string version of the expression is critical; otherwise, reductions will be computed eagerly.\n", |
81 | 81 | "\n", |
82 | 82 | "Let's see how this works." |
83 | 83 | ] |
|
110 | 110 | "id": "6226bf8d46ac7c32", |
111 | 111 | "metadata": {}, |
112 | 112 | "source": [ |
113 | | - "In the code above, an expression combining the arrays `a`, `b`, and `c` is expressed in string form: `a.sum() + b ∗ c`. Then, one builds a lazy expression and save it for later. The expression chosen illustrates how operations automatically adapt to the dimensions of the operands through the concept of broadcasting.\n", |
| 113 | + "In the code above, an expression combining the arrays `a`, `b`, and `c` is expressed in string form: `a.sum() + b ∗ c`. Then, one builds a lazy expression and saves it for later. The chosen expression illustrates how operations automatically adapt to the dimensions of the operands via broadcasting.\n", |
114 | 114 | "\n", |
115 | | - "**Broadcasting** allows arrays of different shapes (dimensions) to align for mathematical operations, such as addition or multiplication, without the need to enlarge operands by replicating data. The main idea is that smaller dimensions are \"stretched\" to larger dimensions in such a way that allows the operation to be performed consistently.\n", |
| 115 | + "**Broadcasting** allows arrays of different shapes (dimensions) to align for mathematical operations, such as addition or multiplication, without the need to enlarge operands by replicating data. The main idea is that smaller dimensions are \"stretched\" to larger dimensions in such a way that the operation may be performed consistently.\n", |
116 | 116 | "\n", |
117 | 117 | "<img src=\"images/lazyexpr-broadcast.png\" width=\"1000\"/>\n", |
118 | 118 | "\n", |
119 | | - "See [NumPy docs on broadcasting](https://numpy.org/doc/stable/user/basics.broadcasting.html) for more information.\n", |
| 119 | + "See the [NumPy docs on broadcasting](https://numpy.org/doc/stable/user/basics.broadcasting.html) for more information.\n", |
120 | 120 | "\n", |
121 | 121 | "Now that we have saved the expression, we can open and compute it to obtain the result. Let's see how this is done." |
122 | 122 | ] |
|
167 | 167 | "id": "362cfd5eb88b9bb6", |
168 | 168 | "metadata": {}, |
169 | 169 | "source": [ |
170 | | - "As we can observe when printing the lazy expression and its shape, the time required to get the `shape` is significantly shorter. This is because `lazy_expression.shape` does not need to compute all the elements of the expression; instead, it only accesses the **metadata** of the operands, from which it is inferred the basic information about the dimensions and type of the result.\n", |
| 170 | + "As we can observe when printing the lazy expression and its shape, the time required to get the `shape` is significantly shorter. This is because `lazy_expression.shape` does not need to compute all the elements of the expression; instead, it only accesses the **metadata** of the operands, from which it infers the necessary information about the dimensions and type of the result.\n", |
171 | 171 | "\n", |
172 | 172 | "Thanks to this metadata, if we know the dimensions of the arrays involved in the operation (such as in the case of `a.sum() + b * c`), Blosc2 can **quickly infer the resulting shape** without performing intensive calculations. This allows for fast access to structural information (like the `shape` and `dtype`) without operating on the actual data.\n", |
173 | 173 | "\n", |
|
181 | 181 | "source": [ |
182 | 182 | "## Resizing operands of persisted lazy expressions\n", |
183 | 183 | "\n", |
184 | | - "In this section, we will see how persisted lazy expressions automatically adapt to changes in the dimensions and values of the original operands, such as arrays `a` and `b`." |
| 184 | + "In this section, we will see how persisted lazy expressions automatically adapt to changes in the dimensions and values of the original operands, such as the arrays `a` and `b`." |
185 | 185 | ] |
186 | 186 | }, |
187 | 187 | { |
|
233 | 233 | "id": "d82492bf518c5a39", |
234 | 234 | "metadata": {}, |
235 | 235 | "source": [ |
236 | | - "After increasing the dimensions of the original arrays by modifying the values of `a` and `b`, the lazy expression is reopened. This step is crucial as it allows us to observe how the computation of the expression adapts to the new dimensions. Upon re-opening the expression, we can check that the results now accurately reflect these changes in the dimensions of the array operands. Moreover, see how obtaining the structural information (the `shape`) of the expression is a quick process, requiring only a fraction of the time it takes for the complete computation.\n", |
| 236 | + "After increasing the dimensions of the original arrays by modifying the values of `a` and `b`, the lazy expression is reopened. This step is crucial as it allows us to observe how the computation of the expression adapts to the new dimensions. Upon re-opening the expression, we can check that the results now accurately reflect these changes in the dimensions of the array operands. Moreover, see how obtaining the updated structural information (the `shape`) of the expression is a quick process, requiring only a fraction of the time it takes for the complete computation.\n", |
237 | 237 | "\n", |
238 | 238 | "This behavior highlights the ability of lazy expressions to adjust to operands using **metadata**, eliminating the need to re-compute each operation from the beginning. Thanks to this approach, notable flexibility and efficiency are achieved in handling arrays of various shapes and sizes." |
239 | 239 | ] |
|
249 | 249 | "\n", |
250 | 250 | "Also, broadcasting support facilitates working with arrays of different sizes, making the process more powerful and intuitive.\n", |
251 | 251 | "\n", |
252 | | - "Understanding how operations are managed in this context enables developers and data scientists to make the most of reduction and broadcasting capabilities, thereby enhancing the efficiency and effectiveness of their analyses and calculations. The beauty of lazy expressions lies in its ability to simplify the complex and empower our creativity!" |
| 252 | + "Understanding how operations are managed in this context enables developers and data scientists to make the most of reduction and broadcasting capabilities, thereby enhancing the efficiency and effectiveness of their analyses and calculations. The beauty of lazy expressions lies in their ability to simplify the complex and empower our creativity!" |
253 | 253 | ] |
254 | 254 | }, |
255 | 255 | { |
|
0 commit comments