Re: Using python in D

2019-06-08 Thread rnd via Digitalmars-d-learn

On Saturday, 8 June 2019 at 19:35:00 UTC, Russel Winder wrote:

PyD is hosted on GitHub so it is a question of putting in an 
issue there:


https://github.com/ariovistus/pyd/issues

The best bet is to write up what you have presented on email 
here, and then let the PyD developers guide you into providing 
the data they need to decide what the actual problem is and how 
it might be fixed.


Thanks for guidance.

I also wanted to know: Once executable is successfully created, 
will it work on systems where Python and pandas are not installed?




Re: Using python in D

2019-06-08 Thread rnd via Digitalmars-d-learn

On Saturday, 8 June 2019 at 09:11:48 UTC, Russel Winder wrote:
...
...
The problem seems to be that PyD is not looking in the right 
place for importing packages, but this is pure speculation.


Perhaps this merits a bug report against the PyD source 
repository?


Thanks for your time, effort and a detailed analysis of this 
problem.


I did not delete Python2.7 since I thought there could be some 
part of Debian/installed package that may depend on it. But I 
will try to do it now.


I am not well versed with the procedure of submitting bug report 
and will appreciate if you/some other expert on this forum does 
it.


best wishes,
rnd.


Re: Using python in D

2019-06-07 Thread rnd via Digitalmars-d-learn

On Friday, 7 June 2019 at 10:55:22 UTC, JN wrote:

On Friday, 7 June 2019 at 05:04:30 UTC, rnd wrote:

On Friday, 7 June 2019 at 04:39:14 UTC, rikki cattermole wrote:

On 07/06/2019 3:54 PM, rnd wrote:


How should I 'initialize python' ?


The example is probably a good place to begin.

https://github.com/ariovistus/pyd/blob/master/examples/simple_embedded/hello.d


Thanks for the link. After putting in missing statements, it 
started running but reported:


 exceptions.ImportError: No module named pandas

I believe pyd is working on Python2 while I have pandas 
installed in Python3.


How can I specify Python version 3 in pyd?


https://github.com/ariovistus/pyd

"To use with dub, either specify the relevant subConfiguration 
for your python version, or run source pyd_set_env_vars.sh 
 on linux or pyd_set_env_vars.bat  on 
windows to set the relevant environment variables and use the 
env subConfiguration."


I tried following in dub.selections.json file:

{
"fileVersion": 1,
"versions": {
"pyd": "0.10.5"
},
"subConfigurations": {
"pyd": "python35"
}
}

I also tried python3.5 and python3 in place of python35, but 
everytime python27 is being used (where pandas is not installed). 
The error is:


$ dub run
Performing "debug" build using /usr/bin/dmd for x86_64.
pyd 0.10.5: target for configuration "python27" is up to date.   
<<< NOTE VERSON HERE;

rntestpy ~master: building configuration "application"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running ./rntestpy
pyd.exception.PythonException@/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/pydobject.d(59):
exceptions.ImportError: No module named pandas

/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/exception.d:46 
void pyd.exception.handle_exception(immutable(char)[], ulong) [0x56438721e9e8]
/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/pydobject.d:59 
pyd.pydobject.PydObject 
pyd.pydobject.PydObject.__ctor(deimos.python.object.PyObject*) [0x56438721f2e8]
/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/embedded.d:54 
pyd.pydobject.PydObject pyd.embedded.py_import(immutable(char)[]) 
[0x56438721e501]
source/main.d:6 _Dmain [0x56438721ded0]
Program exited with code 1

I also tried command "dub run --force" but still the error 
persists.


I also tried to give command "source pyd_set_env_vars.sh 
/usr/bin/python3" but still it is not working.


Another command which I tried produced following output but still 
the problem persisted:


$ python3 pyd_get_env_set_text.py
export PYD_D_VERSION_1=Python_2_4_Or_Later
export PYD_D_VERSION_2=Python_2_5_Or_Later
export PYD_D_VERSION_3=Python_2_6_Or_Later
export PYD_D_VERSION_4=Python_2_7_Or_Later
export PYD_D_VERSION_5=Python_3_0_Or_Later
export PYD_D_VERSION_6=Python_3_1_Or_Later
export PYD_D_VERSION_7=Python_3_2_Or_Later
export PYD_D_VERSION_8=Python_3_3_Or_Later
export PYD_D_VERSION_9=Python_3_4_Or_Later
export PYD_D_VERSION_10=Python_3_5_Or_Later
export PYD_D_VERSION_11=__PYD__DUMMY__
export PYD_D_VERSION_12=__PYD__DUMMY__
export PYD_D_VERSION_13=__PYD__DUMMY__
export PYD_LIBPYTHON_DIR=/usr/lib
export PYD_LIBPYTHON=python3.5m

Where could be the problem and how can it be solved?



Re: Using python in D

2019-06-07 Thread Rnd via Digitalmars-d-learn

On Friday, 7 June 2019 at 10:55:22 UTC, JN wrote:

On Friday, 7 June 2019 at 05:04:30 UTC, rnd wrote:

On Friday, 7 June 2019 at 04:39:14 UTC, rikki cattermole wrote:

On 07/06/2019 3:54 PM, rnd wrote:


How can I specify Python version 3 in pyd?


https://github.com/ariovistus/pyd

"To use with dub, either specify the relevant subConfiguration 
for your python version, or run source pyd_set_env_vars.sh 
 on linux or pyd_set_env_vars.bat  on 
windows to set the relevant environment variables and use the 
env subConfiguration."


After executable is created, will it work on systems where Python 
and pandas are not installed?


Re: Using python in D

2019-06-06 Thread rnd via Digitalmars-d-learn

On Friday, 7 June 2019 at 04:39:14 UTC, rikki cattermole wrote:

On 07/06/2019 3:54 PM, rnd wrote:


How should I 'initialize python' ?


The example is probably a good place to begin.

https://github.com/ariovistus/pyd/blob/master/examples/simple_embedded/hello.d


Thanks for the link. After putting in missing statements, it 
started running but reported:


 exceptions.ImportError: No module named pandas

I believe pyd is working on Python2 while I have pandas installed 
in Python3.


How can I specify Python version 3 in pyd?



Re: Why any! with map! is not working here

2019-06-06 Thread rnd via Digitalmars-d-learn

On Thursday, 6 June 2019 at 21:32:11 UTC, Jonathan M Davis wrote:
If any is not given a predicate, it defaults to just checking 
whether the element itself is true (requiring that the element 
be bool), which is why Marco's suggestion works, but it's a 
rather odd way to write the code and will be less efficient 
unless the optimizer manages to optimize away the extra work 
involved with having map.


However, in general, with D, you're not going to find that 
there is only one way to do things. There are going to tend to 
be many different approaches to solve the same problem. D code 
is often simple because of the powerful language constructs and 
standard library, but it makes no attempt to make it so that 
there's only one way to do things - especially when you start 
combining stuff to do whatever it is you're trying to do.


- Jonathan M Davis


Maybe one of these methods can be made 'official' or 'idiomatic':


any!pred(ss);
ss.any!pred();
ss.any!pred;


This will reduce learning burden on beginners.



Re: Using python in D

2019-06-06 Thread rnd via Digitalmars-d-learn

Edit:

I tried above D program and got following error:

core.exception.AssertError@/home/abcde/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/embedded.d(53):
 python not initialized

??:? _d_assert_msg [0x5562d3f3c466]
/home/abcde/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/embedded.d:53 
pyd.pydobject.PydObject pyd.embedded.py_import(immutable(char)[]) 
[0x5562d3f0b2f1]
source/main.d:6 _Dmain [0x5562d3f0adeb]


How should I 'initialize python' ?


Using python in D

2019-06-06 Thread rnd via Digitalmars-d-learn
I have a simple python script file which contains following 3 
statements:


import pandas
df = pandas.read_csv('testfile.csv')
print(df[0:3])

Can I incorporate above in a D program?
I see there is pyd package for using python in D: 
https://code.dlang.org/packages/pyd

Will following program work:


import std.stdio;
import pyd.embedded;

