Skip to content

Commit

Permalink
fix dot
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Sep 23, 2016
1 parent d498d54 commit 4c19097
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions source/mir/glas/l1.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The Level 1 GLAS perform vector and vector-vector operations.
$(BOOKTABLE $(H2 Vector-vector operations),
$(T2 rot, apply Givens rotation)
$(T2 axpy, constant times a vector plus a vector)
$(T2 dot, dot product, conjugating the first vector)
$(T2 dotu, dot product)
$(T2 dot, dot product)
$(T2 dotc, dot product, conjugating the first vector)
)
$(BOOKTABLE $(H2 Vector operations),
Expand Down Expand Up @@ -295,7 +295,7 @@ F dot(F, size_t N, R1, R2)(Slice!(N, R1) x, Slice!(N, R2) y)
{
assert(x.shape == y.shape, "constraints: x and y must have equal shapes");
pragma(inline, false);
return ndReduce!(_fmuladdc, Yes.vectorized)(F(0), x, y);
return ndReduce!(_fmuladd, Yes.vectorized)(F(0), x, y);
}
}

Expand Down Expand Up @@ -338,7 +338,7 @@ unittest
assert(dot!real(x, y) == 5 + 12 + 21); // 80-bit FP for x86 CPUs
}

/// CDOTC, ZDOTC
/// CDOTU, ZDOTU
unittest
{
import mir.ndslice.slice: slice;
Expand All @@ -349,10 +349,9 @@ unittest
auto y = slice!cd(2);
x[] = [cd(0, 1), cd(2, 3)];
y[] = [cd(4, 5), cd(6, 7)];
assert(dot(x, y) == cd(0, -1) * cd(4, 5) + cd(2, -3) * cd(6, 7));
assert(dot(x, y) == cd(0, 1) * cd(4, 5) + cd(2, 3) * cd(6, 7));
}


/++
Forms the dot product of two complex vectors.
Uses unrolled loops for strides equal to one.
Expand All @@ -363,28 +362,28 @@ Params:
y = second n-dimensional tensor
BLAS: CDOTU, ZDOTU
+/
F dotu(F, size_t N, R1, R2)(Slice!(N, R1) x, Slice!(N, R2) y)
F dotc(F, size_t N, R1, R2)(Slice!(N, R1) x, Slice!(N, R2) y)
if (isComplex!(DeepElementType!(typeof(x))) && isComplex!(DeepElementType!(typeof(y))))
{
static if (allSatisfy!(_shouldBeCastedToUnqual, R1, R2))
{
return .dotu!F(cast(Slice!(N, Unqual!R1))x, cast(Slice!(N, Unqual!R2))y);
return .dotc!F(cast(Slice!(N, Unqual!R1))x, cast(Slice!(N, Unqual!R2))y);
}
else
{
assert(x.shape == y.shape, "constraints: x and y must have equal shapes");
pragma(inline, false);
return ndReduce!(_fmuladd, Yes.vectorized)(F(0), x, y);
return ndReduce!(_fmuladdc, Yes.vectorized)(F(0), x, y);
}
}

/// ditto
auto dotu(size_t N, R1, R2)(Slice!(N, R1) x, Slice!(N, R2) y)
auto dotc(size_t N, R1, R2)(Slice!(N, R1) x, Slice!(N, R2) y)
{
return .dotu!(Unqual!(typeof(x[x.shape.init] * y[y.shape.init])))(x, y);
return .dotc!(Unqual!(typeof(x[x.shape.init] * y[y.shape.init])))(x, y);
}

/// CDOTU, ZDOTU
/// CDOTC, ZDOTC
unittest
{
import mir.ndslice.slice: slice;
Expand All @@ -395,7 +394,7 @@ unittest
auto y = slice!cd(2);
x[] = [cd(0, 1), cd(2, 3)];
y[] = [cd(4, 5), cd(6, 7)];
assert(dotu(x, y) == cd(0, 1) * cd(4, 5) + cd(2, 3) * cd(6, 7));
assert(dotc(x, y) == cd(0, -1) * cd(4, 5) + cd(2, -3) * cd(6, 7));
}

/++
Expand Down

0 comments on commit 4c19097

Please sign in to comment.