Thread overview
How to use libmir --> mir-algorithm, numir, mir-random?
Sep 02, 2020
Shaleen Chhabra
Sep 02, 2020
WebFreak001
Sep 02, 2020
9il
Sep 09, 2020
Shaleen Chhabra
Sep 09, 2020
Shaleen Chhabra
Sep 09, 2020
Fynn Schröder
Sep 09, 2020
Fynn Schröder
Sep 09, 2020
Shaleen Chhabra
Sep 09, 2020
Shaleen Chhabra
Sep 09, 2020
jmh530
September 02, 2020
Hi,

The libmir libraries can be found here: https://github.com/libmir

I wish to use mir-algorithm and numir so that i can directly use .npy format from python and perform the required analysis.

I checked out latest commits of each of the libraries mentioned --> mir-algorithm, mir-random and numir.

But they don't seem to build together. what are the correct dependencies for each library.

TASK:  how can i read / write mir.ndslice matrices and in what preferable format, an example should be good. I also wish to read / write in .npy format, how can i do this?
September 02, 2020
On Wednesday, 2 September 2020 at 07:01:48 UTC, Shaleen Chhabra wrote:
> Hi,
>
> The libmir libraries can be found here: https://github.com/libmir
>
> I wish to use mir-algorithm and numir so that i can directly use .npy format from python and perform the required analysis.
>
> I checked out latest commits of each of the libraries mentioned --> mir-algorithm, mir-random and numir.
>
> But they don't seem to build together. what are the correct dependencies for each library.
>
> TASK:  how can i read / write mir.ndslice matrices and in what preferable format, an example should be good. I also wish to read / write in .npy format, how can i do this?

numir seems to be what you are looking for: https://libmir.github.io/numir/

You can check the loadNpy and saveNpy examples at the bottom of this page: https://libmir.github.io/numir/io.html

Sample:

    auto a1_i4 = loadNpy!(int, 1)("./test/a1_i4.npy");
    assert(a1_i4 == iota(6).map!(to!int));

loadNpy returns a mir.ndslice Slice so you should be able to operate on it like usual. You need to specify the dimensions of your slice at compile time though, the lengths of each dimension do seem to be loaded at runtime.
September 02, 2020
On Wednesday, 2 September 2020 at 07:01:48 UTC, Shaleen Chhabra wrote:
> Hi,
>
> The libmir libraries can be found here: https://github.com/libmir
>
> I wish to use mir-algorithm and numir so that i can directly use .npy format from python and perform the required analysis.
>
> I checked out latest commits of each of the libraries mentioned --> mir-algorithm, mir-random and numir.
>
> But they don't seem to build together. what are the correct dependencies for each library.

You can just import numir, it will automatically include mir-algorithm, mir-core, and mir-random.

https://github.com/libmir/numir/blob/master/dub.json#L9

> TASK:  how can i read / write mir.ndslice matrices and in what preferable format, an example should be good. I also wish to read / write in .npy format, how can i do this?

import std.stdio;
import mir.ndslice;

void main() {
     auto mat = [[1, 2, 3],
                 [4, 5, 6],
                 [7, 8, 9]].fuse;

     writefln("%(%(%d %)\n%)", mat);
     writeln();

     writefln("[%(%(%d %)\n %)]", mat);
     writeln();

     writefln("[%([%(%d %)]%|\n %)]", mat);
     writeln();
}

See also https://dlang.org/phobos/std_format.html

