www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - more n-d arrays

reply Ben Hinkle <bhinkle4 juno.com> writes:
Attached are two files (updates of the same ones from before) with some more
hacking on N-D arrays using expression templates.
The 2D matrices seem to be about 10% slower than static 2D matrices. I
haven't timed the higher dimensions. Supported operations include indexing
and slicing and setting the slice step. For example:
  NDArray!(int,3) A;
  ...
  // index an element
  A[2][3][4];

  // create a sub-array
  A[1..4][3][0..4]

  // create a sub-array with a stepsize of 2 in the first dimension     
  A[1..4].by(2)[3][4] 

Anyway, I'll probably continue poking around with this stuff and trying to
get more of Norbert's ideas prototyped. There are probably lots of
performance issues with what I wrote since it relies on the compiler to
inline lots of templated code but at least the 2D case seems pretty good
for now.

-Ben
May 12 2004
next sibling parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
Looks very intersting but:
if i try to compile the example without -release i get linker error.
And when i add -release i get compiler error:

ndarray.d(249): 'make(cast(NDArray *)(#this.data),#inds)' is not an lvalue

Why do i get this?


"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c7v52k$1g3d$1 digitaldaemon.com...
 Attached are two files (updates of the same ones from before) with some
more
 hacking on N-D arrays using expression templates.
 The 2D matrices seem to be about 10% slower than static 2D matrices. I
 haven't timed the higher dimensions. Supported operations include indexing
 and slicing and setting the slice step. For example:
   NDArray!(int,3) A;
   ...
   // index an element
   A[2][3][4];

   // create a sub-array
   A[1..4][3][0..4]

   // create a sub-array with a stepsize of 2 in the first dimension
   A[1..4].by(2)[3][4]

 Anyway, I'll probably continue poking around with this stuff and trying to
 get more of Norbert's ideas prototyped. There are probably lots of
 performance issues with what I wrote since it relies on the compiler to
 inline lots of templated code but at least the 2D case seems pretty good
 for now.

 -Ben
May 13 2004
parent reply Ben Hinkle <bhinkle4 juno.com> writes:
Ivan Senji wrote:

 Looks very intersting but:
 if i try to compile the example without -release i get linker error.
What is the link error? I don't get any errors with dmd. I just tried gdc and I had to make the private nd_elems public but otherwise everything looked fine.
 And when i add -release i get compiler error:
 
 ndarray.d(249): 'make(cast(NDArray *)(#this.data),#inds)' is not an lvalue
 
 Why do i get this?
I don't know. I'll check it out. I compiled the 2D stuff with -release just fine before writing the n-d case. -Ben
May 13 2004
parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c7vqus$2h2o$1 digitaldaemon.com...
 Ivan Senji wrote:

 Looks very intersting but:
 if i try to compile the example without -release i get linker error.
What is the link error? I don't get any errors with dmd. I just tried gdc and I had to make the private nd_elems public but otherwise everything looked fine.
With only this in main: NDArray!(double,3) x2 = NDArray!(double,3)(null,3,4,5); and without -release i get: E:\DLANGU~1\learn_d\TESTBE~1\testBensMDArray.obj(testBensMDArray) Error 42: Symbol Undefined _array_7ndarray
 And when i add -release i get compiler error:

 ndarray.d(249): 'make(cast(NDArray *)(#this.data),#inds)' is not an
lvalue
 Why do i get this?
I don't know. I'll check it out. I compiled the 2D stuff with -release
just
 fine before writing the n-d case.

 -Ben
May 13 2004
next sibling parent Ben Hinkle <bhinkle4 juno.com> writes:
On Thu, 13 May 2004 16:39:06 +0200, "Ivan Senji"
<ivan.senji public.srce.hr> wrote:

"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c7vqus$2h2o$1 digitaldaemon.com...
 Ivan Senji wrote:

 Looks very intersting but:
 if i try to compile the example without -release i get linker error.
