Re: Speeding up text file parser (BLAST tabular format)

2015-09-15 Thread Andrew Brown via Digitalmars-d-learn
I had some luck building a local copy of llvm in my home directory, using a linux version about as old as yours (llvm 3.5 i used) specifying: --configure --prefix=/home/andrew/llvm so make install would install it somewhere I had permissions. Then I changed the cmake command to: cmake -L -DL

Re: foreach(line; f.byLine) produces core.exception.InvalidMemoryOperationError@(0) in 2.067 but not 2.066

2015-09-15 Thread Andrew Brown via Digitalmars-d-learn
Thanks very much for your help, it seemed to work a treat (I hope :))! Compiling ldc wasn't too bad, make the changes to runtime/phobos/std/stdio.d and then just building as normal was no problem. Unittests are passing and it handles that file perfectly. On Tuesday, 15 September 2015 at 16:11

Re: foreach(line; f.byLine) produces core.exception.InvalidMemoryOperationError@(0) in 2.067 but not 2.066

2015-09-15 Thread Andrew Brown via Digitalmars-d-learn
On Tuesday, 15 September 2015 at 14:55:42 UTC, Martin Krejcirik wrote: For reference, it was this PR: https://github.com/D-Programming-Language/phobos/pull/3089 which fixed the same issue for me. A very naive question: would it be possible in this case to backport it into gdc/ldc by copying th

Re: foreach(line; f.byLine) produces core.exception.InvalidMemoryOperationError@(0) in 2.067 but not 2.066

2015-09-15 Thread Andrew Brown via Digitalmars-d-learn
On Tuesday, 15 September 2015 at 14:19:13 UTC, Daniel Kozák wrote: Which OS? It's CentOS release 6.5 (Final), I tried dmd 2.068.1 and the problem has disappeared. Thanks very much for the advice, I can stick to old gdc for speed until ldc catches up to 2.068. Best Andrew

Re: Reading and converting binary file 2 bits at a time

