220 9135 <b287f3ac-3174-4258-ac4c-8f22186d57bb@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Jesse Perla <jesseperla@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: N3851, the array_view specification: notes and
 use cases for scientific computing
Date: Wed, 5 Feb 2014 16:24:02 -0800 (PST)
Lines: 553
Approved: news@gmane.org
Message-ID: <b287f3ac-3174-4258-ac4c-8f22186d57bb@isocpp.org>
References: <d992e8bb-7f47-40c7-9f97-f6bc31076fc1@isocpp.org>
 <c15950f7-79ff-4303-966d-32cc5aaeaf4a@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_7155_10483635.1391646242555"
X-Trace: ger.gmane.org 1391646238 14512 80.91.229.3 (6 Feb 2014 00:23:58 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 6 Feb 2014 00:23:58 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDPLLXOEXEORBJFMZOLQKGQEEAXNKIQ@isocpp.org Thu Feb 06 01:24:07 2014
Return-path: <std-proposals+bncBDPLLXOEXEORBJFMZOLQKGQEEAXNKIQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f72.google.com ([209.85.219.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDPLLXOEXEORBJFMZOLQKGQEEAXNKIQ@isocpp.org>)
	id 1WBClC-0001tU-59
	for gclcip-std-proposals@m.gmane.org; Thu, 06 Feb 2014 01:24:06 +0100
Original-Received: by mail-oa0-f72.google.com with SMTP id i4sf6313627oah.11
        for <gclcip-std-proposals@m.gmane.org>; Wed, 05 Feb 2014 16:24:05 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=UyIsT9R+Q4RxHvU6WwiOcfmwJwsH5ypcv0SljL1sfPI=;
        b=e51DIg+g6y0yBufTkXANHgipD8rDCU+/rYUgV2o68pkKnCm44bivskS0qFe8I/xLDw
         txCORuoaZdtXlqqmkvDSE2M5+jJvBISXraTVYz+iEwisQhrgIVYRE+KLCuV09zBnLZJo
         CE/w0hWky5HLNSOkJjzMH4kF28D38jl9oH3pq6vIunV3q6r78MxeSpAO3Y8nhNhkNZp6
         +YPlJHYkSKvjggYLUILMySaMY5OrmooSupK4fioXDFQeNVSkDSoIV+Y9VgKy9vGPVV/W
         8JazcDr0eADTaOkCK9TCDiD2MZLwtH2s1n+weE6ykQTQlG8ati5/TdeFfLXtm1qsweF9
         ipJQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=UyIsT9R+Q4RxHvU6WwiOcfmwJwsH5ypcv0SljL1sfPI=;
        b=h8+dQz5a3VMeNpeIzK8u2kx967iSSrUjQH2iEDLgvWkkHoXQ4GCCT4llfeSorHEmEq
         MfF4XogTvfQ9F86nxHTOHiPEYCFN/yt3qBXJcttUx3zSvBB8pNKSR1vUvfGFv7hhPXgz
         LItKRNxEzL7W1Zi2kv8kijGjpV6a1kKlf0nRJ9Ovrhuon/VI3rYxhvG4AXgilhoOlz2M
         BwR6aDyMn8XDfMYa34eWYt3+v/19nM2AHG/dKJKZfh+lglNs2V8S2xwIhXHE5jCrvIuA
         nL/WvIgai8YEFG4qOH3bbPxDtPzebJW9G6xtNGwajvP8kIpQz7n4to1fC778QjaUTa1W
         9yIg==
X-Gm-Message-State: ALoCoQlhkjENZo7MiCcGrrRPUoGQIT6XL2t7slHLPHlhHWq/dUtsVLIjTXpOJfOq91I0uoTmZfuN
X-Received: by 10.182.126.137 with SMTP id my9mr2075472obb.13.1391646245132;
        Wed, 05 Feb 2014 16:24:05 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.43.230 with SMTP id z6ls3641753igl.25.canary; Wed, 05 Feb
 2014 16:24:04 -0800 (PST)
X-Received: by 10.50.79.228 with SMTP id m4mr100679igx.9.1391646244350;
        Wed, 05 Feb 2014 16:24:04 -0800 (PST)
In-Reply-To: <c15950f7-79ff-4303-966d-32cc5aaeaf4a@isocpp.org>
X-Original-Sender: jesseperla@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:9135
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/9135>

------=_Part_7155_10483635.1391646242555
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Thanks, we all really appreciate this work.

On Wednesday, February 5, 2014 3:48:10 PM UTC-8, =C5=81ukasz Mendakiewicz w=
rote:
>
> 1. *Deal killer* Need Static Row vs. column major support!=20
> =20
> It's there -- *strided_array_view*. We have intentionally kept the=20
> requirements of the provided *stride* lax to accommodate peculiar use=20
> cases such as transposed views (stride is decreasing) or even=20
> "self-aliasing views" (stride =3D 0 in one or more dimensions).
>
> This of course means that it must be the *strided_array_view* type used=
=20
> on interfaces expecting varying ordering. However we believe that it shou=
ld=20
> be explicit whether the data can have access pattern that is not "natural=
",=20
> due to all the performance implications.
> I recognize that manually specifying the stride might be error-prone,=20
> however I believe that providing wrappers atop constructing such views=20
> would be the responsibility of the specific library furnishing those=20
> column-major containers in the first place, e.g. "strided_array_view<T,2>=
=20
> to_strided_array_view( some_column_major_math_library::matrix<T>& )".
>

My answer:
Ah, I didn't see that.  That does it for dynamic orderings like=20
boost::multi_array has.  My only problem then is that there is no way to=20
have a static check on the orderings.  So it isn't possible to write an=20
adaptor for things that have static storage orderings such as Eigen, ublas,=
=20
and most of the others.  I also can't tag dispatch to different library=20
functions based on the storage order.
=20

>
> 2. *Deal killer* operator()(...) support
>
> Yes, we realized that operator() is the convention, though only as a=20
> workaround because C++ doesn't have multi-argument operator[].
> We have wrestled with whether this is the right time to finally propose=
=20
> and add multi-argument operator[] directly, and we will raise this questi=
on=20
> in Issaquah. If we had that, that would be clearly the right answer, righ=
t?
>
My answer:
For me, the issue is more one of interoperability in making existing code=
=20
generic.  An enormous amount of software for 2D and 3D containers has been=
=20
written with operator() because a multi-argument operator[] didn't exist=20
(see all of the libraries I mentioned and many more).  So it makes=20
converting that code to use a generic array_view interface very costly.
=20
In the meantime, given we abandon the pre-C++11 intuition, I find using *av=
[{3,=20
1, 4}]* much cleaner than *av(3, 1, 4)*. To me, the message operator[]=20
conveys is "accessing data structure (sub-elements)", while operator()=20
should always mean "executing algorithm (calling a function)". It's=20
unfortunate that we ended up with an overloaded meaning of the latter due=
=20
to language limitations (cf. C#). Also, it only comes up when you don't=20
already have an *index<N>* object (in which case you'd just write *av[idx]*=
and this discussion doesn't matter) but you have integer literals or=20
individual integer variables -- is that really so bad?
It seems like the argument is migration from existing code that happens to=
=20
use operator() because that's all we had. We understand the need for=20
migration, but if we added operator[,,], then we also want to encourage new=
=20
code to be written the right way going forward. Is migrating from=20
operator() syntax really a big deal? If yes, would it be helpful to add a=
=20
(redundant) operator() accessor that we immediately also mark=20
[[deprecated]] to discourage use?


My answer:
In this case, I think it is pretty bad and could hamstring the interface. =
=20
I also would prefer a multi-argument [] if building from scratch, but there=
=20
is a huge amount of scientific code out there that one would want to make=
=20
generic.  If it supports operator(), then we can just change our interfaces=
=20
to a generic one, and use the implicit concept used throughout array_view.=
=20
Adding a redundant operator() seems the easiest solution.  A [[deprecated]]=
=20
doesn't hurt (as long as you never actually deprecate it).  This just=20
doesn't seem like a battle worth fighting over aesthetics to me.


> 3. *Would be very nice* reshape() function
>
> Can you please help me understand what part is missing here with the=20
> functionality of the *array_view* constructor?
>
You are right, that is enough.
=20

>
>
> 4. *Nice to have sooner rather than later* Fixed size extents
>
> This is interesting, although as you observed -- it can be separated from=
=20
> the "core" proposal into a subsequent one.
> I'm also a bit worried with polluting the programming model with the=20
> concept driven mostly by the optimizer rationale.
> Having said that -- can you give us some specific motivating examples and=
=20
> data?
>

To me, the biggest motivating examples for this are ensuring adaptability=
=20
and ensuring conformance for tensor/matrix operations.

*For optimization: *Includes things like SIMD due to fixed extents,=20
managing cache boundaries, etc. that I don't really understand.  I also=20
know that this becomes extremely important for geometry.  Many libraries=20
have handcrafted optimizations for their algorthms with fixed size=20
matrices/vector (e.g.=20
http://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html shows the=
=20
fixed sizes are all over the place).  Think through inverting a matrix  if=
=20
you know it is 2x2 at compiletime and can dispatch to the closed form=20
solution.  They will handcraft assembler code to use SSE instructions for=
=20
things like inner product if they know it fits in the register.  I am=20
always suspicious of premature optimization, but 1) these are the sorts of=
=20
optimizations that library vendors (ie. other people) can write with=20
extents known at compiletime, and we can't use them if we don't have the=20
static size information. and (2) with scientific computing small=20
performance changes can have enormous effects in many applciations.
*For interoperability:* The ideal here would be that I can take an=20
array_view and create adaptor to eigen/ublas/etc.  then use their=20
expression templates for the sematics.  But to generate a static eigen=20
vector/matrix, I need to statically query the bounds of the array_view.
*For conformance: *Having static sizes can significantly improve=20
correctness in generic code at compiletime.  For example, making sure that=
=20
an inner product of two 1D slices have the same length at compile time, etc=
..



=20
On Tuesday, January 28, 2014 11:45:23 AM UTC-8, Jesse Perla wrote:

> I think this is exactly the right approach for the standard.  Instead of =
a=20
> container, standardize on a view for contiguous or strided memory as a=20
> method for access and interoperability, and then use whatever containers=
=20
> you wish in the background.  Then adaptors can be written for the various=
=20
> scientific and numerical libraries to take one of these objects and conve=
rt=20
> into their expression template library.  This may have a chance to be a=
=20
> standard interoperability format, which is crucially needed for those doi=
ng=20
> numerical work.  The only way to do it right now is to pass around raw=20
> pointers between disparate libraries with all sorts of manual conversion =
in=20
> the middle.
> =20
> As use cases for scientific programming, consider the following set of=20
> tests for adaptation:
>
>    1. Adaptor written which can "convert" this 1D version of boost::ublas=
=20
>    vector, and 2D of ublas::matrix, COIN-OR dense matrix and vector, Pyth=
on=20
>    Numpy vector/matrix in C++ libraries, and matlab MEX extension
>    =20
>    2. Can an efficient adaptor be written for boost numeric_bindings to=
=20
>    call a variety of libraries (mostly implementations of LAPACK, MUMPS,=
=20
>    UMFPACK, etc. that are often column-major):=20
>    https://svn.boost.org/svn/boost/sandbox/numeric_bindings/boost/numeric=
/bindings/.=20
>     To see if the correct accessors/types are in array_view, check out th=
e=20
>    example adaptor implementations in=20
>    https://svn.boost.org/svn/boost/sandbox/numeric_bindings/boost/numeric=
/bindings/boost/multi_array.hppand=20
>    https://svn.boost.org/svn/boost/sandbox/numeric_bindings/boost/numeric=
/bindings/eigen/matrix.hpp.=20
>     One requirement of this would be that the adaptor class should have n=
o=20
>    storage of its own.
>    =20
>   =20
> =20
> =20
> From the perspective of scientific computing, the following are some=20
> concerns and additions ordered by necessity:
>
>    - *Deal killer* Need Static row vs. column major support!!!!
>       - A large number of scientific libraries are written with column=20
>       major data.  This is especially true when calling high performance=
=20
>       libraries written in fortran, or interfacing with matlab in MEX.  E=
VERY=20
>       major container used for numerical analysis has this option.
>       - boost::multi_array allows a runtime specification for the=20
>       ordering, but this is overkill.  Better is a template parameter whi=
ch=20
>       determines the ordering for every dimension, and which can be queri=
ed by=20
>       TMP used in the adaptors.  Check out the ordering_type in boost::ub=
las,=20
>        ColMajor vs. RowMajor in eigen, and the general_storage_order in=
=20
>       boost::multi_array and seimilar ones in GLAS, MTL, etc.
>       - If a particular user of the library (e.g. AMP) doesn't want to=20
>       work with row-major, then just a static_assert to reject.
>       - I don't see how this could be added later without breaking a=20
>       bunch of generic code.  I also can't stress enough how crucial this=
 is, or=20
>       it is pretty much useless for interoperability (and, if you ask me,=
 doesn't=20
>       even belong in a C++ standard as it only creates more implementatio=
n noise)
>   =20
>
>    - *Deal killer* operator()(...) support
>       - A good portion of generic code is written with operator(),=20
>       especially using 2D specializations.  If this doesn't have that as =
an=20
>       accessing option, then it is too difficult to convert existing code=
 to be=20
>       generic, which will undermine the use of this standard.  operator()=
 code is=20
>       much more prevalent here than operator []
>       - This should be a variadic accessor for a list of extents, and=20
>       doesn't need to have an index_type version.  Having a constexpr=20
>       specialization would also be nice and allow optimizations, but is n=
ot=20
>       necessary.
>       - Examples: ublas, eigen, COIN-OR densematrix, and most others have=
=20
>       this as their main way to access 1 and 2D matrices.
>   =20
>
>    - *Would be very nice* reshape() function
>       - It would be nice for the user to be able to reshape the array=20
>       with the same allocated size.  Not resize!  An assert could ensure =
that the=20
>       size remains the same.
>       - This is very nice for in-place algorithms using huge array's=20
>       where the user doesn't want to, or doesn't have the resources to,=
=20
>       reallocate an entire copy (e.g. transpose)
>       - It also comes up a lot in numeric analysis with tensor products=
=20
>       and multivariate regressions.  (e.g. using the Kronecker product wi=
th vec,=20
>       etc.)
>   =20
>
>    - *Nice to have sooner rather than later* Fixed size extents
>       - A fixed_array_view: Pass in a static list of extents as a=20
>       variadic template argument.  Would not support a reshape() function=
 as that=20
>       would be a different type.  Though a conversion function could be w=
ritten.
>       - This enables a huge number of optimizations and compile time=20
>       extent checking for errors.  Since most of the 1 and 2d array libra=
ries=20
>       have this, we would be able to pass it around and adapt as required=
 when=20
>       using those algorithms (also SIMD based optimizations)
>   =20
>
>    - *Nice to have* RandomAccessContainer and other range-supported=20
>    concepts, so that existing STL and future range algorithms could be us=
ed=20
>    (especially for the 1D version)
>    =20
>   =20
> =20
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_7155_10483635.1391646242555
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Thanks, we all really appreciate this work.<br><br>On Wedn=
esday, February 5, 2014 3:48:10 PM UTC-8, =C5=81ukasz Mendakiewicz wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">1. <span style=
=3D"font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;font-size:10pt"><f=
ont color=3D"#000000">*Deal
killer* Need Static Row vs. column major support!</font></span><font color=
=3D"#000000" size=3D"3" face=3D"Times New Roman">

</font><div><div>&nbsp;</div></div><div>It's there -- <i>strided_array_view=
</i>. We have intentionally kept the requirements&nbsp;of the provided <i>s=
tride</i> lax to accommodate peculiar use cases such as transposed views (s=
tride is decreasing) or even "self-aliasing views" (stride =3D 0 in one or =
more dimensions).</div><br><div>This of course means that it must be&nbsp;t=
he <i>strided_array_view</i> type used on interfaces expecting varying orde=
ring. However we believe that it should be explicit whether the data&nbsp;c=
an have access pattern that is not&nbsp;"natural", due to all&nbsp;the perf=
ormance implications.</div><div>I&nbsp;recognize that manually specifying t=
he stride might be&nbsp;error-prone, however I believe that providing&nbsp;=
wrappers atop constructing such views would be the responsibility of the sp=
ecific library furnishing those column-major containers in the first place,=
 e.g. "strided_array_view&lt;T,2&gt; to_strided_array_view( some_column_maj=
or_math_<wbr>library::matrix&lt;T&gt;&amp; )".</div></div></blockquote><div=
><br>My answer:<br>Ah, I didn't see that.&nbsp; That does it for dynamic or=
derings like boost::multi_array has.&nbsp; My only problem then is that the=
re is no way to have a static check on the orderings.&nbsp; So it isn't pos=
sible to write an adaptor for things that have static storage orderings suc=
h as Eigen, ublas, and most of the others.&nbsp; I also can't tag dispatch =
to different library functions based on the storage order.<br>&nbsp;</div><=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><br></div=
><div>2. <span style=3D"font-family:&quot;Arial&quot;,&quot;sans-serif&quot=
;;font-size:10pt"><font color=3D"#000000">*De</font></span><span style=3D"f=
ont-family:&quot;Arial&quot;,&quot;sans-serif&quot;;font-size:10pt"><font c=
olor=3D"#000000">al killer* operator()(...) support</font></span></div><div=
><span style=3D"font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;font-s=
ize:10pt"><font color=3D"#000000"><br></font></span></div><div><span style=
=3D"font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;font-size:10pt"><f=
ont color=3D"#000000">Yes, we realized that operator() is the convention, t=
hough only as a workaround because C++ doesn't have multi-argument operator=
[].</font></span></div><div><span style=3D"font-family:&quot;Arial&quot;,&q=
uot;sans-serif&quot;;font-size:10pt"><font color=3D"#000000">We have wrestl=
ed with whether this is the right time to finally propose and add multi-arg=
ument operator[] directly, and we will raise this question in Issaquah. If =
we had that, that would be clearly the right answer, right?</font></span></=
div></div></blockquote><div dir=3D"ltr">My answer:<br>For me, the issue is =
more one of interoperability in making existing code generic.&nbsp; An enor=
mous amount of software for 2D and 3D containers has been written with oper=
ator() because a multi-argument operator[] didn't exist (see all of the lib=
raries I mentioned and many more).&nbsp; So it makes converting that code t=
o use a generic array_view interface very costly.<br>&nbsp;<span style=3D"f=
ont-family:&quot;Arial&quot;,&quot;sans-serif&quot;;font-size:10pt"><font c=
olor=3D"#000000"><br>In the meantime, given we abandon the pre-C++11 intuit=
ion, I find using&nbsp;<i>av[{3, 1, 4}]</i> much cleaner than <i>av(3, 1, 4=
)</i>. To me, the message operator[] conveys is "accessing data structure (=
sub-elements)", while operator() should always mean "executing algorithm (c=
alling a function)". It's unfortunate that we ended up with an overloaded m=
eaning of the latter due to language limitations (cf. C#).&nbsp;Also,&nbsp;=
it only comes up when you don't already have an <i>index&lt;N&gt;</i> objec=
t (in which case you'd just write <i>av[idx]</i> and this discussion doesn'=
t matter) but you have integer literals or individual integer variables -- =
is that really so bad?</font></span><div>It seems like the argument is migr=
ation from existing code that happens to use operator() because that's all =
we had.&nbsp;We understand the need for migration, but if we added operator=
[,,], then we also want to encourage new code to be written the right way g=
oing forward. Is migrating from operator() syntax really a big deal? If yes=
, would it be helpful to add a (redundant) operator() accessor that we imme=
diately also mark [[deprecated]] to discourage use?<br><br><br></div></div>=
<div>My answer:<br>In this case, I think it is pretty bad and could hamstri=
ng the interface.&nbsp; I also would prefer a multi-argument [] if building=
 from=20
scratch, but there is a huge amount of scientific code out there that one w=
ould want to make generic.&nbsp; If it supports=20
operator(), then we can just change our interfaces to a generic one, and
 use the implicit concept used throughout array_view. Adding a redundant op=
erator() seems the easiest solution.&nbsp; A [[deprecated]] doesn't hurt (a=
s long as you never actually deprecate it).&nbsp; This just doesn't seem li=
ke a battle worth fighting over aesthetics to me.<br><br></div><blockquote =
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1p=
x #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><br></div><div>3. <s=
pan style=3D"font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;font-size=
:10pt"><font color=3D"#000000">*Would be very nice*
reshape() function</font></span></div><div><br></div><div>Can you please he=
lp me understand what part is missing here with the functionality of the&nb=
sp;<i>array_view</i> constructor?</div></div></blockquote><div>You are righ=
t, that is enough.<br>&nbsp;<br></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left=
: 1ex;"><div dir=3D"ltr"><div><br></div><div><br></div><div>4. <span style=
=3D"font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;font-size:10pt"><f=
ont color=3D"#000000">*Nice to have sooner
rather than later* Fixed size extents</font></span></div><div><br></div><di=
v>This is interesting, although as you observed -- it can be separated from=
 the "core" proposal into a subsequent one.</div><div>I'm also a bit worrie=
