Error: module ctype is in file 'std/ctype.d' which cannot be read - when running dmd
https://forum.dlang.org/post/idvspaicssrosayuc...@forum.dlang.org On Friday, 24 June 2016 at 21:06:30 UTC, cym13 wrote: On Friday, 24 June 2016 at 21:01:11 UTC, Roman wrote: I should probably add that only importing std.ctype causes the error. I have a bunch of other imports: import std.stdio, std.string, std.algorithm, std.conv, std.ctype, std.regex, std.range; If I remove std.ctype, it compiles just fine. std.ctype (as well as other c-specific bindings) was moved to core.stdc so just replace std.ctype by core.stdc.ctype and it should work as intended. Thank you!It's working.
Re: Multiplying transposed matrices in mir
On Monday, 20 April 2020 at 02:42:33 UTC, 9il wrote: On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: On Sunday, 19 April 2020 at 20:06:23 UTC, jmh530 wrote: [...] Thanks. I somehow missed the whole point of "a * a.transposed" not working because "a.transposed" is not allocated. In the same time, the SliceKind isn't matter for assignment operations: auto b = a.slice; // copy a to b b[] *= a.transposed; // works well BTW for the following operation auto b = a * a.transposed.slice; `b` isn't allocated as well because `*` is lazy. auto b = a.slice; // copy a to b b[] *= a.transposed; // works well So, the assignment operations are preferable anyway.
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: On Sunday, 19 April 2020 at 20:06:23 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 19:20:28 UTC, p.shkadzko wrote: [...] Ah, you're right. I use it in other places where it hasn't been an issue. I can do it with an allocation (below) using the built-in syntax, but not sure how do-able it is without an allocation (Ilya would know better than me). /+dub.sdl: dependency "lubeck" version="~>1.1.7" dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; import lubeck; void main() { auto a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed.slice; } Thanks. I somehow missed the whole point of "a * a.transposed" not working because "a.transposed" is not allocated. In the same time, the SliceKind isn't matter for assignment operations: auto b = a.slice; // copy a to b b[] *= a.transposed; // works well
Re: mir: How to change iterator?
On Sunday, 19 April 2020 at 22:07:30 UTC, jmh530 wrote: On Thursday, 16 April 2020 at 20:59:36 UTC, jmh530 wrote: [snip] /+dub.sdl: dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; void foo(Iterator, SliceKind kind)(Slice!(Iterator, 1, kind) x, Slice!(Iterator, 1, kind) y) { import std.stdio : writeln; writeln("here"); } void main() { auto x = [0.5, 0.5].sliced(2); auto y = x * 5.0; foo(x, y); } This is really what I was looking for (need to make allocation, unfortunately) /+dub.sdl: dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; void foo(Iterator, SliceKind kind)(Slice!(Iterator, 1, kind) x, Slice!(Iterator, 1, kind) y) { import std.stdio : writeln; writeln("here"); } void main() { auto x = [0.5, 0.5].sliced(2); auto y = x * 5.0; foo(x, y.slice); } Using two arguments Iterator1, Iterator2 works without allocation /+dub.sdl: dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; void foo(Iterator1, Iterator2, SliceKind kind) (Slice!(Iterator1, 1, kind) x, Slice!(Iterator2, 1, kind) y) { import std.stdio : writeln; writeln("here"); } void main() { auto x = [0.5, 0.5].sliced(2); auto y = x * 5.0; foo(x, y); }
Re: mir: How to change iterator?
On Thursday, 16 April 2020 at 20:59:36 UTC, jmh530 wrote: [snip] /+dub.sdl: dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; void foo(Iterator, SliceKind kind)(Slice!(Iterator, 1, kind) x, Slice!(Iterator, 1, kind) y) { import std.stdio : writeln; writeln("here"); } void main() { auto x = [0.5, 0.5].sliced(2); auto y = x * 5.0; foo(x, y); } This is really what I was looking for (need to make allocation, unfortunately) /+dub.sdl: dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; void foo(Iterator, SliceKind kind)(Slice!(Iterator, 1, kind) x, Slice!(Iterator, 1, kind) y) { import std.stdio : writeln; writeln("here"); } void main() { auto x = [0.5, 0.5].sliced(2); auto y = x * 5.0; foo(x, y.slice); }
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 20:29:54 UTC, p.shkadzko wrote: [snip] Thanks. I somehow missed the whole point of "a * a.transposed" not working because "a.transposed" is not allocated. a.transposed is just a view of the original matrix. Even when I tried to do a raw for loop I ran into issues because modifying the original a in any way caused all the calculations to be wrong. Honestly, it's kind of rare that I would do an element-wise multiplication of a matrix and its transpose.
Re: How to use import std.algorithm.iteration.permutations?
On Sunday, 19 April 2020 at 20:25:23 UTC, Basile B. wrote: On Sunday, 19 April 2020 at 17:57:21 UTC, David Zaragoza wrote: [...] `permutation()` returns a lazy range (i.e an iterator). To turn a permutation into a concrete data type use .array on each one. --- void test(int[] array){} void main() { int[] a = [1,1,2,2,3,3]; foreach (p; a.permutations) { test(p.array); } } --- forgot to put the imports: --- import std.algorithm.iteration, std.array; ---
Re: How to use import std.algorithm.iteration.permutations?
On Sunday, 19 April 2020 at 17:57:21 UTC, David Zaragoza wrote: Hi When I try to build the following: import std.algorithm.iteration; void test(int[] array); void main() { int[] a = [1,1,2,2,3,3]; foreach (p; a.permutations) { test(p); } } I get the error: .\permutations_example.d(10): Error: function permutations_example.test(int[] array) is not callable using argument types (Indexed!(int[], ulong[])) .\permutations_example.d(10):cannot pass argument p of type Indexed!(int[], ulong[]) to parameter int[] array What's the proper way to obtain the array of permutations of a? Kind regards David `permutation()` returns a lazy range (i.e an iterator). To turn a permutation into a concrete data type use .array on each one. --- void test(int[] array){} void main() { int[] a = [1,1,2,2,3,3]; foreach (p; a.permutations) { test(p.array); } } ---
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 20:06:23 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 19:20:28 UTC, p.shkadzko wrote: [snip] well no, "assumeContiguous" reverts the results of the "transposed" and it's "a * a". I would expect it to stay transposed as NumPy does "assert np.all(np.ascontiguous(a.T) == a.T)". Ah, you're right. I use it in other places where it hasn't been an issue. I can do it with an allocation (below) using the built-in syntax, but not sure how do-able it is without an allocation (Ilya would know better than me). /+dub.sdl: dependency "lubeck" version="~>1.1.7" dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; import lubeck; void main() { auto a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed.slice; } Thanks. I somehow missed the whole point of "a * a.transposed" not working because "a.transposed" is not allocated.
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 19:20:28 UTC, p.shkadzko wrote: [snip] well no, "assumeContiguous" reverts the results of the "transposed" and it's "a * a". I would expect it to stay transposed as NumPy does "assert np.all(np.ascontiguous(a.T) == a.T)". Ah, you're right. I use it in other places where it hasn't been an issue. I can do it with an allocation (below) using the built-in syntax, but not sure how do-able it is without an allocation (Ilya would know better than me). /+dub.sdl: dependency "lubeck" version="~>1.1.7" dependency "mir-algorithm" version="~>3.7.28" +/ import mir.ndslice; import lubeck; void main() { auto a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed.slice; }
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 19:13:14 UTC, p.shkadzko wrote: On Sunday, 19 April 2020 at 18:59:00 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 17:55:06 UTC, p.shkadzko wrote: snip So, lubeck mtimes is equivalent to NumPy "a.dot(a.transpose())". There are elementwise operation on two matrices of the same size and then there is matrix multiplication. Two different things. You had initially said using an mxn matrix to do the calculation. Elementwise multiplication only works for matrices of the same size, which is only true in your transpose case when they are square. The mtimes function is like dot or @ in python and does real matrix multiplication, which works for generic mxn matrices. If you want elementwise multiplication of a square matrix and it’s transpose in mir, then I believe you need to call assumeContiguous after transposed. "assumeContiguous" that's what I was looking for. Thanks! well no, "assumeContiguous" reverts the results of the "transposed" and it's "a * a". I would expect it to stay transposed as NumPy does "assert np.all(np.ascontiguous(a.T) == a.T)".
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 18:59:00 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 17:55:06 UTC, p.shkadzko wrote: snip So, lubeck mtimes is equivalent to NumPy "a.dot(a.transpose())". There are elementwise operation on two matrices of the same size and then there is matrix multiplication. Two different things. You had initially said using an mxn matrix to do the calculation. Elementwise multiplication only works for matrices of the same size, which is only true in your transpose case when they are square. The mtimes function is like dot or @ in python and does real matrix multiplication, which works for generic mxn matrices. If you want elementwise multiplication of a square matrix and it’s transpose in mir, then I believe you need to call assumeContiguous after transposed. "assumeContiguous" that's what I was looking for. Thanks!
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 17:55:06 UTC, p.shkadzko wrote: snip So, lubeck mtimes is equivalent to NumPy "a.dot(a.transpose())". There are elementwise operation on two matrices of the same size and then there is matrix multiplication. Two different things. You had initially said using an mxn matrix to do the calculation. Elementwise multiplication only works for matrices of the same size, which is only true in your transpose case when they are square. The mtimes function is like dot or @ in python and does real matrix multiplication, which works for generic mxn matrices. If you want elementwise multiplication of a square matrix and it’s transpose in mir, then I believe you need to call assumeContiguous after transposed.
How to use import std.algorithm.iteration.permutations?
Hi When I try to build the following: import std.algorithm.iteration; void test(int[] array); void main() { int[] a = [1,1,2,2,3,3]; foreach (p; a.permutations) { test(p); } } I get the error: .\permutations_example.d(10): Error: function permutations_example.test(int[] array) is not callable using argument types (Indexed!(int[], ulong[])) .\permutations_example.d(10):cannot pass argument p of type Indexed!(int[], ulong[]) to parameter int[] array What's the proper way to obtain the array of permutations of a? Kind regards David
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 17:22:12 UTC, jmh530 wrote: On Sunday, 19 April 2020 at 17:07:36 UTC, p.shkadzko wrote: I'd like to calculate XX^T where X is some [m x n] matrix. // create a 3 x 3 matrix Slice!(double*, 2LU) a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed; // error Looks like it is not possible due to "incompatible types for (a) * (transposed(a)): Slice!(double*, 2LU, cast(mir_slice_kind)2) and Slice!(double*, 2LU, cast(mir_slice_kind)0)" I'd like to understand why and how should this operation be performed in mir. Also, what does the last number "0" or "2" means in the type definition "Slice!(double*, 2LU, cast(mir_slice_kind)0)"? 2 is Contiguous, 0 is Universal, 1 is Canonical. To this day, I don’t have the greatest understanding of the difference. Try the mtimes function in lubeck. Ah, I see. There are docs on internal representations of Slices but nothing about the rationale. It would be nice to have them since it is pretty much the core of Slice. "a.mtimes(a.transposed);" works but the results are different from what NumPy gives. For example: a = np.array([[1, 2], [3, 4]]) a * a.transpose() # [[1, 6], [6, 16]] Slice!(int*, 2LU) a = [1, 2, 3, 4].sliced(2,2); writeln(a.mtimes(a.transposed)); // [[5, 11], [11, 25]] So, lubeck mtimes is equivalent to NumPy "a.dot(a.transpose())".
Re: Multiplying transposed matrices in mir
On Sunday, 19 April 2020 at 17:07:36 UTC, p.shkadzko wrote: I'd like to calculate XX^T where X is some [m x n] matrix. // create a 3 x 3 matrix Slice!(double*, 2LU) a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed; // error Looks like it is not possible due to "incompatible types for (a) * (transposed(a)): Slice!(double*, 2LU, cast(mir_slice_kind)2) and Slice!(double*, 2LU, cast(mir_slice_kind)0)" I'd like to understand why and how should this operation be performed in mir. Also, what does the last number "0" or "2" means in the type definition "Slice!(double*, 2LU, cast(mir_slice_kind)0)"? 2 is Contiguous, 0 is Universal, 1 is Canonical. To this day, I don’t have the greatest understanding of the difference. Try the mtimes function in lubeck.
Re: Wich: opIndex overloading by return type
On 4/19/20 11:53 AM, Robert M. Münch wrote: Wouldn't it make a lot of sense to allow different opIndex implementations based on return type? class myC { myT1 opIndex(int x) myT2 opIndex(int x) } Depending on the types involved myC[1] woudl return myT1 or myT2. Use-case: I have a geomentry object and in one case I get x0,y0,x1,y1 and in the other case x,y,w,h IMO that would make a lot of sense. D doesn't do overloading based on return type. You can do some things like return an item that alias this'd to one of the two, and then use an accessor for the other. Or you could provide indexers that operate with those types. e.g: myC.asT1[1] => T1 myC.asT2[1] => T2 -Steve
Multiplying transposed matrices in mir
I'd like to calculate XX^T where X is some [m x n] matrix. // create a 3 x 3 matrix Slice!(double*, 2LU) a = [2.1, 1.0, 3.2, 4.5, 2.4, 3.3, 1.5, 0, 2.1].sliced(3, 3); auto b = a * a.transposed; // error Looks like it is not possible due to "incompatible types for (a) * (transposed(a)): Slice!(double*, 2LU, cast(mir_slice_kind)2) and Slice!(double*, 2LU, cast(mir_slice_kind)0)" I'd like to understand why and how should this operation be performed in mir. Also, what does the last number "0" or "2" means in the type definition "Slice!(double*, 2LU, cast(mir_slice_kind)0)"?
How to make ddoc/ddox output alias name instead of template
Let's say I'm using TaggedAlgebraic [1] I have a specialized union: union _MTYPE { int val; string sval; } And now I want to use this type everywhere: alias MType = TaggedAlgebraic!_MTYPE; Everywhere in my docs where I have a nice function like: void foo(MType m) It spits out: void foo(TaggedAlgebraic!(full.package.name._MTYPE) m) I'd rather the documentation use MType everywhere. Is there a way to force this? I'm specifically looking for ddox to do this, but any information is helpful. -Steve [1] https://code.dlang.org/packages/taggedalgebraic
Why Pegged action dont not work in this case ?
I 've started experimenting Pegged action. Quickly i got blocked by this problem. The start action works where I use the rule but not directly in the rule. Test program: gdb_commander.d: --- /+dub.sdl: dependency "pegged" version="~>0.4.4" versions "dub_run" +/ module gdb_commander; import core.stdc.string, std.json; import pegged.grammar, pegged.peg; enum gdbMiOutput = `GdbmiOutput: Output < OutOfBandRecord* ResultRecord? '(gdb)' #HERE before ResRec OK ResultRecord< {beginResultRecord} Token? '^' ResultClass (',' Result)* {endResultRecord} OutOfBandRecord < AsyncRecord / StreamRecord AsyncRecord < ExecAsyncOutput / StatusAsyncOutput / NotifyAsyncOutput ExecAsyncOutput < Token? '*' AsyncOutput StatusAsyncOutput < Token? '+' AsyncOutput NotifyAsyncOutput < Token? '=' AsyncOutput AsyncOutput < AsyncClass ( ',' Result )* ResultClass < 'done' / 'running' / 'connected' / 'error' / 'exit' AsyncClass < 'stopped' Result < Variable '=' Value Variable< String Value < Const / Object / List Const < CString Object < '{}' / '{' Result ( ',' Result )* '}' List< '[]' / '[' Value ( ',' Value )* ']' / '[' Result ( ',' Result )* ']' StreamRecord< ConsoleStreamOutput / TargetStreamOutput / LogStreamOutput ConsoleStreamOutput < '~' CString TargetStreamOutput < '@' CString LogStreamOutput < '&' CString Token <~ [a-zA-Z_][a-zA-Z0-9_]* CString <~ "\"" (EscapedQuotes / (!"\"" .) )* :"\"" EscapedQuotes <~ backslash doublequote String <~ [a-zA-Z0-9_\-]*`; T beginResultRecord(T)(T t) { import std.stdio; writeln(__PRETTY_FUNCTION__); return t; } T endResultRecord(T)(T t) { import std.stdio; writeln(t); return t; } mixin(grammar(gdbMiOutput)); version(dub_run) { import std.stdio, std.path, std.file, std.process; import pegged.tohtml; enum testString01 = `^done,path="/usr/bin" (gdb)`; enum testString02 = `^done,threads=[ {id="2",target-id="Thread 0xb7e14b90 (LWP 21257)", frame={level="0",addr="0xe410",func="__kernel_vsyscall", args=[]},state="running"}, {id="1",target-id="Thread 0xb7e156b0 (LWP 21254)", frame={level="0",addr="0x0804891f",func="foo", args=[{name="i",value="10"}], file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"}, state="running"}], current-thread-id="1" (gdb)`; enum testString03 = `^done,new-thread-id="3", frame={level="0",func="vprintf", args=[{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""}, {name="arg",value="0x2"}],file="vprintf.c",line="31",arch="i386:x86_64"} (gdb)`; void exportHTMLandBrowse(T)(auto ref T tree, string name) { string fname = __FILE_FULL_PATH__.dirName ~ "/" ~ name ~ ".html"; if (fname.exists) remove(fname); toHTML(tree, fname); browse(fname); } void main() { GdbmiOutput(testString01).exportHTMLandBrowse("t1"); GdbmiOutput(testString02).exportHTMLandBrowse("t2"); GdbmiOutput(testString03).exportHTMLandBrowse("t3"); } } --- --- $ dub gdb_commander.d --- Also I'd like to report that actions dont work with partially specialized templates: --- T handleResultRecord(bool end, T)(T t); // then you use handleResultRecord!true and handleResultRecord!false in the PEG. ---
Re: Wich: opIndex overloading by return type
It is easy. You can make both types as children of common parent class myT, and when return myT.
Wich: opIndex overloading by return type
Wouldn't it make a lot of sense to allow different opIndex implementations based on return type? class myC { myT1 opIndex(int x) myT2 opIndex(int x) } Depending on the types involved myC[1] woudl return myT1 or myT2. Use-case: I have a geomentry object and in one case I get x0,y0,x1,y1 and in the other case x,y,w,h IMO that would make a lot of sense. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Re: Can a lib file converted to 1 ob file?
On Sunday, 19 April 2020 at 11:33:15 UTC, Andre Pany wrote: On Sunday, 19 April 2020 at 10:53:09 UTC, Basile B. wrote: On Sunday, 19 April 2020 at 10:48:04 UTC, Basile B. wrote: This should work if you pass the static library files to the linker. It is exactly its job to select what's used from the archive. So you would have to pass your stuff and optionally phobos2 as a static library (but this would also work if linking against phobos2.dll) BTW I have an example here [1], but it's for FreePascal and under linux, and in the end i've decided to use dynamic library (but with static linking) [2] [1] https://gitlab.com/basile.b/link-with-d [2] https://gitlab.com/basile.b/dexed/-/merge_requests/6 The only thing I found so far is, Delphi does not support linking .lib files. (Mac os 64 bit compiler though seems to support it). I understand from you, that FreePascal is able to link .lib files. Was my impression false and I can link .lib files with Delphi? No (sorry for the false hope) I also find this (‑‑linker-option for iOS only). Very surprising. Looks like you would have to use a dll. Note that with static linking of the dll cdecl; external 'mydll'; You don't have to use a loader.
Re: Can a lib file converted to 1 ob file?
On Sunday, 19 April 2020 at 10:53:09 UTC, Basile B. wrote: On Sunday, 19 April 2020 at 10:48:04 UTC, Basile B. wrote: This should work if you pass the static library files to the linker. It is exactly its job to select what's used from the archive. So you would have to pass your stuff and optionally phobos2 as a static library (but this would also work if linking against phobos2.dll) BTW I have an example here [1], but it's for FreePascal and under linux, and in the end i've decided to use dynamic library (but with static linking) [2] [1] https://gitlab.com/basile.b/link-with-d [2] https://gitlab.com/basile.b/dexed/-/merge_requests/6 The only thing I found so far is, Delphi does not support linking .lib files. (Mac os 64 bit compiler though seems to support it). I understand from you, that FreePascal is able to link .lib files. Was my impression false and I can link .lib files with Delphi? Kind regards Andre
Re: Can a lib file converted to 1 ob file?
On Sunday, 19 April 2020 at 10:48:04 UTC, Basile B. wrote: This should work if you pass the static library files to the linker. It is exactly its job to select what's used from the archive. So you would have to pass your stuff and optionally phobos2 as a static library (but this would also work if linking against phobos2.dll) BTW I have an example here [1], but it's for FreePascal and under linux, and in the end i've decided to use dynamic library (but with static linking) [2] [1] https://gitlab.com/basile.b/link-with-d [2] https://gitlab.com/basile.b/dexed/-/merge_requests/6
Re: Can a lib file converted to 1 ob file?
On Sunday, 19 April 2020 at 07:50:13 UTC, Andre Pany wrote: Hi, My understanding is, a lib file is a collection of multiple obj files. This is exact. From a delphi app I want to call D coding without using a dll. Delphi does not know the concept of lib files but can link obj files. Linking all single obj files of DRuntime, phobos and my library might be possible but I wonder whether there is a better way. Therefore the question, if I have a d lib file which contains all the obj files of DRuntime, phobos and my custom code, is it possible to convert it to exactly 1 obj file? Or must 1 obj file correspond to exactly 1 d module? Kind regards Andre This should work if you pass the static library files to the linker. It is exactly its job to select what's used from the archive. So you would have to pass your stuff and optionally phobos2 as a static library (but this would also work if linking against phobos2.dll)
Can a lib file converted to 1 ob file?
Hi, My understanding is, a lib file is a collection of multiple obj files. From a delphi app I want to call D coding without using a dll. Delphi does not know the concept of lib files but can link obj files. Linking all single obj files of DRuntime, phobos and my library might be possible but I wonder whether there is a better way. Therefore the question, if I have a d lib file which contains all the obj files of DRuntime, phobos and my custom code, is it possible to convert it to exactly 1 obj file? Or must 1 obj file correspond to exactly 1 d module? Kind regards Andre