Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1953

Show
Ignore:
Timestamp:
09/04/10 14:34:11 (14 years ago)
Author:
dsimcha
Message:

Bug 4810: dotProduct problem with ints

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/changelog.dd

    r1948 r1953  
    4343    $(LI $(BUGZILLA 4381): Length attribute for std.typecons.Tuple.) 
    4444    $(LI $(BUGZILLA 4387): std.range.Cycle assumes lvalue elements.) 
    4545    $(LI $(BUGZILLA 4388): std.range.Radial assumes lvalue elements.) 
    4646    $(LI $(BUGZILLA 4403): std.range.FrontTransversal assumes lvalue elements.) 
    4747    $(LI $(BUGZILLA 4404): std.range.Transversal assumes lvalue elements.) 
    4848    $(LI $(BUGZILLA 4455): Taking the sqrt of an integer shouldn't require an explicit cast.) 
    4949    $(LI $(BUGZILLA 4464): std.range.take does not always return Take!R.) 
    5050    $(LI $(BUGZILLA 4603): array(iota(1, 0)) error.) 
    5151    $(LI $(BUGZILLA 4700): to!float("0") fails) 
    5252    $(LI $(BUGZILLA 4789): std.algorithm.sort bug) 
     53    $(LI $(BUGZILLA 4810): dotProduct problem with ints) 
    5354    ) 
    5455) 
    5556 
    5657 
    5758<div id=version> 
    5859$(UL 
    5960    $(NEW 049) 
    6061    $(NEW 048) 
    6162    $(NEW 047) 
    6263    $(NEW 046) 
  • trunk/phobos/std/numeric.d

    r1839 r1953  
    536536 
    537537unittest 
    538538{ 
    539539    alias TypeTuple!( 
    540540        CustomFloat!(5, 10), 
    541541        CustomFloat!(5, 11, CustomFloatFlags.ieee ^ CustomFloatFlags.signed), 
    542542        CustomFloat!(1, 15, CustomFloatFlags.ieee ^ CustomFloatFlags.signed), 
    543543        CustomFloat!(4, 3, CustomFloatFlags.ieee | CustomFloatFlags.probability ^ CustomFloatFlags.signed) 
    544544 
    545545        ) FPTypes; 
    546  
    547     pragma(msg, " --- std.numeric(" ~ __LINE__.stringof ~ ") CustomFloat broken test ---"); 
    548  
    549546 
    550547    foreach (F; FPTypes) 
    551548    { 
    552549        auto x = F(0.125); 
    553550        assert(x.get!float == 0.125F); 
    554551        assert(x.get!double == 0.125); 
    555552 
    556553        x -= 0.0625; 
    557554        assert(x.get!float == 0.0625F); 
    558555        assert(x.get!double == 0.0625); 
     
    12361233    return result; 
    12371234} 
    12381235 
    12391236/// Ditto 
    12401237Unqual!(CommonType!(F1, F2)) 
    12411238dotProduct(F1, F2)(in F1[] avector, in F2[] bvector) 
    12421239{ 
    12431240    immutable n = avector.length; 
    12441241    assert(n == bvector.length); 
    12451242    auto avec = avector.ptr, bvec = bvector.ptr; 
    1246     typeof(return) sum0 = 0.0, sum1 = 0.0; 
     1243    typeof(return) sum0 = 0, sum1 = 0; 
    12471244 
    12481245    const all_endp = avec + n; 
    12491246    const smallblock_endp = avec + (n & ~3); 
    12501247    const bigblock_endp = avec + (n & ~15); 
    12511248 
    12521249    for (; avec != bigblock_endp; avec += 16, bvec += 16) 
    12531250    { 
    12541251        sum0 += avec[0] * bvec[0]; 
    12551252        sum1 += avec[1] * bvec[1]; 
    12561253        sum0 += avec[2] * bvec[2]; 
     
    12831280        sum0 += (*avec++) * (*bvec++); 
    12841281 
    12851282    return sum0; 
    12861283} 
    12871284 
    12881285unittest 
    12891286{ 
    12901287    double[] a = [ 1., 2., ]; 
    12911288    double[] b = [ 4., 6., ]; 
    12921289    assert(dotProduct(a, b) == 16); 
     1290    assert(dotProduct([1, 3, -5], [4, -2, -1]) == 3); 
    12931291} 
    12941292 
    12951293/** 
    12961294Computes the $(LUCKY cosine similarity) of input ranges $(D a) and $(D 
    12971295b). The two ranges must have the same length. If both ranges define 
    12981296length, the check is done once; otherwise, it is done at each 
    12991297iteration. If either range has all-zero elements, return 0. 
    13001298 */ 
    13011299CommonType!(ElementType!(Range1), ElementType!(Range2)) 
    13021300cosineSimilarity(Range1, Range2)(Range1 a, Range2 b)