d with polluting the programming model with the concept driven mostly by th=
e optimizer rationale.</div><div>Having said that -- can you give us some s=
pecific motivating examples and data?</div></div></blockquote><div dir=3D"l=
tr"><br>To me, the biggest motivating examples for this are ensuring adapta=
bility and ensuring conformance for tensor/matrix operations.<br><br><b>For=
 optimization: </b>Includes things like SIMD due to fixed extents, managing=
 cache boundaries, etc. that I don't really understand.&nbsp; I also know t=
hat this becomes extremely important for geometry.&nbsp; Many libraries hav=
e handcrafted optimizations for their algorthms with fixed size matrices/ve=
ctor (e.g. http://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html=
 shows the fixed sizes are all over the place).&nbsp; Think through inverti=
ng a matrix&nbsp; if you know it is 2x2 at compiletime and can dispatch to =
the closed form solution.&nbsp; They will handcraft assembler code to use S=
SE instructions for things like inner product if they know it fits in the r=
egister.&nbsp; I am always suspicious of premature optimization, but 1) the=
se are the sorts of optimizations that library vendors (ie. other people) c=
an write with extents known at compiletime, and we can't use them if we don=
't have the static size information. and (2) with scientific computing smal=
l performance changes can have enormous effects in many applciations.<br><b=
>For interoperability:</b> The ideal here would be that I can take an array=
_view and create adaptor to eigen/ublas/etc.&nbsp; then use their expressio=
n templates for the sematics.&nbsp; But to generate a static eigen vector/m=
atrix, I need to statically query the bounds of the array_view.<br><b>For c=
onformance: </b>Having static sizes can significantly improve correctness i=
n generic code at compiletime.&nbsp; For example, making sure that an inner=
 product of two 1D slices have the same length at compile time, etc.<div><b=
r></div><br><div><br></div><div><div>&nbsp;</div><div>On Tuesday, January 2=
8, 2014 11:45:23 AM UTC-8, Jesse Perla wrote:</div></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-=
left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">=
<div dir=3D"ltr"><div>I think this is exactly the right approach for the st=
andard. &nbsp;Instead of a container, standardize on a view for contiguous =
or strided memory as a method for access and interoperability, and then use=
 whatever containers you wish in the background. &nbsp;Then adaptors can be=
 written for the various scientific and numerical libraries to take one of =
these objects and convert into their expression template library. &nbsp;Thi=
s may have a chance to be a standard interoperability format, which is cruc=
ially needed for those doing numerical work. &nbsp;The only way to do it ri=
ght now is to pass around raw pointers between disparate libraries with all=
 sorts of manual conversion in the middle.</div><div><div>&nbsp;</div></div=
><div>As use cases for scientific programming, consider the following set o=
f tests for adaptation:</div><div><ol><li>Adaptor written which can "conver=
t" this 1D version of boost::ublas vector, and 2D of ublas::matrix, COIN-OR=
 dense matrix and vector, Python Numpy vector/matrix in C++ libraries, and =
matlab MEX extension<div>&nbsp;</div></li><li>Can an efficient adaptor be w=
ritten for boost numeric_bindings to call a variety of libraries (mostly im=
plementations of LAPACK, MUMPS, UMFPACK, etc. that are often column-major):=
 <a href=3D"https://svn.boost.org/svn/boost/sandbox/numeric_bindings/boost/=