September 09, 2020
On Wednesday, 2 September 2020 at 08:19:30 UTC, 9il wrote:
> On Wednesday, 2 September 2020 at 07:01:48 UTC, Shaleen Chhabra wrote:
>> Hi,
>>
>> The libmir libraries can be found here: https://github.com/libmir
>>
>> I wish to use mir-algorithm and numir so that i can directly use .npy format from python and perform the required analysis.
>>
>> I checked out latest commits of each of the libraries mentioned --> mir-algorithm, mir-random and numir.
>>
>> But they don't seem to build together. what are the correct dependencies for each library.
>
> You can just import numir, it will automatically include mir-algorithm, mir-core, and mir-random.
>
> https://github.com/libmir/numir/blob/master/dub.json#L9
>
>> TASK:  how can i read / write mir.ndslice matrices and in what preferable format, an example should be good. I also wish to read / write in .npy format, how can i do this?
>
> import std.stdio;
> import mir.ndslice;
>
> void main() {
>      auto mat = [[1, 2, 3],
>                  [4, 5, 6],
>                  [7, 8, 9]].fuse;
>
>      writefln("%(%(%d %)\n%)", mat);
>      writeln();
>
>      writefln("[%(%(%d %)\n %)]", mat);
>      writeln();
>
>      writefln("[%([%(%d %)]%|\n %)]", mat);
>      writeln();
> }
>
> See also https://dlang.org/phobos/std_format.html



Hi I ran dub build on the numir library, it fetched some dependencies from dub.json.
But there was an error

../../.dub/packages/mir-core-1.1.10/mir-core/source/mir/conv.d(9,15): Error: module lifetime is in file 'core/lifetime.d' which cannot be read

when i do dub build.

Also, do i need to upgrade my dmd version in order to get it working?
September 09, 2020
On Wednesday, 9 September 2020 at 11:30:58 UTC, Shaleen Chhabra wrote:
> On Wednesday, 2 September 2020 at 08:19:30 UTC, 9il wrote:
>> On Wednesday, 2 September 2020 at 07:01:48 UTC, Shaleen Chhabra wrote:
>>> Hi,
>>>
>>> The libmir libraries can be found here: https://github.com/libmir
>>>
>>> I wish to use mir-algorithm and numir so that i can directly use .npy format from python and perform the required analysis.
>>>
>>> I checked out latest commits of each of the libraries mentioned --> mir-algorithm, mir-random and numir.
>>>
>>> But they don't seem to build together. what are the correct dependencies for each library.
>>
>> You can just import numir, it will automatically include mir-algorithm, mir-core, and mir-random.
>>
>> https://github.com/libmir/numir/blob/master/dub.json#L9
>>
>>> TASK:  how can i read / write mir.ndslice matrices and in what preferable format, an example should be good. I also wish to read / write in .npy format, how can i do this?
>>
>> import std.stdio;
>> import mir.ndslice;
>>
>> void main() {
>>      auto mat = [[1, 2, 3],
>>                  [4, 5, 6],
>>                  [7, 8, 9]].fuse;
>>
>>      writefln("%(%(%d %)\n%)", mat);
>>      writeln();
>>
>>      writefln("[%(%(%d %)\n %)]", mat);
>>      writeln();
>>
>>      writefln("[%([%(%d %)]%|\n %)]", mat);
>>      writeln();
>> }
>>
>> See also https://dlang.org/phobos/std_format.html
>
>
>
> Hi I ran dub build on the numir library, it fetched some dependencies from dub.json.
> But there was an error
>
> ../../.dub/packages/mir-core-1.1.10/mir-core/source/mir/conv.d(9,15): Error: module lifetime is in file 'core/lifetime.d' which cannot be read
>
> when i do dub build.
>
> Also, do i need to upgrade my dmd version in order to get it working?

The task which i want to achieve is:

From scratch, i need numir and mir-algorithm to work on my system as a part of one of my repositories.
I need to achieve the following targets as the first go and then use mir-algorithm to perform the needful research.

1. Load/save mir.ndslice arrays in NPY format
2. Load/save mir.sparse arrays in coordinate format as NPY files

but i am unable to configure the libraries, have dmd v2.076.1 installed on my PC.

thanks
September 09, 2020
On Wednesday, 9 September 2020 at 11:36:56 UTC, Shaleen Chhabra wrote:
> but i am unable to configure the libraries, have dmd v2.076.1 installed on my PC.

