Frame 105:25 (plane function) #11
-
Hi all! Going through the book and got a bit stuck on this frame. The fn Is this a typo or am I misunderstanding? Separate question: which results in:
This is in-line with running the following code:
However, if you extend (heh) this example by adding another t1 to the second tensor, things change. Here I would expect a result, similar to the previous example, of: but instead we get: which can be seen using the following code:
So instead of the first argument broadcasting to each t1 in the second argument, each scalar in the first argument is broadcasting to each t1 in the second argument. Is this expected? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @Solaxun. Great questions, both. The second question is also a very good one and has a somewhat subtle answer. In general, when you try to add two tensors of the same
We expect the result to be:
Now, if A0, B0, and C0 are tensor0 (i.e., scalars) and A1, B1, and C1 are tensors1, (as they are in your example), you will get the result that you got, which is The alternative result that you expected would have come from:
which is somewhat counterintuitive. There is a way to get this behavior as well by defining:
This will then get you your desired behavior:
(note: Due to a bug in the flat-tensors representation, which I just found out, this last extension currently only works for |
Beta Was this translation helpful? Give feedback.
-
Yes, that's a good point. We will clarify it further in the book. You are also right that the choice of how to do the extension/broadcast is somewhat arbitrary and a case can be made to go in either direction. |
Beta Was this translation helpful? Give feedback.
-
The bug discovered for the flat-tensors implementation has now been fixed in c5f05d8. |
Beta Was this translation helpful? Give feedback.
Hi @Solaxun. Great questions, both.
For the first, since
plane
is defined with extended operators, it can operate on tensor2's. It will produce a tensor1 as a result (instead of a scalar). We make use of this property throughout the book.The second question is also a very good one and has a somewhat subtle answer.
In general, when you try to add two tensors of the same
tlen
, for example:We expect the result to be:
Now, if A0, B0, and C0 are tensor0 (i.e., scalars) and A1, B1, and C1 are tensors1, (as they are in your example), you will get the result that you got, which is
[[10 9 14] [16 13 16] [6 10 9]]
Th…