numeric/bindings/" target=3D"_blank" onmousedown=3D"this.href=3D'https://ww=
w.google.com/url?q\75https%3A%2F%2Fsvn.boost.org%2Fsvn%2Fboost%2Fsandbox%2F=
numeric_bindings%2Fboost%2Fnumeric%2Fbindings%2F\46sa\75D\46sntz\0751\46usg=
\75AFQjCNFhNKBTnvDMHUmGVfcgXpWX0J7Mnw';return true;" onclick=3D"this.href=
=3D'https://www.google.com/url?q\75https%3A%2F%2Fsvn.boost.org%2Fsvn%2Fboos=
t%2Fsandbox%2Fnumeric_bindings%2Fboost%2Fnumeric%2Fbindings%2F\46sa\75D\46s=
ntz\0751\46usg\75AFQjCNFhNKBTnvDMHUmGVfcgXpWX0J7Mnw';return true;">https://=
svn.boost.org/svn/<wbr>boost/sandbox/numeric_<wbr>bindings/boost/numeric/<w=
br>bindings/</a>. &nbsp;To see if the correct accessors/types are in array_=
view, check out the example adaptor implementations in <a href=3D"https://s=
vn.boost.org/svn/boost/sandbox/numeric_bindings/boost/numeric/bindings/boos=
t/multi_array.hpp" target=3D"_blank" onmousedown=3D"this.href=3D'https://ww=
w.google.com/url?q\75https%3A%2F%2Fsvn.boost.org%2Fsvn%2Fboost%2Fsandbox%2F=
numeric_bindings%2Fboost%2Fnumeric%2Fbindings%2Fboost%2Fmulti_array.hpp\46s=
a\75D\46sntz\0751\46usg\75AFQjCNGQAR7YmaGZC7_Mvi8rVXkNhKYt4w';return true;"=
 onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fsvn.b=
