Why isn't this a machine sized integer

  • Thread starter Thread starter ramsey2879
  • Start date Start date
  • Tags Tags
    Integer Machine
Click For Summary

Discussion Overview

The discussion revolves around a coding issue in Mathematica related to the handling of integers imported from a CSV file. Participants explore the nature of machine-sized integers and the errors encountered when compiling a function that processes these integers.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant shares a code snippet and describes an error message indicating that certain integers should be machine-sized integers.
  • Several participants inquire about the programming language, operating system, and context of the code, noting that machine-sized integers can vary by language and system.
  • Another participant clarifies that the code is for Mathematica and suggests that the presence of curly braces around integers may be causing the issue.
  • Concerns are raised about potential formatting issues when copying code into the forum, with one participant suggesting that an extra space in the code could be problematic.
  • Another participant emphasizes the importance of ensuring all integers are less than 32 bits and suggests creating a shorter list to isolate the error.
  • One participant expresses skepticism about the claim that all numbers are less than 32 bits and questions whether the syntax might be interpreted as text rather than numbers.
  • A suggestion is made to use the Flatten function to ensure the imported list is in the correct format for processing.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the error, with multiple competing views on whether the issue lies in the data format, the syntax, or the handling of machine-sized integers.

Contextual Notes

There are indications that the imported data may not be in the expected format, as it appears as a list of lists rather than a flat list of integers. Additionally, the handling of machine-sized integers is noted to depend on the programming environment.

ramsey2879
Messages
841
Reaction score
3
In:list5 = Import["Composites.csv"]; (*imports a list of odd integers each less than 1000000*)
Timing[f=Compile[{{Caa,_Integer},{S0,_Integer},{S1,_Integer},{Co,_Integer}},
Module[{xCo=Co,xS0=S0,xS1=S1,Temp},While[Temp=Mod[6 xS1-xS0-6,Caa];xCo>0&&Temp>=1,
xS0=xS1;xS1=Temp;xCo--];
xCo]];
count = Length[list5];
list3=Reap[While[count>0,
Caa= list5[[count]];Sow[Caa];Co=Round[(Caa-2)/2];S0=2;S1=3;
So = f[Caa,S0,S1,Co]; Sow[So];
count--]]]
results in red msg:
{3827} in position 1 should be a machine size Integer,
{13067} in position 1 should be a machine size Integer, etc
These are integers from the imported list. I am at loss as how to correct this error. Please help.
PS when I switched the positions of Caa and Co in the compiled function, I get in red {1913} in position 1 should be a machine sized integer, etc.
 
Physics news on Phys.org
Is this for a course?

What language is this, what machine and what OS?

machine sized ints vary with cpu and language usage.

For C/C++ a machine sized int +-32768 or 16-bit integer

For Java an int is a 32-bit value.

Also check your csv file to see if any numbers are greater than the 1000000 mentioned in the comment. Thats if this program had worked before but now does not.
 
jedishrfu said:
Is this for a course?

What language is this, what machine and what OS?

machine sized ints vary with cpu and language usage.

For C/C++ a machine sized int +-32768 or 16-bit integer
For the past dozen years or so, most C or C++ compilers consider an int to be 32 bits.
jedishrfu said:
For Java an int is a 32-bit value.

Also check your csv file to see if any numbers are greater than the 1000000 mentioned in the comment. Thats if this program had worked before but now does not.
 
Opps. Sorry but this is code for Mathematica. I should have made that clear in the title
PS I understand that integers less than 2^31 may qualify as machine readable. I think the {} may be making the number not be an "integer" but if that is the problem, how do I get rid of them, i.e. let the element be the number per se and not --{3427}--.
 
noticed an extra space in your code is that an artifact of display on this forum or is it really there.

,{S1,_Integer},{Co,_I nteger}},
__________________^_________
maybe this space is causing the trouble
 
jedishrfu said:
noticed an extra space in your code is that an artifact of display on this forum or is it really there.

,{S1,_Integer},{Co,_I nteger}},
__________________^_________
maybe this space is causing the trouble

Thanks, that seems to be a problem with cut and paste from Mathematica into this forum. It is not a space appearing in my code, so that is not the problem. Interesting that when Bill Simpson provided the same code in my earlier thread (Sow within While Loop(mathematica)), that a space was apparently added also. I used the compiled function f with numbers bigger than in my list so size of the numbers is not the problem. It has to be something with the adding of Import and Part of list functions to the code.
 
Remember that long list of warnings and cautions I gave you about Compile[] and one of those was that all integers needed to be less than 32 bits. It looks like you either have a small syntax problem or you have stepped over that limit.

By trial and error see if you can create a MUCH shorter list Composites.csv that still demonstrates this error, post that here and I'll see if I can figure out what you have done. I don't want to have to dig through thousands of numbers to discover where your problem is. But as I also said, when you ran into troubles with a Compile I might easily not be the person to figure it out for you.

And yes, that annoying space and other formatting problems show up in text pasted onto the forum. I mentioned that before. That isn't the problem, just as long as you remember to watch for and fix that. I think that inserting a few spaces after commas or operators sometimes makes the problem hide.
 
Bill Simpson said:
Remember that long list of warnings and cautions I gave you about Compile[] and one of those was that all integers needed to be less than 32 bits. It looks like you either have a small syntax problem or you have stepped over that limit.

By trial and error see if you can create a MUCH shorter list Composites.csv that still demonstrates this error, post that here and I'll see if I can figure out what you have done. I don't want to have to dig through thousands of numbers to discover where your problem is. But as I also said, when you ran into troubles with a Compile I might easily not be the person to figure it out for you.

And yes, that annoying space and other formatting problems show up in text pasted onto the forum. I mentioned that before. That isn't the problem, just as long as you remember to watch for and fix that. I think that inserting a few spaces after commas or operators sometimes makes the problem hide.
Trust me, the numbers are all odd numbers less than 32 bits. Could it be that the syntax is "text" instead of a "number"? What I posted is the complete mathematical code that returns this error message. To check if Mathematical was reading the elements as numbers, I tried 2 list5[[25]] and got out: 6854 which was twice the last element, but I am not sure that mathematica always treats the elements as numeric and not just when coupled with multiplication. As for a short list to import, try to import 43,51,59,67,75 and see what output you get.
 
Last edited:
ramsey2879 said:
Trust me, the numbers are all odd numbers less than 32 bits.

After decades and decades of experience I don't trust me, let alone anyone else or software.

ramsey2879 said:
Could it be that the syntax is "text" instead of a "number"? What I posted is the complete mathematical code that returns this error message. To check if Mathematical was reading the elements as numbers, I tried 2 list5[[25]] and got out: 6854 which was twice the last element, but I am not sure that mathematica always treats the elements as numeric and not just when coupled with multiplication. As for a short list to import, try to import 43,51,59,67,75 and see what output you get.

Using Excel 5 I created a column of 43,51,59,67,75 as you directed and saved it as Composites.csv. When I ran your code I got:

CompiledFunction:: cfsa: Argument {75} at position 1 should be a machine-size integer.

and got that for each integer. That looks EXACTLY like the error message you are reporting.

I then inserted

Print[FullForm[list5]];

immediately after your list5=Import[...] and discovered that a column of integers comes in as a list of lists when you are expecting list5 to be just a list so I am guessing that your input from Excel is not in the form that you are trusting it to be.

Try inserting

list5 = Flatten[list5];

after your list5=Import[...] and see if you get a better result.
 
  • #10
Spaces are inserted every 50 characters into strings without white spaces by the forum software.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
6K