www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6345] New: A different kind of vector operation

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6345

           Summary: A different kind of vector operation
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Currently (DMD 2.054) this is not allowed, but a vector op like this is
sometimes useful to me:

struct Foo {
    int x, y;
    int[100] array;
}
void main() {
    auto foos = new Foo[100];
    foos[].y += 10; // ********
}


For the programmer I think the meaning of such code is easy enough to
understand and use.

At the moment I don't see the need to define a operator overload for this too
(I mean something like opSliceUnary).


Don notes:

 An interesting use case:
 void main()
 {
     cdouble[100] foos;
     foos[].re = 5.0;
 }
Wilfried Kirschenmann suggests:
 void main() {
   auto foos = new Foo[100];
   auto ints = new int[100]
   ints = foos[].y;
 }
 
 This would simplify the wrinting of numerous application, especially
 in the writing of image/video processing (eg. rgb2yuv conversions)
 This would also simplify the writing of template library transforming
 "array of struct" to "struct of arrays" in a transparent manner for
 the library user.
Andrej Mitrovic notes (I don't understand this):
 float[] buffers = malloc..;
 float*[] CBuffers = buffers[].ptr;
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 18 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6345


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com



What if I define


ref int y(Foo[] f) {
    return f[0].x;
}


?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 18 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6345




Another possible purpose. Given this matrix:

auto M = new double[][](10, 20);

This:

M[][1] = 1.0;

Means:

foreach (row; p)
    row[1] = 1.0;


This replaces some usages of std.range.transversal().

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 27 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6345


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au



All these operations require the use of strided slices, which would be a huge
amount of work to implement. Also, there are a plethora of corner cases.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6345





 All these operations require the use of strided slices, which would be a huge
 amount of work to implement. Also, there are a plethora of corner cases.
I see. Those corner cases are bad. If you think this is too much work for the gain I'll close this enhancement request, to leave similar functionalities to matrix libraries. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 28 2011