oost.org%2Fsvn%2Fboost%2Fsandbox%2Fnumeric_bindings%2Fboost%2Fnumeric%2Fbin=
dings%2Fboost%2Fmulti_array.hpp\46sa\75D\46sntz\0751\46usg\75AFQjCNGQAR7Yma=
GZC7_Mvi8rVXkNhKYt4w';return true;">https://svn.boost.org/svn/<wbr>boost/sa=
ndbox/numeric_<wbr>bindings/boost/numeric/<wbr>bindings/boost/multi_array.h=
pp</a> and <a href=3D"https://svn.boost.org/svn/boost/sandbox/numeric_bindi=
ngs/boost/numeric/bindings/eigen/matrix.hpp" target=3D"_blank" onmousedown=
=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fsvn.boost.org=
%2Fsvn%2Fboost%2Fsandbox%2Fnumeric_bindings%2Fboost%2Fnumeric%2Fbindings%2F=
eigen%2Fmatrix.hpp\46sa\75D\46sntz\0751\46usg\75AFQjCNGDoUYcES8xClzou_kVsLY=
wCFvzsA';return true;" onclick=3D"this.href=3D'https://www.google.com/url?q=
\75https%3A%2F%2Fsvn.boost.org%2Fsvn%2Fboost%2Fsandbox%2Fnumeric_bindings%2=
Fboost%2Fnumeric%2Fbindings%2Feigen%2Fmatrix.hpp\46sa\75D\46sntz\0751\46usg=
\75AFQjCNGDoUYcES8xClzou_kVsLYwCFvzsA';return true;">https://svn.boost.org/=
svn/<wbr>boost/sandbox/numeric_<wbr>bindings/boost/numeric/<wbr>bindings/ei=
gen/matrix.hpp</a>. &nbsp;One requirement of this would be that the adaptor=
 class should have no storage of its own.<div>&nbsp;</div></li></ol></div><=
