Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast Illustration #265

Open
bluss opened this issue Jan 20, 2017 · 8 comments
Open

Broadcast Illustration #265

bluss opened this issue Jan 20, 2017 · 8 comments

Comments

@bluss
Copy link
Member

bluss commented Jan 20, 2017

This one is really good, ndarray should adopt this (just need to change the code for each illu)

http://www.astroml.org/book_figures/appendix/fig_broadcast_visual.html

@bluss
Copy link
Member Author

bluss commented Jan 20, 2017

draft. Doesn't look good in github, fine in vim, fine in rustdoc's fonts.

array![0, 1, 2] + array![1]
shape [3] + shape [1] = shape [3]
 
┌───┬───┬───┐   ┌───┐┄┄┄┬┄┄┄╮   ┌───┬───┬───┐
│ 012 │ + │ 111 ┊ = │ 123 │
└───┴───┴───┘   └───┘┄┄┄┴┄┄┄╯   └───┴───┴───┘
 
array![[1, 1, 1],
       [1, 1, 1],
       [1, 1, 1]] + array![0, 1, 2]

shape [3, 3] + shape [3] = shape [3, 3]
 
┌───┬───┬───┐   ┌───┬───┬───┐   ┌───┬───┬───┐
│ 111 │   │ 012 │   │ 123 │
├───┼───┼───┤   └───┴───┴───┘   ├───┼───┼───┤
│ 111 │ + ┊ 012 ┊ = │ 123 │
├───┼───┼───┤   ├┄┄┄ ┄┄┄ ┄┄┄┤   ├───┼───┼───┤
│ 111 │   ┊ 012 ┊   │ 123 │
└───┴───┴───┘   ╰┄┄┄┴┄┄┄┴┄┄┄╯   └───┴───┴───┘
 
array![[0],
       [1],
       [2]] + array![[0, 1, 2]]

shape [3, 1] + shape [1, 3] = shape [3, 3]
 
┌───┐┄┄┄ ┄┄┄╮   ┌───┬───┬───┐   ┌───┬───┬───┐
│ 000 ┊   │ 012 │   │ 012 │
├───┤┄┄┄ ┄┄┄    └───┴───┴───┘   ├───┼───┼───┤
│ 111 ┊ + ┊ 012 ┊ = │ 123 │
├───┤┄┄┄ ┄┄┄     ┄┄┄ ┄┄┄ ┄┄┄    ├───┼───┼───┤
│ 222 ┊   ┊ 012 ┊   │ 134 │
└───┘┄┄┄ ┄┄┄╯   ╰┄┄┄ ┄┄┄ ┄┄┄╯   └───┴───┴───┘

@sglyon
Copy link

sglyon commented Feb 12, 2017

I'm a long time numpy user and am I'm having a hard time understanding how broadcasting semantics work here. In fact, if I try your third example from the previous comment I get an error:

⇒ cargo run                                                                                                                                          Spencers-MacBook-Pro
    Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/bertola`
thread 'main' panicked at 'ndarray: could not broadcast array from shape: [1, 3] to: [3, 1]', /Users/sglyon/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-0.7.3/src/lib.rs:573
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Is this expected?

@bluss
Copy link
Member Author

bluss commented Feb 12, 2017

yes, ndarray does not implement the third case.

@sglyon
Copy link

sglyon commented Feb 13, 2017

Ok, thanks for the answer.

Are there plans to implement the third case, or is this something that will not become a feature of this library?

@bluss
Copy link
Member Author

bluss commented Feb 13, 2017

As you know arrays in ndarray have dimensionality in the type.

If we add Array<f32, D1> + Array<f32, D2> the result needs to be a Array<f32, D3> where D3 is some sort of upper bound of the dimension types D1 and D2; so D3 needs to be the bigger of the two to have room to storing the dimension information.

As it is right now, the + always leaves the result with the dimension type D1 and that makes it simple, just broadcast the right hand side to the shape of the left hand side.

I haven't attempted implementing it; I'm in general not so keen on more generic noise than absolutely necessary. Every bit makes the library hard to understand, and many apparently already think it is hard to get into.

@sglyon
Copy link

sglyon commented Feb 16, 2017

OK that makes sense -- thanks for the clarification.

@thecooldrop
Copy link

@bluss, may thisi ssue be closed due to it being practically resolved in PR #565 ?

@bluss
Copy link
Member Author

bluss commented Mar 7, 2021

We never ended up adding broadcasting illustrations for #565 so I guess we're still waiting for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants