Skip to main content
added 1198 characters in body
Source Link

The first part below is already answered, but I've got another question which I think is closely related to this one, so I edited my question.

First part: I started compiling in Mathematica a few weeks ago. In the code below, I want to put the integer value 0 into the list "Pre". If I "Print" the list, it will look like {0,0,....,0}. But the output of the code is {0.,0.,0.,....,0.}. So, my question is, how can I manage it, that the output looks like the "Print", i.e. I want the list to have integer values and not real numbers.

Thanks in advance!

In[1]:= CInit = Compile[{{v0, _Integer, 0}, {s0, _Integer, 0}},
          Module[{s = s0, v = v0, d, Pre},
          d = Table[$MaxMachineNumber, {v}];
          Pre = Table[0, {v}];
          Print[Pre];
          d[[s]] = 0.;
          {d, Pre}
          ], CompilationTarget -> "C"];
        CInit[5, 1]

 During evaluation of In[1]:= {0,0,0,0,0}

 Out[2]= {{0., 1.79769*10^308, 1.79769*10^308, 1.79769*10^308, 
         1.79769*10^308}, {0., 0., 0., 0., 0.}}

Second part:

If I have an empty list and I want to put Integers into it, how can I let Mathematica know that it is a list of Integers and not Reals? I tried to manage this with the third argument in Compile, but that didn't work. For example:

In[22]:= CTest = Compile[{{s, _Integer}}, Module[{Perm = {s}},
         Perm = {};
         Append[Perm, 1]
         ], {{Perm, _Integer, 1}}, CompilationTarget -> "C"]

Compile::cset: Variable Perm of type {_Integer,1} encountered in assignment of type >{_Real,1}. >>

Compile::cset: Variable Perm of type {_Integer,1} encountered in assignment of type >{_Real,1}. >>

I can avoid this error by doing this rather unnecessary thing below:

In[25]:= CTest = Compile[{{s, _Integer}}, Module[{Perm = {s}},
         Perm = Delete[Perm, 1];
         Append[Perm, 1]
         ], CompilationTarget -> "C"]

So, is there another way to tell Mathematica that Perm is a list of Integers without doing it like in the last example?

Thanks in advance!

I started compiling in Mathematica a few weeks ago. In the code below, I want to put the integer value 0 into the list "Pre". If I "Print" the list, it will look like {0,0,....,0}. But the output of the code is {0.,0.,0.,....,0.}. So, my question is, how can I manage it, that the output looks like the "Print", i.e. I want the list to have integer values and not real numbers.

Thanks in advance!

In[1]:= CInit = Compile[{{v0, _Integer, 0}, {s0, _Integer, 0}},
          Module[{s = s0, v = v0, d, Pre},
          d = Table[$MaxMachineNumber, {v}];
          Pre = Table[0, {v}];
          Print[Pre];
          d[[s]] = 0.;
          {d, Pre}
          ], CompilationTarget -> "C"];
        CInit[5, 1]

 During evaluation of In[1]:= {0,0,0,0,0}

 Out[2]= {{0., 1.79769*10^308, 1.79769*10^308, 1.79769*10^308, 
         1.79769*10^308}, {0., 0., 0., 0., 0.}}

The first part below is already answered, but I've got another question which I think is closely related to this one, so I edited my question.

First part: I started compiling in Mathematica a few weeks ago. In the code below, I want to put the integer value 0 into the list "Pre". If I "Print" the list, it will look like {0,0,....,0}. But the output of the code is {0.,0.,0.,....,0.}. So, my question is, how can I manage it, that the output looks like the "Print", i.e. I want the list to have integer values and not real numbers.

In[1]:= CInit = Compile[{{v0, _Integer, 0}, {s0, _Integer, 0}},
          Module[{s = s0, v = v0, d, Pre},
          d = Table[$MaxMachineNumber, {v}];
          Pre = Table[0, {v}];
          Print[Pre];
          d[[s]] = 0.;
          {d, Pre}
          ], CompilationTarget -> "C"];
        CInit[5, 1]

 During evaluation of In[1]:= {0,0,0,0,0}

 Out[2]= {{0., 1.79769*10^308, 1.79769*10^308, 1.79769*10^308, 
         1.79769*10^308}, {0., 0., 0., 0., 0.}}

Second part:

If I have an empty list and I want to put Integers into it, how can I let Mathematica know that it is a list of Integers and not Reals? I tried to manage this with the third argument in Compile, but that didn't work. For example:

In[22]:= CTest = Compile[{{s, _Integer}}, Module[{Perm = {s}},
         Perm = {};
         Append[Perm, 1]
         ], {{Perm, _Integer, 1}}, CompilationTarget -> "C"]

Compile::cset: Variable Perm of type {_Integer,1} encountered in assignment of type >{_Real,1}. >>

Compile::cset: Variable Perm of type {_Integer,1} encountered in assignment of type >{_Real,1}. >>

I can avoid this error by doing this rather unnecessary thing below:

In[25]:= CTest = Compile[{{s, _Integer}}, Module[{Perm = {s}},
         Perm = Delete[Perm, 1];
         Append[Perm, 1]
         ], CompilationTarget -> "C"]

So, is there another way to tell Mathematica that Perm is a list of Integers without doing it like in the last example?

Thanks in advance!

Tweeted twitter.com/#!/StackMma/status/319402711353266176
Source Link

Compile: Putting integers into a list

I started compiling in Mathematica a few weeks ago. In the code below, I want to put the integer value 0 into the list "Pre". If I "Print" the list, it will look like {0,0,....,0}. But the output of the code is {0.,0.,0.,....,0.}. So, my question is, how can I manage it, that the output looks like the "Print", i.e. I want the list to have integer values and not real numbers.

Thanks in advance!

In[1]:= CInit = Compile[{{v0, _Integer, 0}, {s0, _Integer, 0}},
          Module[{s = s0, v = v0, d, Pre},
          d = Table[$MaxMachineNumber, {v}];
          Pre = Table[0, {v}];
          Print[Pre];
          d[[s]] = 0.;
          {d, Pre}
          ], CompilationTarget -> "C"];
        CInit[5, 1]

 During evaluation of In[1]:= {0,0,0,0,0}

 Out[2]= {{0., 1.79769*10^308, 1.79769*10^308, 1.79769*10^308, 
         1.79769*10^308}, {0., 0., 0., 0., 0.}}