DMD v2.076 is ancient (almost 2 years old!). Current is DMD 2.093.1. I can only recommend to download and install an up-to-date version of DMD or LDC. This should solve your issues with using the mir libraries (and others). Then, try to get a simple example from numir working with your installation.
September 09, 2020
On Wednesday, 9 September 2020 at 11:43:16 UTC, Fynn Schröder wrote:
> DMD v2.076 is ancient (almost 2 years old!)
typo: its almost 3 years old
September 09, 2020
On Wednesday, 9 September 2020 at 11:44:35 UTC, Fynn Schröder wrote:
> On Wednesday, 9 September 2020 at 11:43:16 UTC, Fynn Schröder wrote:
>> DMD v2.076 is ancient (almost 2 years old!)
> typo: its almost 3 years old

thanks,
I have upgraded my dmd to latest version.
I now import numir and face this error:

/home/.dub/packages/mir-core-1.1.11/mir-core/source/mir/math/ieee.d:974: undefined reference to `_D3mir10checkedint4addsFNaNbNiNfiiKbZi'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
../blackbird//etc/build.makefile:295: recipe for target 'tools/mir_utils.d:unittest' failed
make: *** [tools/mir_utils.d:unittest] Error 1


What can be the reason?
September 09, 2020
On Wednesday, 9 September 2020 at 11:43:16 UTC, Fynn Schröder wrote:
> On Wednesday, 9 September 2020 at 11:36:56 UTC, Shaleen Chhabra wrote:
>> but i am unable to configure the libraries, have dmd v2.076.1 installed on my PC.
>
> DMD v2.076 is ancient (almost 2 years old!). Current is DMD 2.093.1. I can only recommend to download and install an up-to-date version of DMD or LDC. This should solve your issues with using the mir libraries (and others). Then, try to get a simple example from numir working with your installation.

Hi, I updated my dmd version to dmd-2.093.1
Now it throws a conflict error between

1. function mir.ndslice.topology.iota!(long, 1LU).iota at mir/ndslice/topology.d(630) conflicts with function std.range.iota!int.iota at /home/shaleen/.dvm/compilers/dmd-2.093.1/linux/bin/../../src/phobos/std/range/package.d

2. template mir.ndslice.topology.map(fun...) if (fun.length) at mir/ndslice/topology.d(2565) conflicts with template std.algorithm.iteration.map(fun...) if (fun.length >= 1) at /home/shaleen/.dvm/compilers/dmd-2.093.1/linux/bin/../../src/phobos/std/algorithm/iteration.d(482)



September 09, 2020
On Wednesday, 9 September 2020 at 15:30:33 UTC, Shaleen Chhabra wrote:
> [snip]
>
> Hi, I updated my dmd version to dmd-2.093.1
> Now it throws a conflict error between
>
> 1. function mir.ndslice.topology.iota!(long, 1LU).iota at mir/ndslice/topology.d(630) conflicts with function std.range.iota!int.iota at /home/shaleen/.dvm/compilers/dmd-2.093.1/linux/bin/../../src/phobos/std/range/package.d
>
> 2. template mir.ndslice.topology.map(fun...) if (fun.length) at mir/ndslice/topology.d(2565) conflicts with template std.algorithm.iteration.map(fun...) if (fun.length >= 1) at /home/shaleen/.dvm/compilers/dmd-2.093.1/linux/bin/../../src/phobos/std/algorithm/iteration.d(482)

Below would generate the same error for iota. There are iota functions in std.range and mir.ndslice.topology and the compiler does not know which one to use. You can use one or the other or use static imports.

In the future, it will be a little easier to identify the issues if you post the code as well. You can also start with simpler examples and work your way to larger ones.

```
/+dub.sdl:
dependency "mir-algorithm" version="*"
+/
import std.range;
import mir.ndslice.topology;

void main()
{
    auto x = iota(5);
}
```