Comments (4)
Sorry about that. I think this is fixed on master, and that this expressions should work:
(jl_iIumVJ) pkg> add TensorCast#master
julia> using TensorCast
julia> x = [rand(2,3) for i=1:4];
julia> @cast y[i,j,k] := x[i,j][k]
3×4×2 PermutedDimsArray(::Array{Float64,3}, (2, 3, 1)) with eltype Float64:
[:, :, 1]:
0.899111 0.958207 0.972891 0.0562823
0.675006 0.353919 0.0110689 0.781209
0.410219 0.545557 0.370502 0.512076
...
from tensorcast.jl.
I can't make sense of this example. Shouldn't it error, since x
should be accessed as x[i][j,k]
rather than x[i,j][k]
?
from tensorcast.jl.
Oh I missed that. As you say, the it's exactly a problem with the attempt to write a friendly error message.
Tagged version:
julia> @pretty @cast y[i,j,k] := x[i,j][k]
begin
local reindeer = PermutedDimsArray(red_glue(x, (:, *, *)), (2, 3, 1))
y = reindeer
end
julia> @cast y[i,j,k] := x[i,j][k]
ERROR: UndefVarError: pretty not defined
Stacktrace:
[1] gluecodecheck(A::Vector{Matrix{Float64}}, code::Tuple{Colon, typeof(*), typeof(*)})
@ TensorCast.Fast ~/.julia/packages/TensorCast/rCpV9/src/slice.jl:130
[2] red_glue(A::Vector{Matrix{Float64}}, code::Tuple{Colon, typeof(*), typeof(*)})
@ TensorCast.Fast ~/.julia/packages/TensorCast/rCpV9/src/slice.jl:75
Master, after #17, uses a different glueing method, which works for any dimensionality, hence no error.
julia> @pretty @cast y[i,j,k] := x[i,j][k]
begin
local hyena = PermutedDimsArray(TensorCast.stack_iter(x), (2, 3, 1))
y = hyena
end
julia> @cast y[i,j,k] := x[i,j][k]
3×4×2 PermutedDimsArray(::Array{Float64, 3}, (2, 3, 1)) with eltype Float64:
...
julia> @cast y[i,j,k] := x[i,j][k] assert
ERROR: DimensionMismatch("expected a 2-tensor x[i, j]: ndims(x) == 2")
There are many other circumstances in which things will work despite wrong shapes. Originally the macro tried quite hard to produce very short answers, but perhaps it would be better to always include these checks. There is never a guarantee that extra dimensions will be OK, its just an accident.
julia> y = rand(2,5);
julia> @cast z[i] := log(y[i])
2×5 Matrix{Float64}:
-0.369487 -0.390997 -0.685209 -1.84328 -0.145182
-0.326173 -0.331384 -0.0361702 -0.80519 -0.254444
julia> @pretty @cast z[i] := log(y[i])
begin
z = @__dot__(log(y))
end
julia> @cast z[i] := log(y[i]) assert
ERROR: DimensionMismatch("expected a 1-tensor y[i]: ndims(y) == 1")
from tensorcast.jl.
Should be fixed on v0.3.3, and on v0.4.
from tensorcast.jl.
Related Issues (20)
- Use vector of indexes HOT 3
- World Age Issues with TensorCast calls from pyJulia HOT 3
- Exploit `einops` for docs / tests / advertising
- Slicing an array produces `Vector{<:SubArray}`, hence allocates HOT 4
- Indices which run over a shorter range than `axes(A,d)` HOT 9
- Extra singleton dimension appears during casting HOT 2
- cannot @cast on views of other @cast results HOT 3
- @cast for remaining n-1 dimensions, e.g, add noise to a tensor of column vectors HOT 1
- @cast works for hcat but not for [ ] HOT 1
- @cast on functions with tuples as lvalues HOT 3
- Concatenation / forced indexing HOT 1
- @cast into an SMatrix HOT 3
- Interpolation & scope HOT 1
- Hope to close the both side indices check HOT 2
- Performance of nested reductions HOT 1
- Expr -> Symbol MethodError when combining mapslices and reshapes HOT 1
- Support for AxisKeys
- array arguments in @cast indexing HOT 1
- Error in summation within @reduce HOT 1
- Macro hygeine of `TensorCast` symbol 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 tensorcast.jl.