Questions tagged [data-types]
Mathematica pseudo-types Integer, Real, Rational, Complex, String and Symbol, and their use.
50
questions
2
votes
0
answers
28
views
When should I use Audio vs Sound Data types?
It seems like mathematica has 2 related data types Audio and sound.
Why is there 2 separate data types? When would I use one versus the other?
Guesses
I know I can convert between them by ...
1
vote
0
answers
48
views
FunctionCompile Type Errors
This function works uncompiled:
Function[{n, m, k},
ParallelSum[
Length[Permutations[i]],
{i, IntegerPartitions[m, {n}, Range[0, k]]}
]]
but compiling with <...
3
votes
1
answer
44
views
Type formation rules for 1-position expressions
I made a summary of the rules for formation of types for simple 1-position expressions, as I understand them.
Here it is in textual form:
A symbol, say, α, is a discrete entity, represented by a ...
9
votes
1
answer
242
views
Using DataStructures in FunctionCompile
This is a follow up to this StackExchange question
I am trying to do the equivalent of Select on a "FixedArray" data structure.
Here is what I have tried so far:
...
1
vote
0
answers
50
views
"Compile-time" patterns
If I define a function like
f[x : {_, _Integer}] := (* function body *)
then, as I understand it, every time f[expr] is ...
2
votes
0
answers
91
views
How to use _Complex types in CUDAFunctionLoad?
The documentation for CUDAFunctionLoad specifies various base datatypes you can use for your function's arguments, including ...
1
vote
1
answer
168
views
Adding a curve on DensityPlot: Epilog -> First[ContourPlot[...]] why the first?
I would like to understand why I have to add First around ContourPlot in the following example to have it working:
...
2
votes
0
answers
43
views
How to use TypeFramework?
I found a paclet "TypeFramework". It seems to be designed for typed programming. How can I use it?
3
votes
1
answer
380
views
How to use patterns to specify variable type as Boolean (True, False) in analogy to x_Integer, x_Real, x_Complex, x_List, etc
Say I define a function f[x_, y_]:= ..., the concrete definition of which is not important now.
What is important though is, that I want ...
1
vote
0
answers
150
views
How to restrict the type of input given to the function Input[]?
The function Input[] when evaluated displays a dialog box where one can enter any character. My question is how do I restrict the input only to a certain type such ...
6
votes
1
answer
395
views
Provide definition to FunctionCompile
I recently upgraded to Mathematica 12, and I've been excited to explore new features such as FunctionCompile, which produces llvm code.
I tried compiling the ...
1
vote
0
answers
46
views
SemanticImport changes "string" type to "quantity" type--how to change during import or after import?
This question may overlap with other questions about the quirks of SemanticImport, but I don't see this specific wrinkle on StackExchange and I hope it will be a simple answer to help me and others ...
8
votes
1
answer
175
views
What is an example of of idiomatic "typed" WolframScript?
I'd like to make my own "typed function" in WolframScript. Suppose the type we desire is called money, and we'd like to make a function called ...
10
votes
2
answers
620
views
Make symbols atomic, without losing their type
So, I'd like to define a matrix M, that does not decompose into it's constituents when I do things like Tr[M], but I also want it's type to be retained.
(By type, ...
0
votes
0
answers
243
views
CompiledFunction::ctfa - Argument should be a rank 4 tensor of machine-size real number
Dear Mathematica community,
I got the following error line:
CompiledFunction::ctfa "Argument {<<1>>} at position 1 should be a rank 4 tensor of machine-size real number"
This ...
0
votes
1
answer
51
views
Who knows what happened in this code? (The difference between 3 and 3.)
I have a problem in my code. This code produces two different results when we use GM = {{Sqrt[3.], 0}, {-Sqrt[3], 3}/2} and GM = {{Sqrt[3], 0}, {-Sqrt[3], 3}/2}, where I just use Sqrt[3] instead of ...
20
votes
1
answer
474
views
NumericArray versus PackedArray in MMA12
I just tried to understand the differences between NumericArray and PackedArray in MMA12. The memory footprint of a ...
10
votes
1
answer
287
views
Is it possible to restrict the arguments for a function to a specific entity type?
I'm trying to wrap my head around how to work with Mathematica for building (computable) domain specific knowledge. One particular thing I didn't quite understand is how to create symbols for ...
24
votes
2
answers
2k
views
Why no RationalQ or RealQ?
Interesting pattern came up as I go through the homework replies of my students. Why is there no RationalQ or RealQ? We have <...
2
votes
1
answer
64
views
Data Type that can contain multiple data types
In MATLAB one can use cell arrays and structures to "hold" data of different types. For example, one can define a cell array in which the first cell contains an array, the second a differently sized ...
13
votes
1
answer
261
views
Is it possible to set multiple type to a variable?
Consider this
f[x_Real] := 2 x
f[1]
f[1]
f[1.0]
2.0
I want ...
1
vote
2
answers
126
views
How to create an unevaluated command like Sequence
I work with linear combinations of graphs,
$$c_1 G_1 + c_2 G_2 + \dotsc,$$
and I want to represent them in my Mathematica code. I represent graphs as adjacency matrices, e.g.
...
3
votes
1
answer
189
views
How to define "typed" objects and their operator specializations?
I've defined a primitive sort of type system where my objects are defined as lists with an associated identifier:
...
1
vote
0
answers
43
views
Integer data type mapping problem with SQLInsert in DatabaseLink package
I am working with a following SQL table named "ticket". Now let's see the data types for the columns.
...
4
votes
1
answer
234
views
Specify Variable Size
Is there an easy way to specify the variable size and still use them as variables more specifically for the .NETLink?
Something like the following I am thinking.
...
1
vote
1
answer
131
views
Control data type (or precison?) to limit memory usage
I couldn't find the answer to my question, so here it is:
I have quite a large table, which I generate in Matlab (for some reasons i use both Matlab and Mathematica, I'd like to use only one of them, ...
9
votes
2
answers
17k
views
How to get the type of an object
I'm looking for a way to get the type of an object:
TypeOf["x"] -> String
TypeOf[1] -> Integer
Or something along those lines.
5
votes
1
answer
413
views
Immutability, Association and typing
I have read the article by Leonid on the question. I am still struggling.
I am trying to use Association to inject some pseudo-typing in my code.
Here is my ...
1
vote
0
answers
175
views
Compilation error: "Could not complete external evaluation at..."
I'm pretty new to trying to use Compile[], and I just can't see why I'm getting this error.
I have two functions to define beforehand; one of them is a bit odd:
<...
18
votes
0
answers
280
views
V10's TypeSystem - what are these function useful for? [closed]
The symbols in the TypeSystem` context are clearly used for working with Datasets, but they seem powerful. I was hoping that someone could help explain how they work and is they are useful for ...
1
vote
0
answers
64
views
Pattern type and list indexing warnings/errors
I'm new to Mathematica and am trying to implement some simple noise functions in it in hopes of eventually finding an integral for them. This is the interesting part of the code:
...
4
votes
2
answers
77
views
Type error before replacement rule is applied
When I type
a <> "0" /. {a -> "1"}
I get the error
...
15
votes
1
answer
5k
views
How to convert a column of a Dataset into a list [closed]
I'm loving the fact that Mathematica has finally implemented the Dataset feature, but I'm still struggling a little with it. I have a Dataset that contains a bunch of functions for different diseases ...
3
votes
1
answer
266
views
Datatypes and numbers in Mathematica
I have some questions about numbers in Mathematica:
Does Mathematica work with datatypes like int, long, ...
4
votes
1
answer
51
views
Relative factorisation with scalar quantities
I'd like to find a natural way to tell mathematica that a given unknown in a polynomial should be treated as a number, unlike the other variables.
Typically I'd like to sum two polynomials in several ...
2
votes
1
answer
95
views
Type declaration for list arguments
How can I make
f[n_Integer]=2*n
valid for a list of integers? For example:
f[nlist_Integer] := 2*nlist[[1]]
does not work ...
1
vote
0
answers
79
views
How can I perfect this game for Wolfram Demonstration publication? [closed]
When the messages change the window inactivates, and when I try to host an interactive CDF on my site it turns red and says something about numbers having to be scaled or offset. Any help?
I'm ...
2
votes
1
answer
565
views
Declare type in InputField
Is it possible to declare a type in InputFunction to only accept positive Integers as input?
I know i can create an ...
12
votes
1
answer
13k
views
Get expression type?
Is there a built in function that distinguishes between different kinds of variables?
I mean something like:
VariableType[ 123 ]
Number
...
5
votes
1
answer
154
views
Determine return type of CompiledFunction expression
Is there a way to extract the types of the arguments and the return type from a CompiledFunction expression? I am writing a package for code generation (basically a wrapper around CCodeGenerate) where ...
12
votes
3
answers
382
views
Find all heads a function is defined on
So say I've got a function g defined as follows:
g[x_Integer] := x + 1
g[s_String] := s <> "!!!"
How would I write a ...
4
votes
1
answer
268
views
Using less memory to store and manipulate specific types
Is there a simple way to use Integer types (in particular, a table of Integer types) that require only 4 or 8 bytes (reps. 32 and 64 bits) representation?
It seems that integers in Mathematica have a ...
6
votes
2
answers
196
views
Behavior of 1.2 ∈ Rationals changes in v9?
A friend of mine using version 9 recently showed me this:
It's strange because in version 8.0.4 1.2 ∈ Rationals does return ...
3
votes
1
answer
132
views
.NET link - index of property
I have a property in .NET Type, which is actually a generic list of objects. When I try access the property using numeric index e.g. 10, this works. However when I iterate through indices using ...
1
vote
1
answer
864
views
Mathematica command for type checking?
I have a program where users can enter mathematica commands that can evaluate to any of the standard numeric types (complex, real, int, etc.), or to boolean values. Moreover the users can enter ...
29
votes
6
answers
13k
views
How to check if an expression is a real-valued number
What is a simple, fast way to test whether an expression is a real-valued number? I ask since there is no RealQ function.
If we call this test ...
2
votes
3
answers
833
views
What format to use to store expressions in database?
I am storing lists of expressions into a MySQL database. Each list is of form
{_String, {_String, _Real}, _Real}
What data format should each column of the ...
39
votes
4
answers
4k
views
How to create strong types?
In a program I'm writing, I create a list of lists, that looks something like this:
{{100, {1,2,3,4,5}},
{105, {2,4,6,8}},
{42, {42,39,56}}}
I then pass this ...
120
votes
7
answers
16k
views
Struct equivalent in Mathematica?
I really miss having something like a struct in Mathematica. I know of (and regularly use) a couple of programming techniques which feel like a ...
7
votes
3
answers
357
views
Does there exist any way to add type annotations?
Is there any way to add my own annotations to values or functions in Mathematica? Imagine, for example, that I wanted to annotate a List specifically as a ...