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

array recycling/bsxfun-like operator #436

Closed
shabbychef opened this issue Feb 21, 2012 · 2 comments
Closed

array recycling/bsxfun-like operator #436

shabbychef opened this issue Feb 21, 2012 · 2 comments

Comments

@shabbychef
Copy link
Contributor

Having some kind of array recycling (as e.g. in R) for some (all?) binary operators can aid vectorized computation. (Rather, it allows one to write code without thinking too much about vectorization.) I am not sure that R's version of this Does The Right Thing, however:

  1. Without fair warning, new users may silently be using this 'feature' without knowing it.
  2. Turning it on by default in the core language is an extra complication in the compiler at least, and in the language definition.
  3. My preference, at least, is to recycle as Matlab's bsxfun, instead of considering a multidimensional array as a single vector and recycling modulo its length. For example, I often deal with multidimensional (5d or higher) arrays; to compute a Z-score 'along' dimension dim, in Matlab I can write x_zscore = bsxfun(@rdivide,bsxfun(@minus,x,mean(x,dim)),std(x,1,dim)). While this is agnostic to the dimensionality of x and the value in dim, it is a right PITA to read. It would be preferrable to have, instead, x_zscore = (x - mean(x,dim)) / std(x,1,dim).

Perhaps there should be some way to 'turn on' this kind of recycling in a given scope, which would result in overloading of the binary operators. (And perhaps this mechanism could support other kinds of recycling, e.g. R style.)

@JeffBezanson
Copy link
Member

bsxfun would be an uncontroversial addition to the library even if not ideal.

Another alternative is to define a type like ExpandedArray that virtually replicates an array or vector. Then you could write something like x - expand(mean(x,dim)). Other naming ideas welcome.

@JeffBezanson
Copy link
Member

bsxfun is now implemented.

StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
Temporarily disable the OffsetArrays tests for 0.7
KristofferC added a commit that referenced this issue Jul 3, 2018
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
)

Also deprecate wmedian and wquantile and return an error for non-integer FrequencyWeights.
cmcaine pushed a commit to cmcaine/julia that referenced this issue Nov 11, 2022
* Add debug.md

Co-authored-by: Angelika Tyborska <angelikatyborska@fastmail.com>

* Update exercises/shared/.docs/debug.md

Co-authored-by: Angelika Tyborska <angelikatyborska@fastmail.com>
Keno pushed a commit that referenced this issue Oct 9, 2023
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

2 participants