-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2: ndslice API rework, extern(C++) support (#143)
* v2: ndslice API rework * update combinatorics * uncomment code * clean Slice * fix example * minor cleanup * clean code * move mir.ndslice.algorithm -> mir.algorithm.iteration * add cpp_example * fix docs * update example * comment out DMD
- Loading branch information
Showing
40 changed files
with
4,419 additions
and
5,956 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module eye; | ||
|
||
import mir.ndslice; | ||
|
||
extern(C++, Space) | ||
{ | ||
Slice!(double*, 2) eye(size_t n) nothrow @nogc | ||
{ | ||
auto ret = stdcUninitSlice!double(n, n); | ||
ret[] = 0; | ||
ret.diagonal[] = 1; | ||
return ret; | ||
} | ||
|
||
void printMatrix(Slice!(double*, 2) matrix) | ||
{ | ||
import core.stdc.stdio; | ||
|
||
foreach(row; matrix) | ||
{ | ||
foreach(e; row) | ||
printf("%f ", e); | ||
printf("\n"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <cstdlib> | ||
#include "mir/ndslice.h" | ||
|
||
namespace Space | ||
{ | ||
mir_slice<double*, 2> eye(size_t n); | ||
void printMatrix(mir_slice<double*, 2> matrix); | ||
} | ||
|
||
int main() | ||
{ | ||
mir_slice<double*, 2> matrix = Space::eye(3); | ||
Space::printMatrix(matrix); | ||
std::free(matrix._iterator); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ldmd2 -betterC -O -inline -release eye.d -I../source -c | ||
g++ main.cpp eye.o -std=c++11 -I../include | ||
./a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
************ Mir-Algorithm ************ | ||
The module provides wrappers for $(SUBREF slice, Slice) that | ||
can be used as arguments for C++ functions. | ||
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). | ||
Copyright: Copyright © 2017-, Ilya Yaroshenko | ||
Authors: Ilya Yaroshenko | ||
*/ | ||
#include <cstddef> | ||
|
||
// It is out of ndslice namespace because of a DMD mangling bug. | ||
enum class mir_slice_kind : int | ||
{ | ||
universal = 0, | ||
canonical = 1, | ||
contiguous = 2 | ||
}; | ||
|
||
template < | ||
typename Iterator, | ||
size_t N = 1, | ||
mir_slice_kind kind = mir_slice_kind::contiguous | ||
> | ||
struct mir_slice | ||
{ | ||
size_t _lengths[N]; | ||
ptrdiff_t _strides[kind == mir_slice_kind::universal ? N : kind == mir_slice_kind::canonical ? N - 1 : 0]; | ||
Iterator _iterator; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "mir/ndslice.h" | ||
|
||
template < | ||
typename Index, | ||
typename Data | ||
> | ||
struct mir_observation | ||
{ | ||
Index _index; | ||
Data _data; | ||
} | ||
|
||
template < | ||
typename IndexIterator, | ||
typename Iterator, | ||
size_t N = 1, | ||
mir_slice_kind kind = mir_slice_kind::contiguous | ||
> | ||
struct mir_series | ||
{ | ||
mir_slice<Iterator, N, kind> _data; | ||
IndexIterator _index; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.