div><div>&nbsp;</div></div><div><div>&nbsp;</div></div><div>From the perspe=
ctive of scientific computing, the following are some concerns and addition=
s ordered by necessity:</div><div><ul><li>*Deal killer* Need Static row vs.=
 column major support!!!!</li><ul><li>A large number of scientific librarie=
s are written with column major data. &nbsp;This is especially true when ca=
lling high performance libraries written in fortran, or interfacing with ma=
tlab in MEX. &nbsp;EVERY major container used for numerical analysis has th=
is option.</li><li>boost::multi_array allows a runtime specification for th=
e ordering, but this is overkill. &nbsp;Better is a template parameter whic=
h determines the ordering for every dimension, and which can be queried by =
TMP used in the adaptors. &nbsp;Check out the ordering_type in boost::ublas=
, &nbsp;ColMajor vs. RowMajor in eigen, and the general_storage_order in bo=
ost::multi_array and seimilar ones in GLAS, MTL, etc.</li><li>If a particul=
ar user of the library (e.g. AMP) doesn't want to work with row-major, then=
 just a static_assert to reject.</li><li>I don't see how this could be adde=
d later without breaking a bunch of generic code. &nbsp;I also can't stress=
 enough how crucial this is, or it is pretty much useless for interoperabil=
ity (and, if you ask me, doesn't even belong in a C++ standard as it only c=
reates more implementation noise)</li></ul></ul></div><div><ul><li>*Deal ki=
ller* operator()(...) support</li><ul><li>A good portion of generic code is=
 written with operator(), especially using 2D specializations. &nbsp;If thi=
