Code Monkey home page Code Monkey logo

Comments (3)

mcabbott avatar mcabbott commented on June 12, 2024

Yes something like this could be nice to have.

The simple one which takes integer sizes can't be type-stable & I'd be a little hesitant to make that Base.reshape, although possibly you could talk me into it. It's going to resolve the :, and then work in from each end of the dimensions, keeping keys if dimensions match... combing them when it can? For reshape(ka, 4, :, 3) presumably it keeps only the first.

Maybe one inspiration here is things like this:

julia> reshape('a':'f', 0:1, 11:13)
2×3 OffsetArray(reshape(::StepRange{Char, Int64}, 2, 3), 0:1, 11:13) with eltype Char with indices 0:1×11:13:
 'a'  'c'  'e'
 'b'  'd'  'f'

Making reshape(ka, ka.time, :) the interface wouldn't quite fit, but perhaps this is a reason to revive #6?

At some point I wrote split / join functions for named dimension reshaping, but did not find them all that useful, and possibly they have rotted:
https://github.com/mcabbott/NamedPlus.jl/blob/master/src/reshape.jl#L154

from axiskeys.jl.

rofinn avatar rofinn commented on June 12, 2024

It's going to resolve the :, and then work in from each end of the dimensions, keeping keys if dimensions match... combing them when it can?

Yeah, pretty much. I guess the trick would be with deciding on some basic promotion/merge rules for various types. I was kind of thinking that for string and symbols it'd be easy to just use a separator, but the fallback for other types would probably need to be either string interpolation or a tuple.

I might need to think about it some more, but I feel like the KeyedUnitRanges is largely independent of this one?

At some point I wrote split / join functions for named dimension reshaping, but did not find them all that useful, and possibly they have rotted:
https://github.com/mcabbott/NamedPlus.jl/blob/master/src/reshape.jl#L154

Interesting, this is almost identical to what I was thinking about, just with a different separator symbol and only on dims. Did you just end up writing your code differently to avoid needing to collapse the dims or was there something particularly cumbersome about that workflow?

from axiskeys.jl.

mcabbott avatar mcabbott commented on June 12, 2024

Re the KeyedUnitRanges story, I guess ka.time would always remain the key vector, and so that would have to read reshape(ka, axes(ka, :time), :) if it was to pass along the complete, recognisable, object.

for string and symbols it'd be easy to just use a separator, but the fallback

Yes, that sounds sensible, strings if string-ish, tuples if not. And sometimes, when the reshape doesn't just map two dimensions to one, but messes them up, the fallback fallback would be to drop them & use OneTo(n).

just end up writing your code differently

Yes, the honest answer is that when I have enough dimensions to get confused, mostly I reach for index-notation packages as a way to keep things straight (and line up with what's on paper). I haven't found names as useful as I hoped, maybe because you can't see them when looking at the function, only when actually running it? Maybe they are better suited to messy repl-data-wrangling tasks (with visual feedback) than to core-of-computation tasks (where accidentally introducing a permutedims can be pretty expensive). For such use, worrying too much about type-stability is a waste.

from axiskeys.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.