Giter Club home page Giter Club logo

Comments (14)

9il avatar 9il commented on May 20, 2024

this snippet (copy sl to the buffer) seems to indicate no such utility to flatten elements into an array?

You can use flattened to use flat representation (it is not an array).
http://docs.algorithm.dlang.io/latest/mir_ndslice_topology.html#.flattened

not sure why median above doesn't use ndarray

median uses preallocated buffer.

from mir-algorithm.

9il avatar 9il commented on May 20, 2024

BTW, for Slice!(Contiguous, packs, T*) you can always do sl.iterator[0 .. sl.elementsCount].

from mir-algorithm.

9il avatar 9il commented on May 20, 2024

... this will return a common D array without allocation

from mir-algorithm.

wilzbach avatar wilzbach commented on May 20, 2024

How about adding such common questions into the main README or the wiki?
I hope that @timotheecour won't be the last one to try to transition ;-)

from mir-algorithm.

9il avatar 9il commented on May 20, 2024

Looks good

from mir-algorithm.

timotheecour avatar timotheecour commented on May 20, 2024

@9il

  • arrayview

BTW, for Slice!(Contiguous, packs, T*) you can always do sl.iterator[0 .. sl.elementsCount].

IMO this should be exposed as a method, it's a common case to interoperate between mir and non-mir code.

How about:

auto arrayview(S)(S slice) if (isContiguous!S){
  return sl.iterator[0 .. sl.elementsCount];
}
  • ndarray/flattened with existing buffer

not sure why median above doesn't use ndarray
median uses preallocated buffer.

Likewise, ndarray/flattened using a preallocated buffer (or using Appender!T or an arbitrary allocator) is a common case, and should be exposed in the library. What do you suggest?
How about overloads:

auto darray=myslice.ndarray(Mallocator.instance);
auto darray=myslice.flattened(Mallocator.instance);

(or maybe using ndarrayAlloc flattenedAlloc if name clash is an issue)

from mir-algorithm.

wilzbach avatar wilzbach commented on May 20, 2024

is there a plan to upgrade the reference example in https://dlang.org/phobos/std_experimental_ndslice.html with the new mir? (hopefully with a better buf[n++] = e; replaced as discussed above)

ndslice will be removed with the next release

from mir-algorithm.

9il avatar 9il commented on May 20, 2024

auto arrayview(S)(S slice) if (isContiguous!S){
return sl.iterator[0 .. sl.elementsCount];
}

auto asArray(size_t[] packs, T)(Slice!(Contiguous, packs, T*) sl)
{
    return sl.unpack.iterator[0..sl.elementsCount];
}

auto darray=myslice.ndarray(Mallocator.instance);
auto darray=myslice.flattened(Mallocator.instance);

makeSlice already allows to create new Contiguous slice with a data from another slice.
Then asArray can be used to get array representation.

hopefully with a better buf[n++] = e; replaced as discussed above

We need other method, something like copy to an array.

from mir-algorithm.

wilzbach avatar wilzbach commented on May 20, 2024

Is there a plan to upgrade the reference example in https://dlang.org/phobos/std_experimental_ndslice.html with the new mir?
ndslice will be removed with the next release

Just sent out the request for removal:
dlang/phobos#5187

from mir-algorithm.

timotheecour avatar timotheecour commented on May 20, 2024

is there a plan to upgrade the reference example in https://dlang.org/phobos/std_experimental_ndslice.html with the new mir? (hopefully with a better buf[n++] = e; replaced as discussed above)

ndslice will be removed with the next release

ya but adding this example (or whatever other similar good example snippet) and upgrading it in the new mir repo

from mir-algorithm.

timotheecour avatar timotheecour commented on May 20, 2024

@9il
asArray sounds good assuming all the asX do not allocate as well.

To be clear, that doesn't exist yet right? (couldn't find it)

makeSlice already allows to create new Contiguous slice with a data from another slice.
Then asArray can be used to get array representation.
We need other method, something like copy to an array.

is that the simplest?

import std.algorithm:copy;
myslice.makeSlice.asArray.copy(buffer);

// or something like: myslice.flattened(Allocater from buffer); ?

from mir-algorithm.

9il avatar 9il commented on May 20, 2024

@9il
asArray sounds good assuming all the asX do not allocate as well.

To be clear, that doesn't exist yet right? (couldn't find it)

makeSlice already allows to create new Contiguous slice with a data from another slice.
Then asArray can be used to get array representation.
We need other method, something like copy to an array.

is that the simplest?

import std.algorithm:copy;
myslice.makeSlice.asArray.copy(buffer);

makeSlice allocates data. So you do not need to use it here.

I do not understand the problem with buffer filling and current API. The code in the example will remain the same because the buffer size is very small (like 4x4 pixels), so manual coping will be faster in this case.

Current API allows

buf.ptr.sliced(sl.shape)[] = sl;

This looks pretty clear and simple, IMO

from mir-algorithm.

timotheecour avatar timotheecour commented on May 20, 2024

BTW, for Slice!(Contiguous, packs, T*) you can always do sl.iterator[0 .. sl.elementsCount]

should that be simply sl.iterator.array ? (ie a.toArray can be done via a.iterator.array)

from mir-algorithm.

9il avatar 9il commented on May 20, 2024

BTW, for Slice!(Contiguous, packs, T*) you can always do sl.iterator[0 .. sl.elementsCount]
should that be simply sl.iterator.array ? (ie a.toArray can be done via a.iterator.array)

For Slice!(Contiguous, packs, T*) slices it is just sl.field (without data reallocation).

For all slices sl.field.array allocates new array and copies slice data to it, array is from std.array.

from mir-algorithm.

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.