Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ PACKAGE_mir_ndslice = \
concatenation\
dynamic\
field\
filling\
fuse\
iterator\
mutation\
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mir_algorithm_src = [
'source/mir/ndslice/connect/cpython.d',
'source/mir/ndslice/dynamic.d',
'source/mir/ndslice/field.d',
'source/mir/ndslice/filling.d',
'source/mir/ndslice/fuse.d',
'source/mir/ndslice/internal.d',
'source/mir/ndslice/iterator.d',
Expand Down
42 changes: 42 additions & 0 deletions source/mir/ndslice/filling.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/++
This is a submodule of $(MREF mir,ndslice).

Initialisation routines.

License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
Copyright: 2019 Symmetry Investments Group and Kaleidic Associates Advisory Limited.
Authors: Ilya Yaroshenko

Macros:
SUBREF = $(REF_ALTTEXT $(TT $2), $2, mir, ndslice, $1)$(NBSP)
T2=$(TR $(TDNW $(LREF $1)) $(TD $+))
+/
module mir.ndslice.filling;

import mir.ndslice.slice: Slice, SliceKind;

/++
Fills a matrix with the terms of a geometric progression in each row.
Params:
matrix = `m × n` matrix to fill
vec = vector of progression coefficients length of `m`
+/
void fillVandermonde(F, SliceKind matrixKind, SliceKind kind)(Slice!(F*, 2, matrixKind) matrix, Slice!(const(F)*, 1, kind) vec)
in {
assert(matrix.length == vec.length);
}
body {
import mir.conv: to;

foreach (v; matrix)
{
F a = vec.front;
vec.popFront;
F x = to!F(1);
foreach (ref e; v)
{
e = x;
x *= a;
}
}
}
8 changes: 8 additions & 0 deletions source/mir/ndslice/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ $(TR $(TDNW $(SUBMODULE topology) $(BR)
)
)

$(TR $(TDNW $(SUBMODULE filling) $(BR)
$(SMALL Specialized initialisation routines))
$(TD
$(SUBREF filling, fillVandermonde)
)
)

$(TR $(TDNW $(SUBMODULE fuse) $(BR)
$(SMALL Data fusing (stacking)
$(BR) See also $(SUBMODULE concatenation) submodule.
Expand Down Expand Up @@ -474,6 +481,7 @@ public import mir.ndslice.concatenation;
public import mir.ndslice.chunks;
public import mir.ndslice.dynamic;
public import mir.ndslice.field;
public import mir.ndslice.filling;
public import mir.ndslice.fuse;
public import mir.ndslice.iterator;
public import mir.ndslice.ndfield;
Expand Down
6 changes: 4 additions & 2 deletions source/mir/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ auto sliced(size_t N, Iterator)(Iterator iterator, size_t[N] lengths...)
return ret;
}

import mir.ndslice.topology: universal;
import mir.ndslice.filling: fillVandermonde;
import mir.ndslice.allocation: uninitSlice;
auto x = [1.0, 2, 3, 4, 5].sliced;
auto v = vandermondeMatrix(x);
auto v = uninitSlice!double(x.length, x.length);
v.fillVandermonde(x);
assert(v ==
[[ 1.0, 1, 1, 1, 1],
[ 1.0, 2, 4, 8, 16],
Expand Down