Giter Club home page Giter Club logo

Comments (4)

mcabbott avatar mcabbott commented on June 11, 2024

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.

yha avatar yha commented on June 11, 2024

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.

mcabbott avatar mcabbott commented on June 11, 2024

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.

mcabbott avatar mcabbott commented on June 11, 2024

Should be fixed on v0.3.3, and on v0.4.

from tensorcast.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.