s doesn't have that as an accessing option, then it is too difficult to con=
vert existing code to be generic, which will undermine the use of this stan=
dard. &nbsp;operator() code is much more prevalent here than operator []</l=
i><li>This should be a variadic accessor for a list of extents, and doesn't=
 need to have an index_type version. &nbsp;Having a constexpr specializatio=
n would also be nice and allow optimizations, but is not necessary.</li><li=
>Examples: ublas, eigen, COIN-OR densematrix, and most others have this as =
their main way to access 1 and 2D matrices.</li></ul></ul></div><div><ul><l=
i>*Would be very nice* reshape() function</li><ul><li>It would be nice for =
the user to be able to reshape the array with the same allocated size. &nbs=
p;Not resize! &nbsp;An assert could ensure that the size remains the same.<=
/li><li>This is very nice for in-place algorithms using huge array's where =
the user doesn't want to, or doesn't have the resources to, reallocate an e=
ntire copy (e.g. transpose)</li><li>It also comes up a lot in numeric analy=
sis with tensor products and multivariate regressions. &nbsp;(e.g. using th=
e Kronecker product with vec, etc.)</li></ul></ul></div><div><ul><li>*Nice =
to have sooner rather than later* Fixed size extents</li><ul><li>A fixed_ar=
ray_view: Pass in a static list of extents as a variadic template argument.=
 &nbsp;Would not support a reshape() function as that would be a different =
type. &nbsp;Though a conversion function could be written.</li><li>This ena=
bles a huge number of optimizations and compile time extent checking for er=
rors. &nbsp;Since most of the 1 and 2d array libraries have this, we would =
be able to pass it around and adapt as required when using those algorithms=
 (also SIMD based optimizations)</li></ul></ul></div><div><ul><li>*Nice to =
have* RandomAccessContainer and other range-supported concepts, so that exi=
sting STL and future range algorithms could be used (especially for the 1D =
version)<div>&nbsp;</div></li></ul></div><div><div>&nbsp;</div></div></div>=
</blockquote></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_7155_10483635.1391646242555--

.