What is the link error? I don't get any errors with dmd. I just tried gdc and I had to make the private nd_elems public but otherwise everything looked fine.
With only this in main: NDArray!(double,3) x2 = NDArray!(double,3)(null,3,4,5); and without -release i get: E:\DLANGU~1\learn_d\TESTBE~1\testBensMDArray.obj(testBensMDArray) Error 42: Symbol Undefined _array_7ndarray
 And when i add -release i get compiler error:

 ndarray.d(249): 'make(cast(NDArray *)(#this.data),#inds)' is not an
lvalue
 Why do i get this?
I don't know. I'll check it out. I compiled the 2D stuff with -release
just
 fine before writing the n-d case.

 -Ben
I re-organized some return statements and got rid of the opCall syntax and that seemed to make the linking happier (at least on Windows). I couldn't reproduce the "_array_7ndarray undefined" error - did you include both ndarray.d and nd_example.d on the same call to dmd? I've attached modified versions of ndarray.d and nd_example.d with the tweaks for -inline and -release.
May 13 2004
prev sibling parent reply Ben Hinkle <bhinkle4 juno.com> writes:
begin 644 nd_example.d

M871E(&$ ,T0 ;6%T<FEX('5S:6YG(&=E;F5R:6, =&5M<&QA=&4-"B` 3D1!





M"B` <')I;G1F*"( ,T0 87)R87DB*3L-"B` +R\ <')I;G0 <F5S=6QT(&%S
M(&$ 9FQA="`Q1"!A<G)A>0T*("!I;G0 :SL-"B` 9F]R("AK/3`[(&L\,RHT
M*C4[(&LK*RD >PT*("` (&EF("AK)2 S*C0I(#T


M8GDH,BE;,EU;73L-"B` <')I;G1F*")<;B!3=6(M87)R87D =VET:"`E9"!E

M(&XR(#P >2YL96YG=&A;,ET[(&XR*RLI('L-"B` ("!F;W( *&EN="!N,3TP

M,#TP.R!N,"`\('DN;&5N9W1H6S!=.R!N,"LK+&LK*RD >PT*"6EF("AK)2AY
M+FQE;F=T:%LP72IY+FQE;F=T:%LQ72D /3T ,"D <')I;G1F*")<;B(I.PT*
M"7!R:6YT9B B)2XS9"`B+"!C87-T*&EN="EY6VXP75MN,5U;;C)=*3L-"B` 


`
end

begin 644 ndarray.d
M+RH-"B`J($XM1&EM96YS:6]N86P 87)R87D =&5M<&QA=&4 87!P<F]X:6UA
M=&EN9R!T:&4 <W!E8R!O9 T*("H 3F]R8F5R="!.96UE8R!A=`T*("H :'1T
M<#HO+VAO;65P86=E<RYU;FDM<F5G96YS8G5R9RYD92]^;F5N,3`P,34O9&]C


M<FEC(&-O;'5M;BUO<FEE;G1E9"!.+61I;65N<VEO;F%L(&%R<F%Y(&]F(%0-
M"G-T<G5C="!.1$%R<F%Y*%0L:6YT($XI('L-"B` 5"`J9&%T83L-"B` =6EN


M+BX-"B` <W1A=&EC($Y$07)R87D ;6%K92A4*B!D871A+"!U:6YT(' P+"XN
M+BD >PT*("` ($Y$07)R87D <F5S.PT*("` ('5I;G1;72!L96X /2`H)G P
M*5LP+BY.73L +R\ ;F]T('9E<GD <&]R=&%B;&4L('5S92!S=&1A<F<-"B` 
M("!R97,N;&5N9W1H6UT /2!L96Y;73L-"B` ("!R97,N<W1R:61E6S!=(#T 
M,3L-"B` ("!F;W( *&EN="!K(#T ,3L :R`\($X[("LK:RD >PT*("` ("` 
M<F5S+G-T<FED95MK72`](')E<RYL96YG=&A;:RTQ72IR97,N<W1R:61E6VLM

M=&$ /2!N97< 5%MR97,N<W1R:61E6TXM,5TJ<F5S+FQE;F=T:%M.+3%=73L-



M(&5X<')E<W-I;VYS+B!4:&4 <V5C;VYD+71O+6QA<W0 97AP<F5S<VEO;B!I
M<R!S:6YG;&5D(&]U=`T*("`O+R!B96-A=7-E('1H92!R971U<FX ='EP97, 

M9F9E<F5N="!T:&%N('1H92!O<$EN9&5X(&%N9"!O<%-L:6-E(')E='5R;B!T

M97AP<F5S:6]N+B!!<R!S;V]N(&%S(&$ <VQI8V4 97AP<F5S<VEO;B`-"B` 
M+R\ ;V-C=7)S('1H92!E;G1I<F4 ;W!E<F%T:6]N(&)E8V]M97, 82!S;&EC
M92!E>'!R97-S:6]N(&%N9"!T:&4-"B` +R\ 96YD(')E<W5L="!W:6QL(&)E
M(&%N($Y$07)R87DN($]T:&5R=VES92!T:&4 96YD(')E<W5L="!I<R!T>7!E

M(&-A;FYO="!B92!A<W-I9VYE9"!T;R!A<R!I; T*("`O+R` 05LP+BXR75LS

M(&5X<')E<W-I;VYS('-P96-I86QI>F5D(&9O<B!S96-O;F0M=&\M;&%S=`T*


M("\O('=E<F4 86QS;R!I;F1E>"!E>'!R+ T*("!P<FEV871E('-T<G5C="!)


M("` <W1A=&EC("Y.1$%R<F%Y(2A4+$XI+DEN9&5X17AP<B$H,2D ;6%K92A.
M1$%R<F%Y("IX+`T*"0D)"2!U:6YT6TXM,5T ;BD >PT*("` ("` +DY$07)R


M.PT*("` ('T-" T*("` ("\O($$J6VY=('=H97)E("H 87)E(&]P26YD97  


M=6T *ST >"YS=')I9&5;:UTJ<')E=E]N6VM=.PT*("` ("` <F5T=7)N(' N
M9&%T85MS=6T *R!X+G-T<FED95M.+3%=*FY=.PT*("` ('T-" T*("` ("\O
M($$J6VY=(#T =F%L('=H97)E("H 87)E(&]P26YD97  8V%L;',-"B` ("!V
M;VED(&]P26YD97 H=6EN="!N+"!4('9A;"D >PT*("` ("` =6EN="!S=6T 
M/2`P.PT*("` ("` 9F]R("AI;G0 :STP.R!K(#P 3BTQ.R`K*VLI('L-" ES
M=6T *ST >"YS=')I9&5;:UTJ<')E=E]N6VM=.PT*("` ("` ?0T*("` ("` 


M("` ($Y$07)R87D ;W!3;&EC92AU:6YT(&DL('5I;G0 :BD >PT*("` ("` 

M*&EN="!K/3`[(&L /"!.+3$[("LK:RD >PT*"7-U;2`K/2!X+G-T<FED95MK

M.PT*("` ("` <F5S+G-T<FED95M=(#T >"YS=')I9&5;73L-"B` ("` (')E
M<RYL96YG=&A;3BTQ72`](&HM:3L-"B` ("` (')E<RYD871A(#T )G N9&%T
M85MS=6T *R!X+G-T<FED95M.+3%=*FE=.PT*("` ("` <F5T=7)N(')E<SL-



M:79A=&4 <W1R=6-T(&9O<B!S;&EC:6YG(&5X<')E<W-I;VYS('-P96-I86QI
M>F5D(&9O<B!L87-T(&1I;65N<VEO; T*("!P<FEV871E('-T<G5C="!3;&EC

M+3%=('!R979?:3L-"B` ("!U:6YT6TXM,5T <')E=E]J.PT*("` ('5I;G1;

M('1H92!S96-O;F0M=&\M;&%S="!D:6T-"B` ("!S=&%T:6, +DY$07)R87DA


M"2` ("` =6EN=%M.+3%=('-T97`I('L-"B` ("` ("Y.1$%R<F%Y(2A4+$XI
M+E-L:6-E17AP<B$H,2D <F5S.PT*("` ("` <F5S+G!R979?:5M=(#T :5M=
M.PT*("` ("` <F5S+G!R979?:EM=(#T :EM=.PT*("` ("` <F5S+G!R979?
M<W1E<%M=(#T <W1E<%M=.PT*("` ("` <F5S+G  /2!X.PT*("` ("` <F5T


M<W1E<"D >PT*("` ("` +DY$07)R87DA*%0L3BDN4VQI8V5%>'!R(2 Q*2!R

M<F5V7VE;73L-"B` ("` (')E<RYP<F5V7VI;72`]('!R979?:EM=.PT*("` 
M("` <F5S+G!R979?<W1E<%M=(#T
M<')E=E]S=&5P6TXM,ET /2!S=&5P.PT*("` ("` <F5T=7)N(')E<SL-"B` 


M"B` ("` (&9O<B`H:6YT(&L],#L
M;F=T:%MK72`](&YD7VYE;&5M<RAP<F5V7VI;:UTM<')E=E]I6VM=+'!R979?

M<FED95MK73L-"B` ("` ('T-"B` ("` (')E<RYL96YG=&A;3BTQ72`](&HM


M+3$[("LK:RD >PT*"7-U;2`K/2!R97,N<W1R:61E6VM=*G!R979?:5MK73L-
M"B` ("` ('T-"B` ("` (')E<RYD871A(#T )G N9&%T85MS=6T *R!X+G-T



M"B` ("`O+R!!*EMI+BYJ75MN70T*("` ($Y$07)R87D ;W!);F1E>"AU:6YT

M('T-" T*("`O+R!P<FEV871E('-T<G5C="!F;W( <VQI8V5I;F< 97AP<F5S


M:6-E17AP<BAU:6YT($TI('L-"B` ("!.1$%R<F%Y("IX.PT*("` ('5I;G1;



M(2A4+$XI+E-L:6-E17AP<B$H32D ;6%K92A.1$%R<F%Y("IX+`T*"0D)"0D 
M("` ('5I;G1;3BTQ72!I+`T*"0D)"0D ("` ('5I;G1;3BTQ72!J+`T*"0D)

M*2Y3;&EC945X<'(A*$TI(')E<SL-"B` ("` (')E<RYP<F5V7VE;72`](&E;
M73L-"B` ("` (')E<RYP<F5V7VI;72`](&I;73L-"B` ("` (')E<RYP<F5V
M7W-T97!;72`]('-T97!;73L-"B` ("` (')E<RYX(#T >#L-"B` ("` (')E

M("` +DY$07)R87DA*%0L3BDN4VQI8V5%>'!R(2A-*2!B>2AU:6YT('-T97`I
M('L-"B` ("` ('5I;G1;3BTQ72!A<W1E<#L-"B` ("` (&%S=&5P6UT /2!P

M("!R971U<FX +DY$07)R87DA*%0L3BDN4VQI8V5%>'!R(2A-*2YM86ME*' L

M:EU;:3(N+FHR72H-"B` ("`N3D1!<G)A>2$H5"Q.*2Y3;&EC945X<'(A*$TM
M,2D ;W!3;&EC92AU:6YT(&DL('5I;G0 :BD >PT*("` ("` <')E=E]I6TXM
M35T /2!I.PT*("` ("` <')E=E]J6TXM35T /2!J.PT*("` ("` <F5T=7)N
M("Y.1$%R<F%Y(2A4+$XI+E-L:6-E17AP<B$H32TQ*2YM86ME*' L<')E=E]I
M+'!R979?:BQP<F5V7W-T97`I.PT*("` ('T-" T*("` ("\O($$J6VDN+FI=


M.PT*("` ('T-" T*("` ("\O($$J6VE=* T*("` ("Y.1$%R<F%Y(2A4+$XI
M+E-L:6-E17AP<B$H32TQ*2!O<$EN9&5X*'5I;G0 :2D >PT*("` ("` <F5T

M=F%T92!S=')U8W0 9F]R(&EN9&5X:6YG(&5X<')E<W-I;VYS(&9O<B!R961U
M8VEN9R!D:6UE;G-I;VX 8GD ,0T*("`O+R!W:71H(&QU8VL =&AI<R!C86X 
M8F4 :6YL:6YE9`T*("!P<FEV871E('-T<G5C="!);F1E>$5X<'(H=6EN="!-


M87DA*%0L3BDN26YD97A%>'!R(2A-*2!M86ME*$Y$07)R87D *G L(`T*"0D)

M;F1E>$5X<'(A*$TI(')E<SL-"B` ("` (')E<RYX(#T >#L-"B` ("` (')E


M<B$H32TQ*2!O<$EN9&5X*'5I;G0 ;BD >PT*("` ("` =6EN=%M.+3%=(&EN


M<F5S(#T +DY$07)R87DA*%0L3BDN26YD97A%>'!R(2A-+3$I+FUA:V4H>"QI

M:2XN:ETJ(`T*("` ("Y.1$%R<F%Y(2A4+$XI+E-L:6-E17AP<B$H32TQ*2!O
M<%-L:6-E*'5I;G0 :2QU:6YT(&HI('L-"B` ("` ('5I;G1;3BTQ72!P<F5V

M('!R979?<W1E<#L-"B` ("` (&9O<B`H:6YT(&L],#L :SQ-+3$[("LK:RD 
M>PT*"7!R979?:5MK72`]('!R979?;EMK73L-" EP<F5V7VI;:UT /2!P<F5V
M7VY;:UTK,3L-"B` ("` ('T-"B` ("` ('!R979?:5M-+3%=(#T :3L-"B` 
M("` ('!R979?:EM-+3%=(#T :CL-"B` ("` ('!R979?<W1E<%M=(#T ,3L-
M"B` ("` ("Y.1$%R<F%Y(2A4+$XI+E-L:6-E17AP<B$H32TQ*2!R97, /2`N
M3D1!<G)A>2$H5"Q.*2Y3;&EC945X<'(A*$TM,2DN;6%K92AX+"!P<F5V7VDL


M<'(A*$TM,2D ;W!3;&EC92 I('L-" DN3D1!<G)A>2$H5"Q.*2Y3;&EC945X
M<'(A*$TM,2D <F5S(#T ;W!3;&EC92 P+' N;&5N9W1H6TXM35TI.PT*"7)E



M07)R87DA*%0L3BDN26YD97A%>'!R(2A.+3$I(')E<R`]+DY$07)R87DA*%0L
M3BDN26YD97A%>'!R(2A.+3$I+FUA:V4H8V%S="A.1$%R<F%Y*BDF9&%T82P 


M;G0 :2QU:6YT(&HI('L-"B` ("!U:6YT6TXM,5T <')E=E]I.PT*("` ('5I


M=E]S=&5P6UT /2`Q.PT*("` ("Y.1$%R<F%Y(2A4+$XI+E-L:6-E17AP<B$H





M>'!R(2A.+3$I(')E<R`](&]P4VQI8V4H,"QL96YG=&A;,%TI.PT*("` (')E

M(&)Y*'5I;G0 <W1E<"D >PT*("` ($Y$07)R87D <F5S.PT*("` (')E<RYL
M96YG=&A;72`](&QE;F=T:%M=.PT*("` (')E<RYS=')I9&5;72`]('-T<FED
M95M=.PT*("` (')E<RYL96YG=&A;3BTQ72`](&YD7VYE;&5M<RAL96YG=&A;
M3BTQ72QS=&5P*3L-"B` ("!R97,N<W1R:61E6TXM,5T /2!S=&5P*G-T<FED
M95M.+3%=.PT*("` (')E<RYD871A(#T 9&%T83L-"B` ("!R971U<FX <F5S

M>0T*("!U:6YT(&YE;&5M<R I('L-"B` ("!U:6YT('1O=&%L(#T ,3L-"B` 
M("!F;W( *&EN="!K/3`[(&L /"!..R!K*RLI(`T*("` ("` =&]T86P *CT 
M;&5N9W1H6VM=.PT*("` (')E='5R;B!T;W1A;#L-
M+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O
M+R\O+R\O+R\O+R\-"B\O(%1W;R!D:6UE;G-I;VYA;"!A<G)A>2!I<R!S<&5C

M*%0L:6YT($XZ,BD >PT*("!4("ID871A.PT*("!U:6YT6S)=(&QE;F=T:#L-




M1$%R<F%Y(&UA:V4H5"H 9&%T82P =6EN="!X,"P =6EN="!X,2D >PT*("` 
M($Y$07)R87D <F5S.PT*("` (')E<RYL96YG=&A;,%T /2!X,#L-"B` ("!R
M97,N;&5N9W1H6S%=(#T
M("` <F5S+G-T<FED95LQ72`](' P.PT*("` (')E<RYD871A(#T 9&%T83L-

M9&EA=&4 <W1R=6-T=7)E(&9O<B!I;F1E>&EN9R!E>'!R97-S:6]N<PT*("!P


M:6YT(&XI('L-"B` ("` ("\O(&)O=6YD<RUC:&5C:R!O;B!L96YG=& -"B` 
M("` (')E='5R;B!X+F1A=&%;;2IX+G-T<FED95LP72`K(&XJ>"YS=')I9&5;
M,5U=.PT*("` ('T-" T*("` ("\O($%;;5U;;ET /2!V86P-"B` ("!V;VED


M>"YS=')I9&5;,5U=(#T =F%L.PT*("` ("` +R\ ("` ("!X+F1A=&%;;2`K
M(&XJ>"YS=')I9&5;,5U=(#T =F%L.PT*("` ('T-" T*("` ("\O($%;;5U;
M:2XN:ET-"B` ("!.1$%R<F%Y(&]P4VQI8V4H=6EN="!I+"!U:6YT(&HI('L-
M"B` ("` ($Y$07)R87D <F5S.PT*("` ("` <F5S+F1A=&$ /2`F>"YD871A
M6VTJ>"YS=')I9&5;,%T *R!I*G N<W1R:61E6S%=73L-"B` ("` (')E<RYL
M96YG=&A;,%T /2`Q.PT*("` ("` <F5S+FQE;F=T:%LQ72`](&HM:3L-"B` 
M("` (')E<RYS=')I9&5;,%T /2!X+G-T<FED95LP73L-"B` ("` (')E<RYS




M("` =6EN="!J.PT*("` ('5I;G0 <W1E<#L-" T*("` ("\O($%;:2XN:EU;

M<F%Y(')E<SL-"B` ("` (')E<RYL96YG=&A;,%T /2!N9%]N96QE;7,H:BUI

M<W1R:61E6S!=(#T <W1E<"IX+G-T<FED95LP73L-"B` ("` (')E<RYS=')I
M9&5;,5T /2!X+G-T<FED95LQ73L-"B` ("` (')E<RYD871A(#T )G N9&%T

M<FX <F5S.PT*("` ('T-" T*("` ("\O($%;:2XN:EU;:3(N+FHR70T*("` 

M1$%R<F%Y(')E<SL-"B` ("` (')E<RYL96YG=&A;,%T /2!N9%]N96QE;7,H
M:BUI+'-T97`I.PT*("` ("` <F5S+FQE;F=T:%LQ72`](&HR+6DR.PT*("` 

M97,N<W1R:61E6S%=(#T
M("!R97,N9&%T82`]("9X+F1A=&%;:2IX+G-T<FED95LP72`K(' N<W1R:61E

M05MI+BYJ72YB>2AS=&5P*2H-"B` ("!3;&EC945X<'( 8GDH=6EN="!S=&5P

M("` ("` <F5S+FH /2!J.PT*("` ("` <F5S+G-T97` /2!S=&5P.PT*("` 

M" T*("`O+R!!6RI=6VDR+BYJ,ETN8GDH<W1E<"D-"B` 3D1!<G)A>2!B>2AU
M:6YT('-T97`I('L-"B` ("!.1$%R<F%Y(')E<SL-"B` ("!R97,N;&5N9W1H
M6S!=(#T ;&5N9W1H6S!=.PT*("` (')E<RYL96YG=&A;,5T /2!N9%]N96QE
M;7,H;&5N9W1H6S%=+'-T97`I.PT*("` (')E<RYS=')I9&5;,%T /2!S=')I

M("` (')E<RYD871A(#T
M"B` +R\ 05MM72H-"B` 26YD97A%>'!R(&]P26YD97 H:6YT(&TI('L-"B` 
M("!);F1E>$5X<'( <F5S.PT*("` (')E<RYX(#T 8V%S="A.1$%R<F%Y*BDF



M<W0H3D1!<G)A>2HI)F1A=&$[("\O(&YO(")T:&ES(B!F;W( <W1R=6-T+"!H




M(&EN('1H92!A<G)A>0T*("!U:6YT(&YE;&5M<R I('L-"B` ("!R971U<FX 



M73L-"B` ("!R97,N;&5N9W1H6S%=(#T ,3L-"B` ("!R97,N<W1R:61E6S!=
M(#T <W1R:61E6S!=.PT*("` (')E<RYS=')I9&5;,5T /2`Q.PT*("` (')E
M<RYD871A(#T 9&%T82MS=')I9&5;,5TJ;CL-"B` ("!R971U<FX <F5S.PT*

M<F%Y(')O=RAU:6YT(&TI('L-"B` ("!.1$%R<F%Y(')E<SL-"B` ("!R97,N
M;&5N9W1H6S!=(#T ,3L-"B` ("!R97,N;&5N9W1H6S%=(#T ;&5N9W1H6S%=
M.PT*("` (')E<RYS=')I9&5;,%T /2`Q.PT*("` (')E<RYS=')I9&5;,5T 




M72`](' P.PT*("` (')E<RYL96YG=&A;,5T /2!X,3L-"B` ("!R97,N9&%T

M:V4 36%T<FEX(&$ ;FEC92!A;&EA<R!F;W( ,D0 87)R87D-"G1E;7!L871E


M(&YD7VYE;&5M<RAU:6YT(&XL('5I;G0 <W1E<"D >PT*("!I9B`H;B`]/2`P



M+60 87)R87ES('5S:6YG(&EN9&5X(&%N9"!S;&EC:6YG(&5X<')E<W-I;VX 
M=&5M<&QA=&5S('=I=& -"B`J('-P96-I86QI>F%T:6]N<R!F;W( ,D0 ;6%T
M<FEC97, 9F]R(&)E='1E<B!P97)F;W)M86YC92X-"B`J(%1H92!C;V1E(&ES
M('!U="!I;G1O('1H92!P=6)L:6, 9&]M86EN(&%N9"!C86X 8F4 =7-E9"!F


`
end
May 13 2004
next sibling parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
It works now and the slicing works great, i love it :)
But i am having some more problems but this looks like a compiler
bug to me:
I wrote a function to print the array:

void printArray(NDArray!(double,3) y)
{
 int k=0;
 for(int n2=0; n2 < y.length[2]; n2++)
 {
      for(int n1=0; n1 < y.length[1]; n1++)
      {
           for(int n0=0; n0 < y.length[0]; n0++,k++)
           {
                printf("%d",cast(int)y[n0][n1][n2]);
           }
           printf("\n");
      }
      printf("\n");
  }
}

But compiler says:
E:\D language\learn_d\testBensMDArray\ndarray.d(16): template NDArray(T,int
N) is used as a type

To fix it i have to write:
alias NDArray!(double,3) array3;

and change everywhere in the code "NDArray!(double,3)"  to "array3" and it
works then.
May 13 2004
prev sibling parent =?iso-8859-1?q?Knud_S=F8rensen?= <knud NetRunner.all-technology.com> writes:
On Thu, 13 May 2004 12:36:00 -0400, Ben Hinkle wrote:

 
 import ndarray;
 
 
 int main() {
 
   // create a 3D matrix using generic template
   NDArray!(double,3) x2 = NDArray!(double,3).make(null,3,4,5);
 
   for (int n2=0; n2<5; n2++) {
     for (int n1=0; n1<4; n1++) {
       for (int n0=0; n0<3; n0++) {
 	x2[n0][n1][n2] = 100*n2 + 10*n1 + n0;
       }
     }
   }
I really don't like this notation. The operation is parallel in nature but the for loop make it serial. I do not know how easy it is for the compiler to recognize and parallelize code like this but I would prefer a notation which don't specify a order of execution. Here I use the notation I suggested a while back in a post name Einstein summation index(3) i0; index(4) i1; index(5) i2; x2[i0][i1][i2]=i2*100+i1*10+i0; With this notation the loops are implicit so the compiler can parallelize away; You can think of i0,i1,i2 as named slices. the notation might be slice i0=0..2,i1=0..3,i2=0..4; instead. Knud
May 13 2004
prev sibling parent reply Norbert Nemec <Norbert.Nemec gmx.de> writes:
Good work. I just hope you don't expect to bring this to production quality.
It is a great case study demonstrating some details, but I would not want
to use that in production code. :-)

Especially the stepwise indexing/slicing: it is nice to see that this is
possible, but if this kind of coding should make it into a standard
library, we would be better of sticking with good old C++...

One remark, by the way: If opCall is supposed to create a C-aligned array
(which I would think the reasonable default) the *last* stride should be 1.
What your code is generating, is a Fortran-aligned array.
May 13 2004
parent reply Ben Hinkle <bhinkle4 juno.com> writes:
Norbert Nemec wrote:

 Good work. I just hope you don't expect to bring this to production
 quality. It is a great case study demonstrating some details, but I would
 not want to use that in production code. :-)
The 2D matrices are fast enough to be useful, I think. I haven't done any profiling of the nd stuff so I have no idea how much could be inlined but it all uses structs and direct calls so theoretically it should be fast. Of course building in nd-arrays would most likely give the fastest code and best error messages, etc.
 Especially the stepwise indexing/slicing: it is nice to see that this is
 possible, but if this kind of coding should make it into a standard
 library, we would be better of sticking with good old C++...
Hmm. and I went and added comments and everything :-) I guess code is always simpler when you write it.
 One remark, by the way: If opCall is supposed to create a C-aligned array
 (which I would think the reasonable default) the *last* stride should be
 1. What your code is generating, is a Fortran-aligned array.
I want Fortran-aligned for 2 reasons: Fortran and MATLAB. For numerical stuff I prefer interoperating with those two over C compatibility. I suppose since I work for the makers of MATLAB I have a bias but I've been trying to keep that in check.
May 13 2004
parent Norbert Nemec <Norbert.Nemec gmx.de> writes:
Ben Hinkle wrote:

 Norbert Nemec wrote:
 
 Good work. I just hope you don't expect to bring this to production
 quality. It is a great case study demonstrating some details, but I would
 not want to use that in production code. :-)
The 2D matrices are fast enough to be useful, I think. I haven't done any profiling of the nd stuff so I have no idea how much could be inlined but it all uses structs and direct calls so theoretically it should be fast. Of course building in nd-arrays would most likely give the fastest code and best error messages, etc.
 Especially the stepwise indexing/slicing: it is nice to see that this is
 possible, but if this kind of coding should make it into a standard
 library, we would be better of sticking with good old C++...
Hmm. and I went and added comments and everything :-) I guess code is always simpler when you write it.
Well, I guess, I judged by first impression. I did not really dig into all the details, but I'm pretty sure, the module is still small enough to understand it all. Anyway: you probably have to confess, that many of the design decision were not guided by what you would have liked to do, but more by what the language allows you to do. Especially, the stepwise unpacking is one example for that. In C++, one could have done without it and gotten more functionality with a cleaner syntax and less effort. This is what I meant: code like that - working more "against" than "within" the language - may be a interesting case study and may even be usable so some extent, but my vision of a computer language with powerful arrays looks somewhat different...
 I want Fortran-aligned for 2 reasons: Fortran and MATLAB. For numerical
 stuff I prefer interoperating with those two over C compatibility. I
 suppose since I work for the makers of MATLAB I have a bias but I've been
 trying to keep that in check.
OK, I might actually have to consider that. Up to now, I just assumed that D should have C-style arrays as default. Now, actually, I'm not really sure about that any more...
May 13 2004