Skip to content

Commit cab488e

Browse files
authored
add mir.ndslice.fuse and a a huge work on qualifier propagation (#127)
* add mir.qualifier * ditto * add mir.qualifier * ditto * fix few bugs * update join * prepare docs * fix bugs * fix optmath * add import * fix makefile * ditto * ditto * fix docs * add fuse instead of join, improve API with fused slices, optimize ndslice.algorithm, fix few minor bugs * Update spline.d * Update spline.d * Update pchip.d
1 parent bf616bf commit cab488e

26 files changed

+1070
-109
lines changed

doc/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ARTWORK_DIR=$(DOC_SOURCE_DIR)/artwork
2525
# Packages in mir. Just mention the package name here. The contents of package
2626
# xy/zz is in variable PACKAGE_xy_zz. This allows automation in iterating
2727
# packages and their modules.
28-
MIR_PACKAGES = mir mir/ndslice mir/ndslice/connect mir/internal mir/math mir/math/func mir/array mir/interpolate
28+
MIR_PACKAGES = mir mir/ndslice mir/ndslice/connect mir/internal mir/math mir/math/func mir/array mir/interpolate mir/graph
2929

3030
PACKAGE_mir = bitmanip conv functional primitives range series utility
3131

@@ -35,6 +35,7 @@ PACKAGE_mir_interpolate = package constant linear spline pchip utility
3535
PACKAGE_mir_math = constant common sum numeric package
3636
PACKAGE_mir_math_func = expdigamma
3737
PACKAGE_mir_ndslice_connect = cpp cpython
38+
PACKAGE_mir_graph = tarjan package
3839

3940
PACKAGE_mir_ndslice = \
4041
algorithm\
@@ -44,6 +45,7 @@ PACKAGE_mir_ndslice = \
4445
dynamic\
4546
field\
4647
iterator\
48+
fuse\
4749
mutation\
4850
ndfield\
4951
package\

index.d

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $(BOOKTABLE ,
1010
$(TH Modules)
1111
$(TH Description)
1212
)
13+
$(LEADINGROW Containers)
14+
$(TR $(TDNW $(MREF mir,series)★) $(TD Generic series suitable for time-series or semi-immutable ordered maps with CPU cache friendly binary search.))
1315
$(LEADINGROW Algorithms constructors, multidimensional arrays, iterators)
1416
$(TR $(TDNW $(MREF mir,ndslice)★) $(TD Package for vectors, matrixes, and nd-arrays))
1517
$(TR $(TDNW $(MREF mir,ndslice,algorithm)) $(TD Loop free programming: `each`, `reduce`, and friends))
@@ -18,19 +20,21 @@ $(BOOKTABLE ,
1820
$(TR $(TDNW $(MREF mir,ndslice,concatenation)) $(TD Concatenation and padding))
1921
$(TR $(TDNW $(MREF mir,ndslice,dynamic)) $(TD Dynamic dimension manipulators))
2022
$(TR $(TDNW $(MREF mir,ndslice,field)) $(TD Field declarations))
23+
$(TR $(TDNW $(MREF mir,ndslice,fuse)) $(TD Fuse (stack) utilities for rows, columns, and cells))
2124
$(TR $(TDNW $(MREF mir,ndslice,iterator)) $(TD Iterator declarations))
2225
$(TR $(TDNW $(MREF mir,ndslice,ndfield)) $(TD NdField declarations))
2326
$(TR $(TDNW $(MREF mir,ndslice,slice)★) $(TD Slice structure, basic constructors))
2427
$(TR $(TDNW $(MREF mir,ndslice,sorting)) $(TD Sorting utilities))
2528
$(TR $(TDNW $(MREF mir,ndslice,topology)★) $(TD Advanced ndslice constructors (key module).))
2629
$(TR $(TDNW $(MREF mir,ndslice,traits)) $(TD Multi-dimensional traits))
30+
$(LEADINGROW Graphs)
31+
$(TR $(TDNW $(MREF mir,graph) WIP) $(TD Basic routines to work with graphs))
32+
$(TR $(TDNW $(MREF mir,graph,tarjan)★) $(TD Tarjan's strongly connected components algorithm))
33+
$(LEADINGROW Interpolation)
34+
$(TR $(TDNW $(MREF mir,interpolate)★) $(TD Interpolation algorithms))
2735
$(LEADINGROW Interconnection with other languages)
2836
$(TR $(TDNW $(MREF mir,ndslice,connect,cpp)) $(TD Definitions suitable for `extern(C++)` functions))
2937
$(TR $(TDNW $(MREF mir,ndslice,connect,cpython)) $(TD Utilities for $(HTTPS docs.python.org/3/c-api/buffer.html, Python Buffer Protocol)))
30-
$(LEADINGROW Data structures, finance)
31-
$(TR $(TDNW $(MREF mir,series)★) $(TD Generic series suitable for time-series or semi-immutable ordered maps with CPU cache friendly binary search.))
32-
$(LEADINGROW Interpolation)
33-
$(TR $(TDNW $(MREF mir,interpolate)★) $(TD Interpolation algorithms))
3438
$(LEADINGROW Math)
3539
$(TR $(TDNW $(MREF mir,math)) $(TD Package))
3640
$(TR $(TDNW $(MREF mir,math,common)★) $(TD Common math functions and fp-math compiler optimization attributes))

source/mir/functional.d

+17
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,21 @@ struct AliasCall(T, string methodName, TemplateArgs...)
708708
{
709709
T __this;
710710
alias __this this;
711+
712+
///
713+
auto lightConst()() const @property
714+
{
715+
import mir.qualifier;
716+
return AliasCall!(LightConstOf!T, methodName, TemplateArgs)(__this.lightConst);
717+
}
718+
719+
///
720+
auto lightImmutable()() immutable @property
721+
{
722+
import mir.qualifier;
723+
return AliasCall!(LightImmutableOf!T, methodName, TemplateArgs)(__this.lightImmutable);
724+
}
725+
711726
this()(auto ref T value)
712727
{
713728
__this = value;
@@ -752,6 +767,8 @@ template aliasCall(string methodName, TemplateArgs...)
752767

753768
static struct S
754769
{
770+
auto lightConst()() const @property { return S(); }
771+
755772
auto fun(size_t ct_param = 1)(size_t rt_param)
756773
{
757774
return rt_param + ct_param;

source/mir/graph/utility.d renamed to source/mir/graph/package.d

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/++
2+
Basic routines to work with graphs.
3+
24
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
35
Copyright: Copyright © 2018-, Kaleidic Associates Advisory Limited
46
Authors: Ilya Yaroshenko
@@ -8,7 +10,11 @@ SUBREF = $(REF_ALTTEXT $(TT $2), $2, mir, graph, $1)$(NBSP)
810
T2=$(TR $(TDNW $(LREF $1)) $(TD $+))
911
+/
1012

11-
module mir.graph.utility;
13+
module mir.graph;
14+
15+
import mir.math.common: optmath;
16+
17+
@optmath:
1218

1319
import mir.series;
1420

source/mir/graph/tarjan.d

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/++
2+
This is a submodule of $(MREF mir,graph).
3+
24
Tarjan's strongly connected components algorithm.
35
46
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
@@ -14,6 +16,11 @@ module mir.graph.tarjan;
1416

1517
import std.traits;
1618

19+
import mir.math.common: optmath;
20+
21+
@optmath:
22+
23+
1724
/++
1825
Classic Tarjan's strongly connected components algorithm.
1926
@@ -217,7 +224,8 @@ auto tarjan(G, I = Unqual!(ForeachType!(ForeachType!G)))(G graph)
217224
+/
218225
pure version(mir_test) unittest
219226
{
220-
import mir.graph.utility;
227+
import mir.graph;
228+
import mir.graph.tarjan;
221229

222230
GraphSeries!(string, uint) gs = [
223231
"00": ["01"],
@@ -249,7 +257,8 @@ Tests that the graph `0 -> 1 -> 2 -> 3 -> 4` returns 4 components.
249257
+/
250258
pure version(mir_test) unittest
251259
{
252-
import mir.graph.utility;
260+
import mir.graph;
261+
import mir.graph.tarjan;
253262

254263
GraphSeries!(char, uint) gs = [
255264
'a': ['b'],
@@ -268,13 +277,14 @@ pure version(mir_test) unittest
268277
----
269278
0 <- 2 <-- 5 <--> 6
270279
| ^ ^ ^___
271-
v / | \ /\
280+
v_| | | _
272281
1 <- 3 <-> 4 <-- 7_|
273282
----
274283
+/
275284
pure version(mir_test) unittest
276285
{
277-
import mir.graph.utility;
286+
import mir.graph;
287+
import mir.graph.tarjan;
278288

279289
auto gs = [
280290
0: [1],
@@ -300,14 +310,15 @@ pure version(mir_test) unittest
300310
/++
301311
-----
302312
2 <-> 1
303-
\ ^
304-
v /
305-
0
313+
| ^
314+
v_0 /
315+
306316
-----
307317
+/
308318
pure version(mir_test) unittest
309319
{
310-
import mir.graph.utility;
320+
import mir.graph;
321+
import mir.graph.tarjan;
311322

312323
auto gs = [
313324
0: [1],
@@ -331,7 +342,8 @@ not when they were actually removed from the stack
331342
+/
332343
pure version(mir_test) unittest
333344
{
334-
import mir.graph.utility;
345+
import mir.graph;
346+
import mir.graph.tarjan;
335347

336348
auto root = 0;
337349
auto lvl1 = [1,2,3,4,5,6,7,8,9,10];

source/mir/interpolate/constant.d

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ T2=$(TR $(TDNW $(LREF $1)) $(TD $+))
1313
+/
1414
module mir.interpolate.constant;
1515

16+
@optmath:
17+
1618
///
1719
version(mir_test)
1820
@safe pure unittest
@@ -64,6 +66,8 @@ template constant(T, size_t N = 1, FirstGridIterator = immutable(T)*, NextGridIt
6466
{
6567
static if (N > 1) pragma(msg, "Warning: multivariate constant interpolant was not tested.");
6668

69+
@optmath:
70+
6771
private alias GridIterators = AliasSeq!(FirstGridIterator, NextGridIterators);
6872
private alias GridVectors = Constant!(T, N, GridIterators).GridVectors;
6973

@@ -105,6 +109,8 @@ struct Constant(F, size_t N = 1, FirstGridIterator = immutable(F)*, NextGridIter
105109
package alias GridIterators = AliasSeq!(FirstGridIterator, NextGridIterators);
106110
package alias GridVectors = staticMap!(GridVector, GridIterators);
107111

112+
@optmath:
113+
108114
/// Aligned buffer allocated with `mir.internal.memory`. $(RED For internal use.)
109115
Slice!(Contiguous, [N], F*) _data;
110116
/// Grid iterators. $(RED For internal use.)

source/mir/interpolate/linear.d

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import mir.internal.utility;
2323
public import mir.interpolate: atInterval;
2424
import mir.interpolate;
2525

26+
@optmath:
27+
2628
/++
2729
Constructs multivariate linear interpolant with nodes on rectilinear grid.
2830
@@ -43,6 +45,8 @@ template linear(T, size_t N = 1, FirstGridIterator = immutable(T)*, NextGridIter
4345
private alias GridIterators = AliasSeq!(FirstGridIterator, NextGridIterators);
4446
private alias GridVectors = Linear!(T, N, GridIterators).GridVectors;
4547

48+
@optmath:
49+
4650
/++
4751
Params:
4852
grid = immutable `x` values for interpolant
@@ -382,6 +386,18 @@ struct LinearKernel(X)
382386
X w0 = 0;
383387
X w1 = 0;
384388

389+
///
390+
auto lightConst()() const @property
391+
{
392+
return LinearKernel!X(step, w0, w1);
393+
}
394+
395+
///
396+
auto lightImmutable()() immutable @property
397+
{
398+
return LinearKernel!X(step, w0, w1);
399+
}
400+
385401
///
386402
this()(X x0, X x1, X x)
387403
{

source/mir/interpolate/package.d

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import std.traits: isInstanceOf;
2323
import mir.primitives;
2424
import mir.functional: RefTuple;
2525
import mir.ndslice.slice: Slice, Contiguous;
26+
import mir.math.common: optmath;
27+
28+
@optmath:
2629

2730
package ref iter(alias s)() { return s._iterator; };
2831
package alias GridVector(It) = Slice!(Contiguous, [1], It);

source/mir/interpolate/pchip.d

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import std.traits;
1919
import std.meta: AliasSeq;
2020
import mir.ndslice.slice;
2121
import mir.array.primitives;
22-
import mir.math.common: optmath;
22+
import mir.math.common: fmamath;
2323
import mir.ndslice.internal: ConstIfPointer;
2424

25-
@optmath:
25+
@fmamath:
2626

2727
/++
2828
Constructs piecewise cubic hermite interpolating polynomial with nodes on rectilinear grid.
@@ -44,7 +44,7 @@ template pchip(T, size_t N = 1, FirstGridIterator = immutable(T)*, NextGridItera
4444
`points` and `values` must have the same length >= 3
4545
Returns: $(SUBREF spline, Spline)
4646
+/
47-
Spline!(T, N, GridIterators) pchip(SliceKind ykind, yIterator)(
47+
@fmamath Spline!(T, N, GridIterators) pchip(SliceKind ykind, yIterator)(
4848
GridVectors grid,
4949
scope Slice!(ykind, [N], yIterator) values) @safe
5050
{

source/mir/interpolate/spline.d

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import std.meta;
2626
import mir.array.primitives;
2727
import mir.functional;
2828
import mir.internal.utility: Iota;
29-
import mir.math.common: optmath;
29+
import mir.math.common: fmamath;
3030
import mir.ndslice.internal;
3131
import mir.ndslice.slice;
3232
import mir.ndslice.traits;
3333

34+
@fmamath:
35+
3436
///
3537
@safe pure nothrow unittest
3638
{
@@ -320,8 +322,6 @@ unittest
320322
// assert(appreq(d[1][1][1], y_x0x1x2));
321323
}
322324

323-
@optmath:
324-
325325
/++
326326
Constructs multivariate cubic spline in symmetrical form with nodes on rectilinear grid.
327327
Result has continues second derivatives throughout the curve / nd-surface.
@@ -438,6 +438,8 @@ struct Spline(F, size_t N = 1, FirstGridIterator = immutable(F)*, NextGridIterat
438438
package alias GridIterators = AliasSeq!(FirstGridIterator, NextGridIterators);
439439
package alias GridVectors = staticMap!(GridVector, GridIterators);
440440

441+
@fmamath:
442+
441443
/// Aligned buffer allocated with `mir.internal.memory`. $(RED For internal use.)
442444
Slice!(Contiguous, [N], F[2 ^^ N]*) _data;
443445
/// Grid iterators. $(RED For internal use.)

source/mir/interpolate/utility.d

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module mir.interpolate.utility;
22

33
import mir.ndslice.slice;
44
import std.traits;
5+
import mir.math.common: optmath;
56

67
/++
78
ParabolaKernel structure.

0 commit comments

Comments
 (0)