Re: forcing tabs in regex
On Wednesday, 28 February 2018 at 05:09:03 UTC, psychoticRabbit wrote: On Wednesday, 28 February 2018 at 01:06:30 UTC, dark777 wrote: Regex validates years bisexto and not bisextos in format: const std::regex pattern(R"(^(?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec|[Ff]eb)|(29|30)([-/.])(0?[13-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec)|(31)([-/.])(0?[13578]|1[02]|[Jj]an|[Mm]a[ry]|[Jj]ul|[Aa]ug|[Oo]ct|[Dd]ec))(?:\2|\5|\8)(0{2,3}[1-9]|0{1,2}[1-9]\d|0?[1-9]\d{2}|[1-9]\d{3})|(29)([-/.])(0?2|[Ff]eb)\12(\d{1,2}(?:0[48]|[2468][048]|[13579][26])|(?:0?[48]|[13579][26]|[2468][048])00))$)"); this regex above validates the formats through backreferences. what is this evil dark magic? Something that is horribly slow and might be incorrect, there are very few reasons to write large regexes like that and they usually boil down to “it only accepts regex” otherwise parser combinators are much better fit.
Re: forcing tabs in regex
On Wednesday, 28 February 2018 at 01:06:30 UTC, dark777 wrote: Regex validates years bisexto and not bisextos in format: const std::regex pattern(R"(^(?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec|[Ff]eb)|(29|30)([-/.])(0?[13-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec)|(31)([-/.])(0?[13578]|1[02]|[Jj]an|[Mm]a[ry]|[Jj]ul|[Aa]ug|[Oo]ct|[Dd]ec))(?:\2|\5|\8)(0{2,3}[1-9]|0{1,2}[1-9]\d|0?[1-9]\d{2}|[1-9]\d{3})|(29)([-/.])(0?2|[Ff]eb)\12(\d{1,2}(?:0[48]|[2468][048]|[13579][26])|(?:0?[48]|[13579][26]|[2468][048])00))$)"); this regex above validates the formats through backreferences. what is this evil dark magic?
Re: What's the latest news for calling D from python 3 using ctypes?
On Wednesday, 28 February 2018 at 02:40:59 UTC, Nicholas Wilson wrote: On Wednesday, 28 February 2018 at 01:19:25 UTC, Enjoys Math wrote: [...] For some reason, idk why, PyD is a dub source dependency (as opposed to a library). If you add \path\to\pyd to the include directory(?) dub variable (or -I\path\to\pyd to dmd/ldc/gdc) it should hopefully work. , This is a great article. It gave me a lot of useful information. thank you very much. Link profile: http://phongkhamdakhoathegioi.vn/me-day-ve-noi-va-cach-chua-tri-hieu-qua.html
Re: What's the latest news for calling D from python 3 using ctypes?
On Wednesday, 28 February 2018 at 01:19:25 UTC, Enjoys Math wrote: Can't build now: -- Build started: Project: categorytheorybackend, Configuration: debug Win32 -- Building C:\MyProjects\___ENJOYS_MATH\CategoryTheoryFrontend\CategoryTheoryBackend\categorytheorybackend.exe... Error: Error writing file 'obj\debug\dummy\dummy\dummy\dummy\dummy\categorytheorybackend\..\..\..\..\..\Users\FruitfulApproach\AppData\Roaming\dub\packages\pyd-0.9.9\pyd\infrastructure\deimos\python\abstract_.obj' Building C:\MyProjects\___ENJOYS_MATH\CategoryTheoryFrontend\CategoryTheoryBackend\categorytheorybackend.exe failed! Details saved as "file://C:\MyProjects\___ENJOYS_MATH\CategoryTheoryFrontend\CategoryTheoryBackend\.dub\obj\debug\dummy\dummy\dummy\dummy\dummy\categorytheorybackend\categorytheorybackend.buildlog.html" == Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped == For some reason, idk why, PyD is a dub source dependency (as opposed to a library). If you add \path\to\pyd to the include directory(?) dub variable (or -I\path\to\pyd to dmd/ldc/gdc) it should hopefully work.
Re: What's the latest news for calling D from python 3 using ctypes?
On Wednesday, 28 February 2018 at 00:18:17 UTC, Nicholas Wilson wrote: On Tuesday, 27 February 2018 at 23:59:10 UTC, Enjoys Math wrote: I am making a library that will run very speedily in D (or, failing that, C++) and do the backend work of a PyQt5 gui. Was wondering the simplest route to accomplish this, preferably in ctypes calls. Thanks. http://code.dlang.org/packages/pyd With PyD you can wrap the D functions for python instead of calling them through types in python. How would you get VisualD + PyD to work nicely together? See my failed build post above.
Re: What's the latest news for calling D from python 3 using ctypes?
Can't build now: -- Build started: Project: categorytheorybackend, Configuration: debug Win32 -- Building C:\MyProjects\___ENJOYS_MATH\CategoryTheoryFrontend\CategoryTheoryBackend\categorytheorybackend.exe... Error: Error writing file 'obj\debug\dummy\dummy\dummy\dummy\dummy\categorytheorybackend\..\..\..\..\..\Users\FruitfulApproach\AppData\Roaming\dub\packages\pyd-0.9.9\pyd\infrastructure\deimos\python\abstract_.obj' Building C:\MyProjects\___ENJOYS_MATH\CategoryTheoryFrontend\CategoryTheoryBackend\categorytheorybackend.exe failed! Details saved as "file://C:\MyProjects\___ENJOYS_MATH\CategoryTheoryFrontend\CategoryTheoryBackend\.dub\obj\debug\dummy\dummy\dummy\dummy\dummy\categorytheorybackend\categorytheorybackend.buildlog.html" == Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==
Re: What's the latest news for calling D from python 3 using ctypes?
On Wednesday, 28 February 2018 at 01:10:36 UTC, Enjoys Math wrote: Got it. dub init myproject from within my python frontend source dir will create a subdirectory. Then you do dub generate visuald from within the subdir myproject.
Re: What's the latest news for calling D from python 3 using ctypes?
Got it. dub init myproject from within my python frontend source dir will create a subdirectory.
forcing tabs in regex
Regex validates years bisexto and not bisextos in format: const std::regex pattern(R"(^(?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec|[Ff]eb)|(29|30)([-/.])(0?[13-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec)|(31)([-/.])(0?[13578]|1[02]|[Jj]an|[Mm]a[ry]|[Jj]ul|[Aa]ug|[Oo]ct|[Dd]ec))(?:\2|\5|\8)(0{2,3}[1-9]|0{1,2}[1-9]\d|0?[1-9]\d{2}|[1-9]\d{3})|(29)([-/.])(0?2|[Ff]eb)\12(\d{1,2}(?:0[48]|[2468][048]|[13579][26])|(?:0?[48]|[13579][26]|[2468][048])00))$)"); this regex above validates the formats through backreferences. dd-mm- ou dd-str- ou dd-Str- dd/mm/ ou dd/str/ ou dd/Str/ dd.mm. ou dd.str. ou dd.Str. Regex validates years bisexto and not bisextos in format: const std::regex pattern(R"(^(?:\d{4}([-/.])(?:(?:(?:(?:0?[13578]|1[02]|[Jj](?:an|ul)|[Mm]a[ry]|[Aa]ug|[Oo]ct|[Dd]ec)([-/.])(?:0?[1-9]|[1-2][0-9]|3[01]))|(?:(?:0?[469]|11|[Aa]pr|[Jj]un|[Ss]ep|[Nn]ov)([-/.])(?:0?[1-9]|[1-2][0-9]|30))|(?:(0?2|[Ff]eb)([-/.])(?:0?[1-9]|1[0-9]|2[0-8]|(?:(?:\d{2}(?:0[48]|[2468][048]|[13579][26]))|(?:(?:[02468][048])|[13579][26])00)([-/.])(0?2|[Ff]eb)([-/.])29)$)"); this regex above had to validate the formats through backreferences. but it is validating in the following formats -mm/dd ou -str/dd ou -Str/dd /mm.dd ou /str.dd ou /Str.dd .mm-dd ou .str-dd ou .Str-dd when it had to validate only in the following formats -mm-dd ou -str-dd ou -Str-dd /mm/dd ou /str/dd ou /Str/dd .mm.dd ou .str.dd ou .Str.dd how do I do it validate only with some of the tabs?
Re: What's the latest news for calling D from python 3 using ctypes?
On Wednesday, 28 February 2018 at 00:18:17 UTC, Nicholas Wilson wrote: On Tuesday, 27 February 2018 at 23:59:10 UTC, Enjoys Math wrote: I am making a library that will run very speedily in D (or, failing that, C++) and do the backend work of a PyQt5 gui. Was wondering the simplest route to accomplish this, preferably in ctypes calls. Thanks. http://code.dlang.org/packages/pyd With PyD you can wrap the D functions for python instead of calling them through types in python. Thank you! That looks like what I need. How do you install pyd with dub so that I can import ? dub fetch pyd dub run pyd doesn't work. Will try other params and get back to this thread.
Re: What's the latest news for calling D from python 3 using ctypes?
On Tuesday, 27 February 2018 at 23:59:10 UTC, Enjoys Math wrote: I am making a library that will run very speedily in D (or, failing that, C++) and do the backend work of a PyQt5 gui. Was wondering the simplest route to accomplish this, preferably in ctypes calls. Thanks. http://code.dlang.org/packages/pyd With PyD you can wrap the D functions for python instead of calling them through types in python.
Re: Equivalent to Python with Statement
On Tuesday, 27 February 2018 at 16:18:43 UTC, Stefan Koch wrote: On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote: I know Python's `with` statement can be used to have an automatic close action: ``` with open("x.txt") as file: #do something with file #`file.close()` called automatically ``` I know D's `with` statement does something different but is there some sort of equivalent? In this case with(File("bla")) will do the same. FWIW std.stdio.File is refcounted and will be automatically closed at the end of the scope. So typically you don't even need `with` ;-) @Jonathan: have a look at these two examples to see what DMD does under the hood: https://run.dlang.io/is/89NBxI https://run.dlang.io/is/eXC7ZV
What's the latest news for calling D from python 3 using ctypes?
I am making a library that will run very speedily in D (or, failing that, C++) and do the backend work of a PyQt5 gui. Was wondering the simplest route to accomplish this, preferably in ctypes calls. Thanks.
Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
On Tuesday, 27 February 2018 at 21:54:34 UTC, Nathan S. wrote: Cross-posting from the github issue (https://github.com/libmir/mir-random/issues/77) with a workaround (execute it at https://run.dlang.io/is/Swr1xU): [snip] Step in the right direction at least.
Re: Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]
On Tuesday, 27 February 2018 at 22:17:25 UTC, Jonathan wrote: On Tuesday, 27 February 2018 at 22:13:05 UTC, Jonathan wrote: Is it possible to cast a 2d static length array to a 1d static length array? E.g. int[2][2] a = [[1,2],[3,4]]; int[4]b = cast(int[4])a; Is not the byte data in memory exactly the same? *( [pos,size].ptr .cst!(void*) .cst!(int[4]*) ) (using dub `cst` library) or *( cast(int[4]*)(cast(void*)([pos,size].ptr)) ) Okay, this works but is this the best way?! This should work int[4] b = *(cast(int[4]*)a.ptr);
Re: Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]
On Tuesday, 27 February 2018 at 22:13:05 UTC, Jonathan wrote: Is it possible to cast a 2d static length array to a 1d static length array? E.g. int[2][2] a = [[1,2],[3,4]]; int[4]b = cast(int[4])a; Is not the byte data in memory exactly the same? *( [pos,size].ptr .cst!(void*) .cst!(int[4]*) ) (using dub `cst` library) or *( cast(int[4]*)(cast(void*)([pos,size].ptr)) ) Okay, this works but is this the best way?!
Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]
Is it possible to cast a 2d static length array to a 1d static length array? E.g. int[2][2] a = [[1,2],[3,4]]; int[4]b = cast(int[4])a; Is not the byte data in memory exactly the same?
Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
Cross-posting from the github issue (https://github.com/libmir/mir-random/issues/77) with a workaround (execute it at https://run.dlang.io/is/Swr1xU): I am not sure what the correct interface should be for this in the long run, but for now you can use a wrapper function to convert an ndvariable to a variable: ```d /++ Converts an N-dimensional variable to a fixed-dimensional variable. +/ auto specifyDimension(ReturnType, NDVariable)(NDVariable vr) if (__traits(isStaticArray, ReturnType) && __traits(compiles, {static assert(NDVariable.isRandomVariable);})) { import mir.random : isSaturatedRandomEngine; import mir.random.variable : isRandomVariable; static struct V { enum bool isRandomVariable = true; NDVariable vr; ReturnType opCall(G)(scope ref G gen) if (isSaturatedRandomEngine!G) { ReturnType ret; vr(gen, ret[]); return ret; } ReturnType opCall(G)(scope G* gen) if (isSaturatedRandomEngine!G) { return opCall!(G)(*gen); } } static assert(isRandomVariable!V); V v = { vr }; return v; } ``` So `main` from your above example becomes: ```d void main() { import std.stdio; import mir.random : Random, threadLocalPtr; import mir.random.ndvariable : multivariateNormalVar; import mir.random.algorithm : range; import mir.ndslice.slice : sliced; import std.range : take; auto mu = [10.0, 0.0].sliced; auto sigma = [2.0, -1.5, -1.5, 2.0].sliced(2,2); Random* rng = threadLocalPtr!Random; auto sample = rng .range(multivariateNormalVar(mu, sigma).specifyDimension!(double[2])) .take(10); writeln(sample); } ```
Re: Struct ctor called with cast
On Tuesday, 27 February 2018 at 21:04:59 UTC, ag0aep6g wrote: On 02/27/2018 09:59 PM, Radu wrote: On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote: On 02/27/2018 09:30 PM, Radu wrote: [...] [...] [...] So the bug is that somehow the templated version makes it so there is an implicit void* ctor. In your original code (quoted above), you've got a templated constructor. The `Type` in `this(Type)(Type t)` is not the enum. It's a template parameter of the constructor. To get a non-templated constructor that takes a `Type` (the enum), you have to write: this(Type t) /* NOTE: Only one set of parentheses. */ { /* ... */ } Understood, make sense now, thanks!
Re: Struct ctor called with cast
On 2/27/18 3:59 PM, Radu wrote: On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote: On 02/27/2018 09:30 PM, Radu wrote: enum Type { a }; struct S(Type t = Type.a) { this(Type)(Type t) { import std.stdio; writeln("ctor called."); } } void main() { auto x = S!(Type.a)(Type.a); void* y = auto z = (cast(S!(Type.a)) y); } [snip] So the bug is that somehow the templated version makes it so there is an implicit void* ctor. Look at your constructor. You actually have a TEMPLATED constructor inside a TEMPLATED type. In other words, inside your constructor, `Type` is not an enum Type, it's actually a void *. It becomes clearer if you change the name of the second template parameter: struct S(Type t = Type.a) { this(T)(T t) { import std.stdio; writeln("ctor called."); } } -Steve
Re: Struct ctor called with cast
On 02/27/2018 09:59 PM, Radu wrote: On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote: On 02/27/2018 09:30 PM, Radu wrote: [...] enum Type { a }; struct S(Type t = Type.a) { this(Type)(Type t) { import std.stdio; writeln("ctor called."); } } [...] So the bug is that somehow the templated version makes it so there is an implicit void* ctor. In your original code (quoted above), you've got a templated constructor. The `Type` in `this(Type)(Type t)` is not the enum. It's a template parameter of the constructor. To get a non-templated constructor that takes a `Type` (the enum), you have to write: this(Type t) /* NOTE: Only one set of parentheses. */ { /* ... */ }
Re: Struct ctor called with cast
On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote: On 02/27/2018 09:30 PM, Radu wrote: enum Type { a }; struct S(Type t = Type.a) { this(Type)(Type t) { import std.stdio; writeln("ctor called."); } } void main() { auto x = S!(Type.a)(Type.a); void* y = auto z = (cast(S!(Type.a)) y); } Surprisingly the cast will actually call the ctor. Is this to be expected? Sure looks like a bug to me, as a non templated S will complain about the cast. Not a bug. The spec says [1]: "Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: S(v)" Templates have nothing to do with it. Your code boils down to this: struct S { this(void* t) { import std.stdio; writeln("ctor called."); } } void main() { void* y; auto z = cast(S) y; } [1] https://dlang.org/spec/expression.html#cast_expressions OK, got it - thanks. But this: struct S { this(int t) { import std.stdio; writeln("ctor called."); } } void main() { auto x = S(1); void* y = auto z = (cast(S) y); } Produces: Error: cannot cast expression y of type void* to S Which is kinda correct as I don't have any ctor in S taking a void*. Adding this(void* t) { import std.stdio; writeln("ctor called."); } Will make the error go away. So the bug is that somehow the templated version makes it so there is an implicit void* ctor.
Re: Struct ctor called with cast
On 02/27/2018 09:30 PM, Radu wrote: enum Type { a }; struct S(Type t = Type.a) { this(Type)(Type t) { import std.stdio; writeln("ctor called."); } } void main() { auto x = S!(Type.a)(Type.a); void* y = auto z = (cast(S!(Type.a)) y); } Surprisingly the cast will actually call the ctor. Is this to be expected? Sure looks like a bug to me, as a non templated S will complain about the cast. Not a bug. The spec says [1]: "Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: S(v)" Templates have nothing to do with it. Your code boils down to this: struct S { this(void* t) { import std.stdio; writeln("ctor called."); } } void main() { void* y; auto z = cast(S) y; } [1] https://dlang.org/spec/expression.html#cast_expressions
Re: How do I trace that memory error?
On Tuesday, 27 February 2018 at 16:55:27 UTC, Marc wrote: [...] So deep down the error is in that method which I call from deserializeLine() function: void setValue(T, V)(auto ref T aggregate, string field, V value) { writeln("setting {", field, "} to {", value, "}"); import std.traits : FieldNameTuple; import std.meta : Alias; switch (field) { foreach (fieldName; FieldNameTuple!T) { case fieldName: static if (is(typeof(__traits(getMember, aggregate, fieldName) = value))) { __traits(getMember, aggregate, fieldName) = value; return; } else { assert(false, T.stringof ~ "."~field~" cannot be assigned from a "~V.stringof~"."); } } default: assert(false, T.stringof ~ " has no field named "~field~"."); } } the function is used like this: Field field = new Field(); foreach(CSVLinkedIndex linkedIndex; linkedIndexes) { string value = values[linkedIndex.csv_column_index]; setValue(field, linkedIndex.field_member, value); } which eventually (in about 8 calls) return the error: core.exception.OutOfMemoryError@src\core\exception.d(702): Memory allocation failed it uses about 4MB in a 8GB machine then crashs. It's return by the top function using yield: yield(field); But I can't find out why gc fails to allocate at some point. In fact, I've forced the gc to do so in my top loop: foreach(Field field; deserializeFile()) { scope(exit) { import core.memory : GC; GC.collect(); } } Which didn't solve the issue.
Struct ctor called with cast
I have this: enum Type { a }; struct S(Type t = Type.a) { this(Type)(Type t) { import std.stdio; writeln("ctor called."); } } void main() { auto x = S!(Type.a)(Type.a); void* y = auto z = (cast(S!(Type.a)) y); } Surprisingly the cast will actually call the ctor. Is this to be expected? Sure looks like a bug to me, as a non templated S will complain about the cast.
Re: Equivalent to Python with Statement
yes, for classes you can use scoped: import std.stdio; import std.typecons : scoped; class A { void saySomething() { writeln("Hi from A"); } ~this() { writeln("Destruct A"); } } void main() { with(scoped!A()) { saySomething(); writeln("something"); } writeln("Hello D"); } On Tue, Feb 27, 2018 at 5:25 PM, Jonathan via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 27 February 2018 at 16:18:43 UTC, Stefan Koch wrote: > >> On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote: >> >>> I know Python's `with` statement can be used to have an automatic close >>> action: >>> ``` >>> with open("x.txt") as file: >>> #do something with file >>> #`file.close()` called automatically >>> ``` >>> >>> I know D's `with` statement does something different but is there some >>> sort of equivalent? >>> >> >> In this case with(File("bla")) >> will do the same. >> > > Oh really, cool. > > Is this just because the scope of the file variable will end and thus its > `~this`? > >
Re: Validity of cast(void*)size_t.max
On 02/27/2018 11:56 AM, Steven Schveighoffer wrote: On 2/27/18 11:37 AM, Nordlöw wrote: On Tuesday, 27 February 2018 at 16:31:51 UTC, Steven Schveighoffer wrote: Why not use null? It's already used to indicate that a slot is free. :) cast(void*)1 is likely to be unused. -Steve And to be sure, one can have an actual object that represents nullness and use its pointer. (Similar to "the null object pattern".) Ali
Re: Validity of cast(void*)size_t.max
On 2/27/18 11:37 AM, Nordlöw wrote: On Tuesday, 27 February 2018 at 16:31:51 UTC, Steven Schveighoffer wrote: Why not use null? It's already used to indicate that a slot is free. :) cast(void*)1 is likely to be unused. -Steve
Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
On Tuesday, 27 February 2018 at 17:24:22 UTC, Nathan S. wrote: On Tuesday, 27 February 2018 at 16:42:00 UTC, Nathan S. wrote: On Tuesday, 27 February 2018 at 15:08:42 UTC, jmh530 wrote: Nevertheless, it probably can't hurt to file an issue if you can't get something like the first one to work. I would think it should just work. The problem is that `mir.random.ndvariable` doesn't satisfy `mir.random.variable.isRandomVariable!T`. ndvariables have a slightly different interface from variables: instead of of `rv(gen)` returning a result, `rv(gen, dst)` writes to dst. I agree that the various methods for working with variables should be enhanced to work with ndvariables. So, I see that the interface will have to be slightly different for ndvariable than for variable. With the exception of MultivariateNormalVariable, the same ndvariable instance can be called to fill output of any length "n", so one can't meaningfully create a range based on just the ndvariable without further specification. What would "front" return? For MultivariateNormalVariable "n" is constrained but it is a runtime parameter rather than a compile-time parameter. You'll want to ping @9il / Ilya Yaroshenko to discuss what the API should be like for this. Honestly, I think the post above was my first use of mir.random, so I'm nowhere near familiar enough at this point to add much useful feedback. I'm definitely glad that it is getting worked on and plan on using it in the future. The only thing I would note is that there are not just N-dimensional random variables, there are also NXN dimensional random variables (not sure what else there could be, but it would be significantly less popular). A Wishart distribution (used for the distribution of covariance matrices) can be simulated by multiplying the transpose of a multivariate random normal by itself. This produces an NXN matrix. Ideally, the API could handle this type of distribution as well. Another type of distribution I sometimes see is from Bayesian statistics (less common than typical distributions and could probably be built on top of what is already in mir.random, but I figured it couldn't hurt to bring it to your attention). A normal-inverse-gamma distribution is one example of these types of distributions. Simulating from this distribution would produce a pair of the mean and variance, not just one value. This would contrast with multivariate normal in that you would know it has two dimensions at compile-time.
Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
On Tuesday, 27 February 2018 at 16:42:00 UTC, Nathan S. wrote: On Tuesday, 27 February 2018 at 15:08:42 UTC, jmh530 wrote: Nevertheless, it probably can't hurt to file an issue if you can't get something like the first one to work. I would think it should just work. The problem is that `mir.random.ndvariable` doesn't satisfy `mir.random.variable.isRandomVariable!T`. ndvariables have a slightly different interface from variables: instead of of `rv(gen)` returning a result, `rv(gen, dst)` writes to dst. I agree that the various methods for working with variables should be enhanced to work with ndvariables. So, I see that the interface will have to be slightly different for ndvariable than for variable. With the exception of MultivariateNormalVariable, the same ndvariable instance can be called to fill output of any length "n", so one can't meaningfully create a range based on just the ndvariable without further specification. What would "front" return? For MultivariateNormalVariable "n" is constrained but it is a runtime parameter rather than a compile-time parameter. You'll want to ping @9il / Ilya Yaroshenko to discuss what the API should be like for this.
Re: How do I trace that memory error?
On Tuesday, 27 February 2018 at 15:08:23 UTC, Stefan Koch wrote: On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do I find out the source of the error? I'd say allocating in a loop is a bad idea :) perhaps you should start with posting the code that leads to this. I've also tried to create only one instance: create a local variable inside the method then reuse it. I get same error. No debugg tool has helped so far.
Re: How do I trace that memory error?
On Tuesday, 27 February 2018 at 15:08:23 UTC, Stefan Koch wrote: On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do I find out the source of the error? I'd say allocating in a loop is a bad idea :) perhaps you should start with posting the code that leads to this. The code is that one on my second post. The deserializeLine() create allocate instance of Field then return. So yeah, I'm allocating on loop but I don't doing too much. I was watching the memory usage of the application (with win10 taskbar memory usage feature) and I saw it uses only about 4mb on 8gb machine. I've tried build a 64bit executable but I got same error.
Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
On Tuesday, 27 February 2018 at 15:08:42 UTC, jmh530 wrote: Nevertheless, it probably can't hurt to file an issue if you can't get something like the first one to work. I would think it should just work. The problem is that `mir.random.ndvariable` doesn't satisfy `mir.random.variable.isRandomVariable!T`. ndvariables have a slightly different interface from variables: instead of of `rv(gen)` returning a result, `rv(gen, dst)` writes to dst. I agree that the various methods for working with variables should be enhanced to work with ndvariables.
Re: Validity of cast(void*)size_t.max
On Tuesday, 27 February 2018 at 16:31:51 UTC, Steven Schveighoffer wrote: Why not use null? -Steve It's already used to indicate that a slot is free. :)
Re: Validity of cast(void*)size_t.max
On 2/27/18 9:13 AM, Nordlöw wrote: Is `cast(void*)size_t.max` always an invalid address? You mean, can it point at valid data? Possibly, but likely not. In my past as an embedded developer, a lot of times the interrupt vectors are stored at the end of address space. Is so, could it be used to indicate removed/delete elements in hash tables with open addressing and a key type being either a pointer or class? Why not use null? -Steve
Re: Equivalent to Python with Statement
On Tuesday, 27 February 2018 at 16:18:43 UTC, Stefan Koch wrote: On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote: I know Python's `with` statement can be used to have an automatic close action: ``` with open("x.txt") as file: #do something with file #`file.close()` called automatically ``` I know D's `with` statement does something different but is there some sort of equivalent? In this case with(File("bla")) will do the same. Oh really, cool. Is this just because the scope of the file variable will end and thus its `~this`?
Equivalent to Python with Statement
I know Python's `with` statement can be used to have an automatic close action: ``` with open("x.txt") as file: #do something with file #`file.close()` called automatically ``` I know D's `with` statement does something different but is there some sort of equivalent?
Re: Equivalent to Python with Statement
On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote: I know Python's `with` statement can be used to have an automatic close action: ``` with open("x.txt") as file: #do something with file #`file.close()` called automatically ``` I know D's `with` statement does something different but is there some sort of equivalent? In this case with(File("bla")) will do the same.
Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
On Tuesday, 27 February 2018 at 09:23:49 UTC, kerdemdemir wrote: I need a classifier in my project. Since it is I believe most easy to implement I am trying to implement logistic regression. I am trying to do the same as the python example: https://beckernick.github.io/logistic-regression-from-scratch/ I need to data sets with which I will test. This works(https://run.dlang.io/is/yGa4a0) : double[2] x1; Random* gen = threadLocalPtr!Random; auto mu = [0.0, 0.0].sliced; auto sigma = [1.0, 0.75, 0.75, 1].sliced(2,2); auto rv = multivariateNormalVar(mu, sigma); rv(gen, x1[]); writeln(x1); But when I increase my data set size from double[2] to double[100] I am getting an assert : mir-random-0.4.3/mir-random/source/mir/random/ndvariable.d(378): Assertion failure which is: assert(result.length == n); How can I have a result vector which has size like 5000 something? Erdemdem I haven't made much use of mir.random yet... The dimension 2 in this case is the size of the dimension of the random variable. What you want to do is simulate multiple times from this 2-dimensional random variable. It looks like the examples on the main Readme page uses mir.random.algorithm.range. I tried below, but I got errors. I did notice that the MultivariateNormalVariable documentation says that it is in beta still. void main() { import mir.random : Random, unpredictableSeed; import mir.random.ndvariable : MultivariateNormalVariable; import mir.random.algorithm : range; import mir.ndslice.slice : sliced; import std.range : take; auto mu = [10.0, 0.0].sliced; auto sigma = [2.0, -1.5, -1.5, 2.0].sliced(2,2); auto rng = Random(unpredictableSeed); auto sample = range!rng (MultivariateNormalVariable!double(mu, sigma)) .take(10); } However, doing it manually with a for loop works. void main() { import mir.random : rne; import mir.random.ndvariable : multivariateNormalVar; import mir.random.algorithm : range; import mir.ndslice.slice : sliced; import std.stdio : writeln; auto mu = [10.0, 0.0].sliced; auto sigma = [2.0, -1.5, -1.5, 2.0].sliced(2,2); auto rv = multivariateNormalVar(mu, sigma); double[2][100] x; for (size_t i = 0; i < 100; i++) { rv(rne, x[i][]); } writeln(x); } Nevertheless, it probably can't hurt to file an issue if you can't get something like the first one to work. I would think it should just work.
Re: How do I trace that memory error?
On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do I find out the source of the error? I'd say allocating in a loop is a bad idea :) perhaps you should start with posting the code that leads to this.
Re: How do I trace that memory error?
On Tuesday, 27 February 2018 at 14:06:19 UTC, Nicholas Wilson wrote: On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do I find out the source of the error? "received signal ?" seems like the one of the GC signals used for stopping threads. just get gdb to ignore those. An attempt to continue results in crash. I also added in my foreach's body: scope(exit) { import core.memory : GC; GC.collect(); } But also doesn't solve the issue.
Re: CMake support for D
On Tuesday, 27 February 2018 at 09:20:21 UTC, Russel Winder wrote: On Mon, 2018-02-26 at 20:28 +, King_DuckZ via Digitalmars-d-learn wrote: […] One [more] year ahead, and I found this old thread I had forgotten about. In the meantime, trentforkert has stopped (apparently) working on cmake, and dcarp's has failed me for projects larger than a couple files. It also looks like it's not receiving updates anymore. The DCarp CMake-D repository is active. If it doesn't work then it just needs more work. All of this kept me away from D. Now that gdc is rumoured to get merged into gcc 8 tho, is there any concrete chance of this happening? I think even rust (which came out after D) has decent cmake support at this point. As far as I am aware CMake is not used for Rust, the vast majority of people use Cargo. This mean it is certain some Rust people will use CMake. :-) It is worth noting that the Rust plugin to CLion does not require CMake, it uses Cargo. CLion not IDEA is not the focus of the Rust plugin due to debugging. CLion is the platform for all native code language for JetBrains as I understand it exacly because of debugging support. I believe the work on D plugin support for IntelliJ IDEA should refocus on CLion. It can still use Dub it seems, and it can get access to the debugging framework. Clearly it would still be good in D had CMake support. It strikes me the DCarp's CMake-D repository is the one to support. Right, I stand corrected about Rust, though as you say there are those who use it with CMake. About cmake-d, there's this https://github.com/dcarp/cmake-d/issues/19, which I could work around. More seriously though, it doesn't track dependencies between .d files. So if for example you have: // a.d void foo() {} // b.d import a; int main() { foo(); return 0; } and compile it, all goes well. Now if you change a to be: //a.d void foo(a=10) { //use a somewhere } and just 'make' then you're in for some really funky crash (it may not be the exact code, but I had a problem very similar to this). The only fix is make clean; make. This is really hard to spot as soon as you start having more than a couple files, and it's really something the build system should take care of. Unfortunately I don't think a purely scripted solution for cmake will ever be able to handle this problem. Speaking of CLion, at this point I've pretty much abandoned it, vim is more than enough for me. My problem is mixing D with C and C++, and with being already so familiar with CMake that starting all over again just puts me off to the point I'd rather not do any D at all. Build systems are not my passion really, and learning CMake was already painful enough.
Validity of cast(void*)size_t.max
Is `cast(void*)size_t.max` always an invalid address? Is so, could it be used to indicate removed/delete elements in hash tables with open addressing and a key type being either a pointer or class? And will it work correctly with the GC?
Re: How do I trace that memory error?
On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do I find out the source of the error? "received signal ?" seems like the one of the GC signals used for stopping threads. just get gdb to ignore those.
Re: iota to array
On 2/26/18 6:34 PM, psychoticRabbit wrote: On Sunday, 25 February 2018 at 14:52:19 UTC, Steven Schveighoffer wrote: 1 == 1.0, no? no. at least, not when a language forces you to think in terms of types. But you aren't. You are thinking in terms of text representation of values (which is what a literal is). This works just fine: double x = 1; double y = 1.0; assert(x == y); The same generated code to store 1 into x is used to store 1.0 into y. There is no difference to the compiler, it's just different in the source code. I admit, I've never printed output without using format specifiers, but still, if I say write(1.0), it should not go off and print what looks to me, like an int. If it didn't, I'm sure others would complain about it :) Inheriting crap from C is no excuse ;-) and what's going on here btw? assert( 1 == 1.01 ); // assertion error in DMD but not in LDC assert( 1 == 1.001 ); // no assertion error?? Floating point is not exact. In fact, even the one that asserts, cannot be accurately represented internally. At some decimal place, it cannot store any more significant digits, so it just approximates. You may want to just get used to this, it's the way floating point has -Steve
Re: Derelict GLFW3 and dynamic linking on Linux
On Tuesday, 27 February 2018 at 13:14:38 UTC, Mike Parker wrote: On Tuesday, 27 February 2018 at 12:00:20 UTC, Kayomn wrote: [...] It *is* a version problem. The exception is a SymbolLoadException, which means the loader found the library just fine (you can see it in the file name, libglfw.so.3.1). However, it attempted to load `glfwSetWindowIcon` and failed. If you check the GLFW 3 documentation [1] you'll find the following: [...] Thanks for clearing that up, it's been bugging me for a while.
Re: Derelict GLFW3 and dynamic linking on Linux
On Tuesday, 27 February 2018 at 12:00:20 UTC, Kayomn wrote: derelict.util.exception.SymbolLoadException@../../.dub/packages/derelict-util-2.0.6/source/derelict/util/exception.d(35): Failed to load symbol glfwSetWindowIcon from shared library /u sr/lib/x86_64-linux-gnu/libglfw.so.3.1 I was reading this GitHub issue, and they seemed to describe the issue as being version incompatibilities: https://github.com/DerelictOrg/DerelictGLFW3/issues/9 However, I'm certain I'm using the correct GLWF version for my project. It *is* a version problem. The exception is a SymbolLoadException, which means the loader found the library just fine (you can see it in the file name, libglfw.so.3.1). However, it attempted to load `glfwSetWindowIcon` and failed. If you check the GLFW 3 documentation [1] you'll find the following: = Since Added in version 3.2. = Then, going to the DerelictGLFW3 documentation [2], you can see that DerelictGLFW3 2.0.0 was the last version to support 3.1. However, you can still use the latest version of the Derelict binding with GLFW 3.1 if you ignore the functions from 3.2. You can do this via the selective loading mechanism [3]. Of course, if you need any functions from 3.2, then you should update your local version of GLFW. [1] http://www.glfw.org/docs/latest/group__window.html#gadd7ccd39fe7a7d1f0904666ae5932dc5 [2] http://derelictorg.github.io/packages/glfw3/ [3] http://derelictorg.github.io/loading/failure/#selective-symbol-loading
Derelict GLFW3 and dynamic linking on Linux
Hi, I've been working on something using Windows and now I'm attempting to build it on Linux with Dub, however I appear to be having an issue. import base.application; import derelict.opengl3.gl3; import derelict.glfw3.glfw3; int main(string[] args) { DerelictGL3.load(); version (Windows) { DerelictGLFW3.load(".\\dll\\glfw3.dll"); } else { DerelictGLFW3.load("/usr/lib/x86_64-linux-gnu/libglfw.so"); } return Application(args).run(); } I've checked that the provided library object referenced exists, regardless every time I compile I get this same symbol loading error without fail: derelict.util.exception.SymbolLoadException@../../.dub/packages/derelict-util-2.0.6/source/derelict/util/exception.d(35): Failed to load symbol glfwSetWindowIcon from shared library /u sr/lib/x86_64-linux-gnu/libglfw.so.3.1 I was reading this GitHub issue, and they seemed to describe the issue as being version incompatibilities: https://github.com/DerelictOrg/DerelictGLFW3/issues/9 However, I'm certain I'm using the correct GLWF version for my project.
Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
I need a classifier in my project. Since it is I believe most easy to implement I am trying to implement logistic regression. I am trying to do the same as the python example: https://beckernick.github.io/logistic-regression-from-scratch/ I need to data sets with which I will test. This works(https://run.dlang.io/is/yGa4a0) : double[2] x1; Random* gen = threadLocalPtr!Random; auto mu = [0.0, 0.0].sliced; auto sigma = [1.0, 0.75, 0.75, 1].sliced(2,2); auto rv = multivariateNormalVar(mu, sigma); rv(gen, x1[]); writeln(x1); But when I increase my data set size from double[2] to double[100] I am getting an assert : mir-random-0.4.3/mir-random/source/mir/random/ndvariable.d(378): Assertion failure which is: assert(result.length == n); How can I have a result vector which has size like 5000 something? Erdemdem
Re: CMake support for D
On Mon, 2018-02-26 at 20:28 +, King_DuckZ via Digitalmars-d-learn wrote: > […] > > One [more] year ahead, and I found this old thread I had > forgotten about. In the meantime, trentforkert has stopped > (apparently) working on cmake, and dcarp's has failed me for > projects larger than a couple files. It also looks like it's not > receiving updates anymore. The DCarp CMake-D repository is active. If it doesn't work then it just needs more work. > All of this kept me away from D. Now that gdc is rumoured to get > merged into gcc 8 tho, is there any concrete chance of this > happening? I think even rust (which came out after D) has decent > cmake support at this point. As far as I am aware CMake is not used for Rust, the vast majority of people use Cargo. This mean it is certain some Rust people will use CMake. :-) It is worth noting that the Rust plugin to CLion does not require CMake, it uses Cargo. CLion not IDEA is not the focus of the Rust plugin due to debugging. CLion is the platform for all native code language for JetBrains as I understand it exacly because of debugging support. I believe the work on D plugin support for IntelliJ IDEA should refocus on CLion. It can still use Dub it seems, and it can get access to the debugging framework. Clearly it would still be good in D had CMake support. It strikes me the DCarp's CMake-D repository is the one to support. -- Russel. === Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Roadm: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk signature.asc Description: This is a digitally signed message part