void main(){
py_import("pandas");
py_stmts("df = pandas.read_csv('testfile.csv')"); 
py_stmts("print(df[0:3])");
}

Thanks for your insight.



Re: Why any! with map! is not working here

2019-06-06 Thread rnd via Digitalmars-d-learn

On Thursday, 6 June 2019 at 09:49:28 UTC, Jonathan M Davis wrote:


So, to start, the any portion should be something more like

any!pred(ss);

or

ss.any!pred();

or

ss.any!pred;

where pred is whatever the predicate is.


Apparently, following also works:


any(ss.map!(a => a > 127))   // as written by Marco de Wild
or
any(map!(a => a > 127)(ss))


Thanks for detailed explanations.
Philosophically, I personally think, there should be only one way 
to do such things since that will add to simplicity, as in C.
Apparently, smallness and simplicity of C contributed greatly to 
its success.
Only drawbacks of C, like its unsafe parts, should be removed and 
clearly advantages newer concepts should be added in a clearly 
defined manner.

Just thinking loudly!




Why any! with map! is not working here

2019-06-06 Thread rnd via Digitalmars-d-learn
I am trying to check if any character in the string is > 127 by 
following function:


import std.algorithm.searching;
import std.algorithm.iteration;
bool isBinary(char[] ss){
  return (any!(map!(a => a > 127)(ss)));
}

However, I am getting this error:

Error: variable ss cannot be read at compile time

I also tried:

bool isBinary(char[] ss){
return (any!(ss.map!(a => a > 127)));
}


But I get error:

Error: template identifier map is not a member of variable 
mysrcfile.isBinary.ss



How can this be corrected?





Not able to use this C++ library in D

