Show
Ignore:
Timestamp:
04/30/08 16:05:32 (6 months ago)
Author:
Don Clugston
Message:

Added prod(). Use .ptr to get raw data, so it works with Bill Baxter's ArrayView?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/blade/BladeDemo.d

    r172 r187  
    11//  Written in the D programming language 1.0. 
    22/** 
    3 * BLADE 0.3Alpha -- Basic Linear Algebra D Expressions 
     3* BLADE Alpha -- Basic Linear Algebra D Expressions 
    44* 
    55*/ 
     
    99import std.stdio; 
    1010 
    11 // Local arrays in D aren't aligned to 128-bit boundaries. 
     11// Local arrays in D aren't currently aligned to 128-bit boundaries. 
    1212// In such cases, the library generates an 'SSE misalignment' assert error, 
    1313// to avoid segfaults. 
    1414// Use heap-allocated arrays, or static arrays (DMD 1.023 or later) 
    1515// cdouble[] always remains aligned, even when sliced. 
    16    
     16 
    1717void main() 
    18 {  
     18{ 
    1919    static z = [3.4, 565, 31.3, 0]; 
    2020    double [] a = new double[4]; 
     
    2929        r[i]= q[i]*2213.3L; 
    3030    } 
    31     double [4][] another = [[33.1, 4543, 43, 878.7],  
     31    double [4][] another = [[33.1, 4543, 43, 878.7], 
    3232                            [5.14, 455, 554, 2.43]]; 
    3333    real k=3.4; 
    34      
    3534    mixin(vectorize(` a += (d[2..$-1]*2.01*a[2]-another[][1])["abc".length-3..$]`)); 
    36     mixin(vectorize(" a-= 2.01*(        3.04+k)*r"));     
    37     
     35    mixin(vectorize(" a-= 2.01*(        3.04+k)*r")); 
     36 
    3837    mixin(vectorize("q+= q*2.01")); 
    3938    mixin(vectorize("another[0]+=r-=another[0]+another[0]")); 
    40     
     39 
    4140    // All of the next four are equivalent 
    4241    mixin(vectorize("a+=6*another[1,0..$]")); 
    4342    mixin(vectorize("a+=6*(another[1,0..$]+another[1,0..$])")); 
    44    
     43 
    4544 
    4645    mixin(vectorize("a+=6*another[1][0..$]")); 
     
    4948    // I don't think I'll support this syntax long-term. 
    5049    mixin(vectorize("a+=6*another[1,[0,$]]")); 
    51      
     50 
    5251    // Strided vector 
    5352    mixin(vectorize("another[0..$,1]=6*a[0..2]")); 
     
    6160   mixin(vectorize("a = -a")); 
    6261   mixin(vectorize("u = sum(sqrt(abs(p))) + sum(sqrt(abs(q)))")); 
     62   mixin(vectorize("u = prod(q)")); 
     63    writefln("a=", a); 
    6364 
    64     writefln("a=", a); 
    6565}