Ignore:
Timestamp:
Oct 21, 2022, 12:13:25 PM (2 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, master
Children:
9e042d8
Parents:
8bd886e
Message:

Improve new-array subscripting to cover missing cases.

Missing cases include acknowledging a[0] and a[1] as required uses; therefore, give them
special overloads. Add comments to explain why.

Missing cases include test coverage of these overloads (where tests actually fail when an overload
is missing). Perhaps surprisingly, you need to use a lot of features at the same time for the need
for several overloads to obtain; make test coverage go there.

Also, switch thesis's demo of mutidimensional transposing/slicing to use (improved) libcfa ar
(pseudo-)trait, in place of former ix trait. Therefore, also port this demo to new array
syntax. (No changes to thesis discussion around this demo yet; these are still pending.) All
in, cause this thesis demo to be runnable again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/programs/hello-md.cfa

    r8bd886e ra5e2682  
    11#include "array.hfa"
    2 
    3 
    4 trait ix( C &, E &, ztype(N) ) {
    5     E & ?[?]( C &, ptrdiff_t );
    6     void __taglen( tag(C), tag(N) );
    7 };
    8 
    9 forall( ztype(Zn), ztype(S), Timmed &, Tbase & )
    10 void __taglen( tag(arpk(Zn, S, Timmed, Tbase)), tag(Zn) ) {}
    112
    123
     
    3829
    3930
    40 forall( ztype( N ) )
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40forall( [N] )
    4141void print1d_cstyle( array(float, N) & c );
    4242
    43 forall( C &, ztype( N ) | ix( C, float, N ) )
     43forall( [N], C & | ar( C, float, N ) )
    4444void print1d( C & c );
    4545
     
    5858
    5959
    60 forall( ztype( N ) )
     60forall( [N] )
    6161void print1d_cstyle( array(float, N) & c ) {
    62     for( i; z(N) ) {
     62    for( i; N ) {
    6363        printf("%.1f  ", c[i]);
    6464    }
     
    7878
    7979
    80 forall( C &, ztype( N ) | ix( C, float, N ) )
     80forall( [N], C & | ar( C, float, N ) )
    8181void print1d( C & c ) {
    82     for( i; z(N) ) {
     82    for( i; N ) {
    8383        printf("%.1f  ", c[i]);
    8484    }
     
    9999
    100100
    101 void fill( array(float, Z(5), Z(7)) & a ) {
     101void fill( array(float, 5, 7) & a ) {
    102102    for ( i; (ptrdiff_t) 5 ) {
    103103        for ( j; 7 ) {
    104             a[[i,j]] = 1.0 * i + 0.1 * j;
    105             printf("%.1f  ", a[[i,j]]);
     104            a[i,j] = 1.0 * i + 0.1 * j;
     105            printf("%.1f  ", a[i,j]);
    106106        }
    107107        printf("\n");
     
    118118
    119119
    120 array( float, Z(5), Z(7) ) a;
     120array( float, 5, 7 ) a;
    121121fill(a);
    122122/*
     
    148148
    149149
    150 print1d( a[[ 2, all ]] );  // 2.0  2.1  2.2  2.3  2.4  2.5  2.6
    151 print1d( a[[ all, 3 ]] );  // 0.3  1.3  2.3  3.3  4.3
     150print1d( a[ 2, all ] );  // 2.0  2.1  2.2  2.3  2.4  2.5  2.6
     151print1d( a[ all, 3 ] );  // 0.3  1.3  2.3  3.3  4.3
    152152
    153153
    154154
    155 print1d_cstyle( a[[ 2, all ]] );
     155print1d_cstyle( a[ 2, all ] );
    156156
    157157
     
    161161
    162162
    163 #ifdef SHOWERR1
     163#ifdef SHOW_ERROR_1
    164164
    165 print1d_cstyle( a[[ all, 2 ]] );  // bad
     165print1d_cstyle( a[ all, 2 ] );  // bad
    166166
    167167#endif
Note: See TracChangeset for help on using the changeset viewer.