2019-06-05 Thread rnd via Digitalmars-d-learn
I am trying to use C++ DCMTK library ( https://dcmtk.org/ ) 
functions in D.
A relevant reference page is 
https://support.dcmtk.org/docs/classDcmFileFormat.html#details



Following is C++ code modified from 
https://stackoverflow.com/questions/5052148/how-to-use-dcmtk-in-qt


#include "dcmtk/dcmdata/dctk.h"
#include 
using namespace std;

int main() {
   DcmFileFormat fileformat;
   OFCondition status = fileformat.loadFile("test.dcm");
   if (status.good())   {
cout << "File loaded" << endl;
   }else{
  cerr << "Error: cannot read DICOM file (" << status.text() 
<< ")" << endl;

   }
   return 0;
}


I have tried to do the same in D with following code:

import std.stdio;
extern (C++) void loadFile(FILE *infile);
extern (C++) class DcmFileFormat;
extern (C++) class OFCondition;

void main(){
   DcmFileFormat fileformat;
   OFCondition status = fileformat.loadFile("test.dcm");
   if (status.good())   {
writeln("File loaded");
   }else{
  writeln("Error: cannot read DICOM file (", status.text(), 
")");

   }
}

However, I am getting following errors:

$ dmd dcmtk_eg.d
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for loadFile
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for loadFile
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for opDot
dcmtk_eg.d(5): Error: class `dcmtk_eg.DcmFileFormat` is forward 
referenced when looking for opDispatch
dcmtk_eg.d(10): Error: function 
dcmtk_eg.loadFile(shared(_IO_FILE)* infile) is not callable using 
argument types (DcmFileFormat, string)
dcmtk_eg.d(10):cannot pass argument fileformat of type 
dcmtk_eg.DcmFileFormat to parameter shared(_IO_FILE)* infile
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for opDot
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for opDispatch
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for mod
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good
dcmtk_eg.d(6): Error: class `dcmtk_eg.OFCondition` is forward 
referenced when looking for good



Where is the problem and how can it be solved? Thanks for your 
help.





Re: Reading Dicom files in Dlang

2019-06-03 Thread Rnd via Digitalmars-d-learn

On Monday, 3 June 2019 at 15:56:00 UTC, Rémy Mouëza wrote:

On Monday, 3 June 2019 at 14:19:40 UTC, Rnd wrote:

[...]


We can call C functions directly from D. First, the functions 
must be declared in D, as D's syntax is different from C's.


[...]



Thanks for a very comprehensive answer.


Re: Reading Dicom files in Dlang

2019-06-03 Thread Rnd via Digitalmars-d-learn

On Friday, 31 May 2019 at 16:43:28 UTC, rnd wrote:

On Friday, 31 May 2019 at 13:49:02 UTC, KnightMare wrote:

  struct Range {
private __vector(ushort) _outer;
private size_t _a, _b;

this(vector(ushort) data, size_t a, size_t b) {   // 
 line 457

  _outer = data;
  _a = a;
  _b = b;
}


imo problem is in string
private __vector(ushort)_outer;
it looks like template(vector!ushort) or function or this is 
vector from core.simd

and replacing it to private long _outer; fix the problem
paste code imebra.d and imebra_im.d to someplace


Best to download it from https://imebra.com/get-it/ so that all 
files are available to you.


I am still waiting for someone to help me with this.

Can we directly call C functions from D without going through 
swig?




Re: What is difference between struct and class?

2019-06-03 Thread Rnd via Digitalmars-d-learn

On Monday, 3 June 2019 at 08:54:12 UTC, Jonathan M Davis wrote:
structs in D are basically the same as C++ classes that don't 
have inheritance and can be put on the stack or the heap, and 
classes in D are akin to C++ classes that use inheritance and 
are always put on the heap and used via pointers. D classes are 
similar to Java classes in that respect.


- Jonathan M Davis


Also struct in D seem to be very similar to classes in C except 
lack of inheritance.


These similarities and differences should be highlighted in 
documentation etc since many new users have at least some 
knowledge of C/C++ and understanding will be easier.


Re: What is difference between struct and class?

2019-06-03 Thread Rnd via Digitalmars-d-learn

On Monday, 3 June 2019 at 06:01:15 UTC, Jonathan M Davis wrote:
On Sunday, June 2, 2019 9:40:43 PM MDT Rnd via 
Digitalmars-d-learn wrote:

On Monday,

http://ddili.org/ders/d.en/index.html

If you want to know more about structs and classes 
specifically, then you can go straight to the sections on them, 
but you're going to understand a lot of things better if you 
just read through the book.


- Jonathan M Davis


I know 'new' is not needed to create instances of structs but can 
one use 'new'?


If yes, when should one use 'new'?



Re: What is difference between struct and class?

2019-06-02 Thread Rnd via Digitalmars-d-learn

On Monday, 3 June 2019 at 00:47:27 UTC, Adam D. Ruppe wrote:

On Monday, 3 June 2019 at 00:17:08 UTC, Rnd wrote:

What additional features do classes offer in D?


Classes support built-in runtime polymorphism through 
inheritance. structs don't.


As a result of this, classes are a little bit heavier 
resource-wise and are semantically always object references.


I am not clear if structs can have constructors (this) and 
whether they can be multiple? Also can data be made private and 
getters and setters used to access them?




What is difference between struct and class?

2019-06-02 Thread Rnd via Digitalmars-d-learn
I see that struct can have data as well as member functions and 
instances can be created. So they sound like classes only.


What additional features do classes offer in D?


Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Rnd via Digitalmars-d-learn

On Sunday, 2 June 2019 at 15:55:46 UTC, Paul Backus wrote:

On Sunday, 2 June 2019 at 15:48:54 UTC, Rnd wrote:
I have recently started using Dlang, hence this basic 
question. Thanks for your insight.


map and filter are templates in D, and !(...) is D's syntax for 
passing arguments to templates:


map!(x => x*x)([1, 2, 3, 4, 5])
 ^ ^
 | |
 | +- This array is a normal function argument
 |
 +- This lambda is a template argument


Is it not possible in the language to have template map function 
also to called as map(x=>... ?


This will reduce complexity which will attract more people to 
this language.


Easy languages have great mass appeal as has been shown with Ruby 
and Python.


What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Rnd via Digitalmars-d-learn
I have recently started using Dlang, hence this basic question. 
Thanks for your insight.


Re: Reading Dicom files in Dlang

2019-05-31 Thread rnd via Digitalmars-d-learn

On Friday, 31 May 2019 at 13:49:02 UTC, KnightMare wrote:

  struct Range {
private __vector(ushort) _outer;
private size_t _a, _b;

this(vector(ushort) data, size_t a, size_t b) {   // 
 line 457

  _outer = data;
  _a = a;
  _b = b;
}


imo problem is in string
private __vector(ushort)_outer;
it looks like template(vector!ushort) or function or this is 
vector from core.simd

and replacing it to private long _outer; fix the problem
paste code imebra.d and imebra_im.d to someplace


Best to download it from https://imebra.com/get-it/ so that all 
files are available to you.




Re: Reading Dicom files in Dlang

2019-05-31 Thread rnd via Digitalmars-d-learn

On Friday, 31 May 2019 at 11:20:15 UTC, KnightMare wrote:

whats wrong with answer at SO?
https://stackoverflow.com/questions/56278268/reading-dicom-files-in-dlang


dlang_wrapper.so file is created.

I try to access it with following file:

import imebra;
import imebra_im;

import core.stdc.stdio;
import core.stdc.stdlib;
import core.sys.posix.dlfcn;

extern (C) int ldl();

void main(){
//auto loadedDataSet = CodecFactory.load("33141578.dcm") ;
printf("+main()\n");

void* lh = dlopen("libdlang_wrapper.so", RTLD_LAZY);
if (!lh)   {
fprintf(stderr, "dlopen error: %s\n", dlerror());
exit(1);
}
printf("libdlang_wrapper.so is loaded\n");
}


But it gives following error:

$ rdmd rntestImebra.d
imebra.d(457): Error: function declaration without return type. 
(Note that constructors are always named this)

imebra.d(457): Error: found data when expecting )
imebra.d(457): Error: semicolon expected following function 
declaration

imebra.d(457): Error: declaration expected, not ,
imebra.d(459): Error: no identifier for declarator _a
imebra.d(459): Error: declaration expected, not =
imebra.d(460): Error: no identifier for declarator _b
imebra.d(460): Error: declaration expected, not =
imebra.d(464): Error: function declaration without return type. 
(Note that constructors are always named this)
imebra.d(731): Error: function declaration without return type. 
(Note that constructors are always named this)

imebra.d(731): Error: found other when expecting )
imebra.d(731): Error: semicolon expected following function 
declaration

imebra.d(731): Error: declaration expected, not )
imebra.d(733): Error: declaration expected, not if
imebra.d(734): Error: unrecognized declaration
imebra_im.d(51): Error: module `string` is in file 
'std/c/string.d' which cannot be read

import path[0] = .
import path[1] = /usr/include/dmd/phobos
import path[2] = /usr/include/dmd/druntime/import
Failed: ["/usr/bin/dmd", "-v", "-o-", "rntestImebra.d", "-I."]

Line 457 of part of this code:

  struct Range {
private __vector(ushort) _outer;
private size_t _a, _b;

this(vector(ushort) data, size_t a, size_t b) {   //  
line 457

  _outer = data;
  _a = a;
  _b = b;
}



Reading Dicom files in Dlang

2019-05-31 Thread rnd via Digitalmars-d-learn
Is it possible to read Dicom (https://en.wikipedia.org/wiki/DICOM 
) images (which are widely used in medical field) using D 
language?


Dicom specifications are given here: 
https://www.dicomstandard.org/current/


There is some discussion on this topic on this page but no 
details on this forum: 
https://forum.dlang.org/post/fsjefp$10sp$1...@digitalmars.com


I do not think there are any specific d library for this purpose 
but there are many C libraries available, e.g. :


https://dicom.offis.de/dcmtk.php.en

and

https://github.com/dgobbi/vtk-dicom

There is some discussion here on using C for reading Dicom files 
on [this forum][3].


Can one of these libraries be used to read Dicom images in D 
language?


PS: Sample Dicom images are available here: 
https://www.dicomlibrary.com/


Wrapper for Imebra has been suggested here 
(https://stackoverflow.com/questions/56278268/reading-dicom-files-in-dlang ) but it is not working.