Giter VIP home page Giter VIP logo

Comments (11)

9il avatar 9il commented on August 28, 2024

np.squeeze(x, axis=(2,)).shape is equal to x.transposed!2[0]. Would it be OK?

from mir.

9il avatar 9il commented on August 28, 2024

You can create PR for squeeze if you want)

from mir.

wilzbach avatar wilzbach commented on August 28, 2024

The problem with squeeze is that you don't know how many dimensions it will return on compile-time, so we need to create a Slice with dynamic dimensions ...
@9il any idea how to do this?

auto squeeze(size_t N, Range)(auto ref Slice!(N, Range) slice)
{
    size_t nonSqueezeDims = 0;
    foreach (i; Iota!(0, N))
        if (slice._lengths[i] > 1)
            nonSqueezeDims += 1;

    Slice!(1, Range) ret; // how to make a slice of a dynamic dimension?
    size_t dims = 0;
    foreach (i; Iota!(0, N))
    {
        if (slice._lengths[i] > 1)
        {
            ret._lengths[dims] = slice._lengths[i];
            ret._strides[dims] = slice._strides[i];
            dims++;
        }
    }
    ret._ptr = slice._ptr;
    return ret;
}
unittest
{
    import mir.ndslice.slice;
    import std.range: iota;
    auto s = iota(3).sliced(1, 3, 1);
    s.squeeze.writeln;
    // [0, 1, 2]
}

from mir.

9il avatar 9il commented on August 28, 2024

@9il any idea how to do this?

No idea is good. This is major difference between numpy and ndslice

from mir.

wilzbach avatar wilzbach commented on August 28, 2024

No idea is good. This is major difference between numpy and ndslice

Hmm while compile-time dimensions are really awesome, this seems to be a major limitation that we should think about if we ever want to challenge NumPy (or similar libs).

Pinging reviewers and participants of the merge into phobos for their opinions and ideas:

@John-Colvin @burner @TurkeyMan @nordlow @SFrijters @JackStouffer @klickverbot

from mir.

9il avatar 9il commented on August 28, 2024

@greenify This is not very good idea to ping all at once =)

Could you provide a real world example where this feature is required?

from mir.

John-Colvin avatar John-Colvin commented on August 28, 2024

@absolutelyEveryoneEver I'll look at this tomorrow

from mir.

wilzbach avatar wilzbach commented on August 28, 2024

This is not very good idea to ping all at once

I am sorry - acted to rash. I will remember it. Sorry for spamming you @ pinged people.

Could you provide a real world example where this feature is required?

How you would implement loadtxt or loadmat if you don't know the dimensions before compile-time?

from mir.

9il avatar 9il commented on August 28, 2024

How you would implement loadtxt or loadmat if you don't know the dimensions before compile-time?

You always can use 2D matrix

from mir.

9il avatar 9il commented on August 28, 2024

Or you can use unions

from mir.

wilzbach avatar wilzbach commented on August 28, 2024

Could you provide a real world example where this feature is required?

I have thought long about this and no I can't.
The best example that I could find is here:

http://northstar-www.dartmouth.edu/doc/idl/html_6.2/REFORM.html

You always can use 2D matrix

Well let's assume you want to load a file from MatLab/R which is unknown to one, e.g.

VarSlice s = loadmat("foo.m"); // loads a 4-dimensional matrix, dimension come from file
s.sum;

Of course one could write a wrapper around such format to determine the dimensions, but ultimately we need to its dimensions and I guess that any application that wants to do more based on dynamic dimensions is rare and well better off to switch to a dynamic language.

Maybe it was just too many years of programming in dynamically typed languages (Python, JavaScript, NodeJs, ...) that I saw this to be problematic.

==> a big sorry to all the people that I spammed, but at least know you know that development for mir is happening here ;-)

Just for complete here's a list of squeeze implementations in dynamic languages that I found during a short search:

Octave:https://www.gnu.org/software/octave/doc/interpreter/Object-Sizes.html
Matlab: https://se.mathworks.com/help/matlab/ref/squeeze.html#bum54rg
R: https://stat.ethz.ch/R-manual/R-devel/library/base/html/drop.html
JS: http://mathjs.org/docs/datatypes/matrices.html
FreeMat: http://freemat.sourceforge.net/help/array_squeeze.html

from mir.

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.