Comments (4)
I don't think '
should be broadcast via @.
. It gets used too often for reshaping, such as in @. x + x'
. A decent amount of code would break (and some of it would break quietly) if this interaction were changed.
If one wants it to broadcast, one can use adjoint
directly a la @. x + adjoint(x)
.
But to others' suggestions, it could be worth documenting this behavior. What other operators are skipped by @.
? So far, I've noticed '
, :
, _[_...]
. To get these to broadcast via @.
, one needs to use adjoint
, Colon()
, getindex
/setindex!
directly. We also don't broadcast any flavor of parenthetical (i.e., ()
when not a call, []
, {}
), obviously.
That's what I could glean from the source, but the metaprograming is a little sophisticated for me so I'm quite certain I've missed things.
I notice that one can use (:).(x,y)
but not @. (:)(x,y)
. This is probably a bug an unavoidable consequence of x:y
and (:)(x,y)
being AST-equivalent and the desire to be able to write things like @. x[begin+1:end] - x[begin:end-1]
without the @.
doing weird things to indexing ranges. Although :
is mostly used with scalars for indexing so this may not be a problem. Can someone provide additional commentary or background on why :
is excluded?
from julia.
Colons used to have their own special Expr(:(:), ...)
syntax form and thus wasn't considered a called function initially. Its special-casing in dottable
was added when its syntactic special-casing was removed. But you're probably right — as a function with only scalar methods defined in Base, I don't think you'd ever see a difference (outside of things that were previously errors or perhaps some package methods that stretch the generic definition to its limit).
And that's where it's quite different from '
.
But where it's similar is that you can't syntactically "add dots" to the infix 1:2
or 3:4:5
; x.:y
means something very different. Similarly, .'
doesn't work at all (and used to mean something very different).
Edit: I started this comment not sure how much intentionality was behind this restriction, but after writing that last paragraph I'm convinced there's a good rhyme and reason to it all — it's about syntactically "adding dots."
from julia.
A grep for "@\.[^#]*'"
in my local files also found two instances (here and here) in Makie:
z = @. sin(x) * cos(x')
and
zs = @. √(xs^2 + ys'^2)
Maybe a better fix would be to document the current behavior as a special case...
from julia.
Regarding why @.
is not allowed to broadcast :
I can imagine an index type that
- supports
:
to make valid index ranges and - behaves as non-scalar under broadcasting.
Then @.
would interfere with indexing in something like @. x[a:b] * y
. Is that why :
is special cased?
This is theoretical though. In practice I can't come up with an example where broadcasting :
causes problems. To take @mikmoore 's example:
julia> x = 1:3;
julia> @. x[begin+1:end] * x[begin:end-1]
2-element Vector{Int64}:
2
6
This still works after allowing @.
to broadcast the :
operator:
julia> Broadcast.dottable(x::Symbol) = (!Base.isoperator(x) || first(string(x)) != '.' || x === :..)
julia> @. x[begin+1:end] * x[begin:end-1]
2-element Vector{Int64}:
2
6
and now we can do the following (which doesn't work without the dottable
redefinition):
julia> @. 1:x
3-element Vector{UnitRange{Int64}}:
1:1
1:2
1:3
from julia.
Related Issues (20)
- Julia crashes when running a long task on a super computer that uses meta prorgamming and threads
- Weird Windows 11 failure / crash HOT 2
- Error: "attempt to send to unknown socket" after rmprocs
- 2x Regression in string join benchmark on NanoSoldier HOT 5
- Project precompilation fails on 1.11.0-alpha2 if Project.toml contains "name" but no UUID
- Incorrect Pkg commands result in "Unhandled Task ERROR:" HOT 1
- expose GMP bit-flipping operations (tstbit, combit, etcetera) HOT 2
- Segfault when LD_LIBRARY_PATH is set at something HOT 6
- RNA Extraction and RNA Purification Market Size, Growth Strategies, Competitive Landscape, Factor Analysis, 2035
- malformed profiling results, zero line numbers
- `convert` doesn't preserve `Base.OneTo` if the element type is being changed HOT 2
- Evaluate the cost of relocatable files in parallel filesystems HOT 2
- Segfault in jl_emit_codeinst HOT 1
- Error when instantiating environment: "compiled/v1.12/RegressionTests/L2wCO_p4MmI.ji" No such file or directory HOT 1
- Wrong number of methods after redefinition of function HOT 2
- libunwind ld warning during build and incorrect line numbers in stacktrace HOT 1
- `@fastmath` and `literal_pow` not compatible HOT 1
- Source link 404 HOT 1
- 1.11.0-alpha2: problems with precompilation HOT 3
- Destructed arguments cannot be properly used to define optional arguments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.