Comments (11)
np.squeeze(x, axis=(2,)).shape
is equal to x.transposed!2[0]
. Would it be OK?
from mir.
You can create PR for squeeze
if you want)
from mir.
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 any idea how to do this?
No idea is good. This is major difference between numpy and ndslice
from mir.
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.
@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.
@absolutelyEveryoneEver I'll look at this tomorrow
from mir.
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.
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.
Or you can use union
s
from mir.
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)
- Special optimization for compile time known kernels HOT 1
- Separable filters support for DCV HOT 1
- Package mir contains invalid dependency cpuid (ci=1) HOT 5
- libmir.so missing from .gitignore HOT 1
- cannot infer argument types, expected 1 argument, not 2 in opApply on Slice HOT 2
- auto a=[[1,2],[3,4]].ndarray; // how to do that? (doens't compile) HOT 3
- Error: cannot append type int[] to type Slice!(2LU, int*) HOT 2
- mir vs ndslice conflict in dmd vs ldc when compiling with dub on ubuntu HOT 2
- Tiny Mersenne Twister HOT 1
- regression test to make sure at least latest dub versions work? currently broken HOT 1
- dot, norm, asum to mir.math.sum HOT 1
- mir-random does not compile with latest ldc on raspberry pi HOT 4
- How to reference the library HOT 6
- FFT? HOT 1
- OpenCL implementation? HOT 1
- can't understand how `sliced` definition compiles HOT 3
- Failing on Buildkite HOT 3
- rand!float() exponent problem HOT 3
- mir-algorithm dependency fails to build because of mir-core with ldc2 and gdc HOT 4
- Deprecation warnings
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 mir.