2015-08-31 Thread Andrew Brown via Digitalmars-d-learn
Thanks very much for all the help, your advice worked a treat. One final question, originally I was defining the struct inside the main loop and it was using 4 bytes per field rather than 2 bits, e.g.: import std.bitmanip; import std.stdio; struct Crumb1 { mixin(bitfields!(

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Andrew Brown via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:26:55 UTC, rumbu wrote: On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; v

Reading and converting binary file 2 bits at a time

2015-08-27 Thread Andrew Brown via Digitalmars-d-learn
Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read("binaryfile"); auto g = cast(bool[]) f; writeln(g); } but all the values of g then a

Re: GDC fails to link with GSL and fortran code

2015-03-17 Thread Andrew Brown via Digitalmars-d-learn
I'm getting some idea how difficult compilers could be to maintain across distros, but I'm probably still a long way from knowing the true horror. Thank you for taking the time to help me out, and then when my immediate problem was solved, more time to help me learn something. I see there'

Re: GDC fails to link with GSL and fortran code

2015-03-17 Thread Andrew Brown via Digitalmars-d-learn
Thank you very much for your replies, I now have 2 solutions to my problem! Both compiling on a virtual machine running debian wheezy, and using gcc to do the linking produced executables that would run on the cluster. Compiling with the verbose flags for linker and compiler produced the foll

GDC fails to link with GSL and fortran code

2015-03-16 Thread Andrew Brown via Digitalmars-d-learn
Hi, I'm trying to compile code which calls C and fortan routines from D on the linux cluster at work. I've managed to get it to work with all 3 compilers on my laptop, but LDC and GDC fail on the cluster (though DMD works perfectly). I'm using the precompiled compiler binaries on these system

Re: std.algorithm.sort error with default predicate

2014-07-07 Thread Andrew Brown via Digitalmars-d-learn
Is it chain you are after to concatenate the objects and sort them together? http://dlang.org/phobos/std_range.html#.chain You'd need to cast them all to the same type. On Monday, 7 July 2014 at 20:50:06 UTC, Archibald wrote: On Monday, 7 July 2014 at 20:17:16 UTC, bearophile wrote: Archibal

Re: Doing exercise from book, but I'm getting error with splitter

2014-06-16 Thread Andrew Brown via Digitalmars-d-learn
I'm giving up On Monday, 16 June 2014 at 16:49:46 UTC, Andrew Brown wrote: Sorry, comments split over two lines, this should work: import std.stdio, std.array, std.string; //need to import std.array void main() { ulong[string] dictionary; // the length property is ulong, not uint forea

Re: Doing exercise from book, but I'm getting error with splitter

2014-06-16 Thread Andrew Brown via Digitalmars-d-learn
Sorry, comments split over two lines, this should work: import std.stdio, std.array, std.string; //need to import std.array void main() { ulong[string] dictionary; // the length property is ulong, not uint foreach (line; stdin.byLine()) { foreach (word; splitter(strip(line))) {

Re: Doing exercise from book, but I'm getting error with splitter

2014-06-16 Thread Andrew Brown via Digitalmars-d-learn
I think you can find splitter in std.array. I had a few other problems compiling your code, I could get this version to work: import std.stdio, std.array, std.string; //need to import std.array void main() { ulong[string] dictionary; // the length property is ulong, not uint foreach (line;

Re: passing predicates to lowerBound, or alternatively, how lazy is map?

2014-06-11 Thread Andrew Brown via Digitalmars-d-learn
So I was hoping for a learning experience, and I got it. With a little playing around, looking at phobos, and TDPL, I think I've figured out how lowerBound gets its predicate. It learns it from assumeSorted. So I can do this: order.assumeSorted!((a, b) => number[a] < number[b]) .lowerBoun

Re: passing predicates to lowerBound, or alternatively, how lazy is map?

2014-06-11 Thread Andrew Brown via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 13:25:03 UTC, John Colvin wrote: On Wednesday, 11 June 2014 at 13:20:37 UTC, Andrew Brown wrote: You are correct. assumeSorted and lowerBound will provide better time complexity than countUntil I'm sorry, one final question because I think I'm close to understa

Re: passing predicates to lowerBound, or alternatively, how lazy is map?

2014-06-11 Thread Andrew Brown via Digitalmars-d-learn
You are correct. assumeSorted and lowerBound will provide better time complexity than countUntil I'm sorry, one final question because I think I'm close to understanding. Map produces a forward range (lazily) but not a random access range? Therefore, lowerBound will move along this range un

Re: passing predicates to lowerBound, or alternatively, how lazy is map?

2014-06-11 Thread Andrew Brown via Digitalmars-d-learn
map is fully lazy. However, if you've already got the sorted indices in `order`, I would do this: auto numLessThanN = numbers.indexed(order).countUntil!((x) => x >= N)(); That indexed command is perfect though, does the trick, thank you very much.

Re: passing predicates to lowerBound, or alternatively, how lazy is map?

2014-06-11 Thread Andrew Brown via Digitalmars-d-learn
My question about this is how lazy is map? Will it work on every value of order and then pass it to lowerBound, or could it work to evaluate only those values asked by lowerBound? I guess probably not, but could a function be composed that worked in this way? Thank you very much Andrew m

passing predicates to lowerBound, or alternatively, how lazy is map?

2014-06-11 Thread Andrew Brown via Digitalmars-d-learn
Hi there, The problem this question is about is now solved, by writing my own binary search algorithm, but I'd like to ask it anyway as I think I could learn a lot from the answers. The problem was, given an array of numbers, double[] numbers, and an ordering from makeIndex size_t[] order, I

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-06-02 Thread Andrew Brown via Digitalmars-d-learn
Having read more of the debate, I think coverage is more important than reproducibility. From my point of view, I'm not sure if there's much point in giving reproducible wrong answers.

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-06-01 Thread Andrew Brown via Digitalmars-d-learn
Thank you for hunting down the difference, in my case it's not a deal breaking problem. I can just specify the compiler and language version, then the results become reproducible. And I'm sure I'll appreciate the performance boost! On Sunday, 1 June 2014 at 12:11:22 UTC, Ivan Kazmenko wrote: O

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-05-31 Thread Andrew Brown via Digitalmars-d-learn
Looking at old data, it is the dmd version that's changed, so I think this is the likely reason. Andrew On Friday, 30 May 2014 at 20:45:23 UTC, monarch_dodra wrote: On Friday, 30 May 2014 at 18:41:55 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: On 30/05/14 18:13, monarch_dodra

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-05-30 Thread Andrew Brown via Digitalmars-d-learn
GDC version 4.8.2,i guess that's my problem. This is what happens when you let Ubuntu look after your packages. Thank you very much! Andrew On Friday, 30 May 2014 at 16:13:49 UTC, monarch_dodra wrote: On Friday, 30 May 2014 at 13:39:18 UTC, Andrew Brown wrote: Hi there, The following code:

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-05-30 Thread Andrew Brown via Digitalmars-d-learn
I'd like it to be predictable given the seed, right now it's predictable given the seed and the compiler. Is this a bug, shouldn't the random number process be completely defined in the language? I'm not trying to misuse it like the PHP crowd :) It's for a piece of scientific software: I'm ho

Different random shuffles generated when compiled with gdc than with dmd

2014-05-30 Thread Andrew Brown via Digitalmars-d-learn
Hi there, The following code: void main(){ import std.array : array; import std.stdio : writeln; import std.random : rndGen, randomShuffle; import std.range : iota; rndGen.seed(12); int[] temp = iota(10).array; randomShuffle(temp); writeln(temp); } writes [1, 8, 4, 2, 0

Re: Write double to text file, then read it back later without losing precision

2014-05-19 Thread Andrew Brown via Digitalmars-d-learn
I'm sure it will be, thank you very much. On Monday, 19 May 2014 at 15:57:53 UTC, bearophile wrote: Andrew Brown: I would like to write a double to a text file as hexadecimal and then read it back in without losing information. Is this good enough for you? void main() { import std.stdio

Write double to text file, then read it back later without losing precision

2014-05-19 Thread Andrew Brown via Digitalmars-d-learn
I would like to write a double to a text file as hexadecimal and then read it back in without losing information. Could someone tell me whether this is possible? It would happen in the same program, would I have to worry about different architectures? Thanks very much Andrew

Re: Seg fault when calling C code

2014-05-16 Thread Andrew Brown via Digitalmars-d-learn
I guess my confusion came about because in the page about interfacing with C, there's a static array example where parameters are given in terms D understands: extern (C) { void foo(ref int[3] a); // D prototype } I guess D has no problem translating that into a simple pointer that C can

Re: Seg fault when calling C code

2014-05-16 Thread Andrew Brown via Digitalmars-d-learn
On Friday, 16 May 2014 at 14:52:17 UTC, Marc Schütz wrote: On Friday, 16 May 2014 at 11:42:35 UTC, Kagamin wrote: For example, windows headers do use C++ &-references in function signatures and msdn provides code examples using that convention, the equivalent in D is ref. But that's extern(C+

Re: Seg fault when calling C code

2014-05-15 Thread Andrew Brown via Digitalmars-d-learn
That worked a treat! Thank you very much! On Thursday, 15 May 2014 at 21:11:54 UTC, Ali Çehreli wrote: On 05/15/2014 01:55 PM, Andrew Brown wrote: > extern(C) { >void regress(int nInd, int nCov, ref double[] x, ref double[] y, ref > double[] rOut); > } I don't think that should even be allo

Seg fault when calling C code

2014-05-15 Thread Andrew Brown via Digitalmars-d-learn
I'm trying to calculate residuals after fitting linear regression, and I've got some code in C using the gsl which should do it. Everything works fine if I use static arrays (below, defining X[15], y[5] etc.). Trouble is, I won't know the number of individuals or covariates until runtime, so I'