Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 26, 2016
1 parent 1f37557 commit b14d190
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions std/experimental/ndslice/internal.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum indexError(size_t pos, size_t N) =
~ " must be less than corresponding length.";

enum indexStrideCode = q{
static if(_indexes.length)
static if (_indexes.length)
{
size_t stride = _strides[0] * _indexes[0];
assert(_indexes[0] < _lengths[0], indexError!(0, N));
Expand All @@ -29,7 +29,7 @@ enum indexStrideCode = q{
};

enum mathIndexStrideCode = q{
static if(_indexes.length)
static if (_indexes.length)
{
size_t stride = _strides[0] * _indexes[N - 1];
assert(_indexes[N - 1] < _lengths[0], indexError!(N - 1, N));
Expand Down
39 changes: 25 additions & 14 deletions std/experimental/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ body
ret._strides[N - 1] = 1;
else
ret._strides[N - 1] = range._strides[0];
foreach_reverse(i; Iota!(0, N - 1))
foreach_reverse (i; Iota!(0, N - 1))
{
ret._lengths[i] = lengths[i];
ret._strides[i] = ret._strides[i + 1] * ret._lengths[i + 1];
Expand Down Expand Up @@ -414,15 +414,21 @@ private template _Range_Values(Names...)
private template _Range_DeclarationList(Names...)
{
static if (Names.length)
enum string _Range_DeclarationList = "Range_" ~ Names[0] ~ " range_" ~ Names[0] ~ ", " ~ _Range_DeclarationList!(Names[1..$]);
{
enum string _Range_DeclarationList = "Range_" ~ Names[0] ~ " range_"
~ Names[0] ~ ", " ~ _Range_DeclarationList!(Names[1..$]);
}
else
enum string _Range_DeclarationList = "";
}

private template _Slice_DeclarationList(Names...)
{
static if (Names.length)
enum string _Slice_DeclarationList = "Slice!(N, Range_" ~ Names[0] ~ ") slice_" ~ Names[0] ~ ", " ~ _Slice_DeclarationList!(Names[1..$]);
{
enum string _Slice_DeclarationList = "Slice!(N, Range_" ~ Names[0] ~ ") slice_"
~ Names[0] ~ ", " ~ _Slice_DeclarationList!(Names[1..$]);
}
else
enum string _Slice_DeclarationList = "";
}
Expand Down Expand Up @@ -731,7 +737,7 @@ auto makeNdarray(T, Allocator, size_t N, Range)(auto ref Allocator alloc, Slice
{
alias E = typeof(makeNdarray!T(alloc, slice[0]));
auto ret = makeArray!E(alloc, slice.length);
foreach(i, ref e; ret)
foreach (i, ref e; ret)
e = .makeNdarray!T(alloc, slice[i]);
return ret;
}
Expand All @@ -752,7 +758,7 @@ auto makeNdarray(T, Allocator, size_t N, Range)(auto ref Allocator alloc, Slice
static immutable ar = [[0L, 1, 2, 3], [4L, 5, 6, 7], [8L, 9, 10, 11]];
assert(m == ar);

foreach(ref row; m)
foreach (ref row; m)
Mallocator.instance.dispose(row);
Mallocator.instance.dispose(m);
}
Expand Down Expand Up @@ -1452,7 +1458,8 @@ struct Slice(size_t _N, _Range)
if (dimension < N)
{
pragma(inline, true);
assert(n <= _lengths[dimension], __FUNCTION__ ~ ": n should be less than or equal to length!" ~ dimension.stringof);
assert(n <= _lengths[dimension],
__FUNCTION__ ~ ": n should be less than or equal to length!" ~ dimension.stringof);
_lengths[dimension] -= n;
_ptr += _strides[dimension] * n;
}
Expand All @@ -1462,7 +1469,8 @@ struct Slice(size_t _N, _Range)
if (dimension < N)
{
pragma(inline, true);
assert(n <= _lengths[dimension], __FUNCTION__ ~ ": n should be less than or equal to length!" ~ dimension.stringof);
assert(n <= _lengths[dimension],
__FUNCTION__ ~ ": n should be less than or equal to length!" ~ dimension.stringof);
_lengths[dimension] -= n;
}

Expand Down Expand Up @@ -1623,7 +1631,7 @@ struct Slice(size_t _N, _Range)
{
if (this.length != rarrary.length)
return false;
foreach(i, ref e; rarrary)
foreach (i, ref e; rarrary)
if (e != this[i])
return false;
return true;
Expand All @@ -1650,9 +1658,10 @@ struct Slice(size_t _N, _Range)
in {
assert(i <= j,
"Slice.opSlice!" ~ dimension.stringof ~ ": the left bound must be less than or equal to the right bound.");
enum errorMsg = ": difference between the right and the left bounds"
~ " must be less than or equal to the length of the given dimension.";
assert(j - i <= _lengths[dimension],
"Slice.opSlice!" ~ dimension.stringof ~
": difference between the right and the left bounds must be less than or equal to the length of the given dimension.");
"Slice.opSlice!" ~ dimension.stringof ~ errorMsg);
}
body
{
Expand Down Expand Up @@ -1799,7 +1808,8 @@ struct Slice(size_t _N, _Range)
&& RN <= ReturnType!(opIndex!Slices).N)
{
auto slice = this[slices];
assert(slice._lengths[$ - RN .. $] == value._lengths, __FUNCTION__ ~ ": argument must have the corresponding shape.");
assert(slice._lengths[$ - RN .. $] == value._lengths,
__FUNCTION__ ~ ": argument must have the corresponding shape.");
version(none) //future optimization
static if ((isPointer!Range || isDynamicArray!Range) && (isPointer!RRange || isDynamicArray!RRange))
{
Expand Down Expand Up @@ -2850,7 +2860,6 @@ private template PtrTuple(Names...)
pure nothrow unittest
{
auto a = new int[20], b = new int[20];
import std.stdio;
alias T = PtrTuple!("a", "b");
alias S = T!(int*, int*);
auto t = S(a.ptr, b.ptr);
Expand Down Expand Up @@ -2902,12 +2911,14 @@ private enum bool isType(T) = true;

private enum isStringValue(alias T) = is(typeof(T) : string);

private void _indexAssign(bool lastStrideEquals1, string op, size_t N, size_t RN, Range, RRange)(Slice!(N, Range) slice, Slice!(RN, RRange) value)
private void _indexAssign(bool lastStrideEquals1, string op, size_t N, size_t RN, Range, RRange)
(Slice!(N, Range) slice, Slice!(RN, RRange) value)
if (N >= RN)
{
static if (N == 1)
{
static if (lastStrideEquals1 && (isPointer!Range || isDynamicArray!Range) && (isPointer!RRange || isDynamicArray!RRange))
static if (lastStrideEquals1 && (isPointer!Range || isDynamicArray!Range)
&& (isPointer!RRange || isDynamicArray!RRange))
{
static if (isPointer!Range)
auto l = slice._ptr;
Expand Down

0 comments on commit b14d190

Please sign in to comment.