Skip to content

Commit fbcde01

Browse files
committed
add series constructor from associative arrays
1 parent b15b79b commit fbcde01

File tree

5 files changed

+425
-364
lines changed

5 files changed

+425
-364
lines changed

source/mir/functional.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,16 @@ Unref!(RefTuple!T) unref(V : RefTuple!T, T...)(V value)
144144
}
145145

146146
/// ditto
147-
V unref(V)(V value)
147+
ref V unref(V)(return ref V value)
148148
{
149149
return value;
150150
}
151151

152+
/// ditto
153+
V unref(V)(V value)
154+
{
155+
return value;
156+
}
152157

153158
private string joinStrings()(string[] strs)
154159
{

source/mir/ndslice/allocation.d

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,17 @@ Returns:
271271
ContiguousSlice!(N, T)
272272
makeUninitSlice(T, Allocator, size_t N)(auto ref Allocator alloc, size_t[N] lengths...)
273273
{
274-
immutable len = lengthsProduct(lengths);
275-
auto array = cast(T[]) alloc.allocate(len * T.sizeof);
276-
return array.sliced(lengths);
274+
if (immutable len = lengthsProduct(lengths))
275+
{
276+
auto mem = alloc.allocate(len * T.sizeof);
277+
if (mem.length == 0) assert(0);
278+
auto array = () @trusted { return cast(T[]) mem; }();
279+
return array.sliced(lengths);
280+
}
281+
else
282+
{
283+
return T[].init.sliced(lengths);
284+
}
277285
}
278286

279287
///

source/mir/ndslice/sorting.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,15 @@ template sort(alias less = "a < b")
169169
static if (__traits(isSame, naryFun!less, less))
170170
///
171171
@optmath Slice!(kind, packs, Iterator) sort(SliceKind kind, size_t[] packs, Iterator)
172-
(Slice!(kind, packs, Iterator) slice)
172+
(Slice!(kind, packs, Iterator) slice) @safe
173173
if (packs.length == 1)
174174
{
175175
if (false) // break safety
176176
{
177177
import mir.utility : swapStars;
178-
swapStars(slice._iterator, slice._iterator);
179-
auto l = less(*slice._iterator, *slice._iterator);
178+
auto elem = typeof(*slice._iterator).init;
179+
elem = elem;
180+
auto l = less(elem, elem);
180181
}
181182
import mir.ndslice.topology: flattened;
182183
if (slice.anyEmpty)

0 commit comments

Comments
 (0)