# Tag Info

7

This is a type incompatibility problem. The compiler must make an assignment to the output of If in order to return a value. If[True, 1] is equivalent to If[True, 1, Null], and there is no type that can be assigned to both 1 and Null. You will get the same problem if you make an assignment to the If result when it isn't the final output of Compile: ...

9

The answer (if it can be called one) seems to be rooted in type-inferencing. The first observation you can make is that Break[] is considered a top-level function, rather than a statement, and is wrapped in a Function to be executed by main evaluator (in byte-code instructions): Function[{xs}, If[CompileFunctionVariable$38938 < 5., Break[], ++i]] This ... 1 With 1. the note about the behavior of ReplacePart inside Compile made by Daniel Lichtblau and Albert Retey in the comments above, 2. the correction for the simple mistake {a2, _Real} {a3, _Real}, 3. the note about All inside Compile here, 4. a modification for the uncompiled definition of qr i.e. changing qr = MapThread[Join[#1, {#2}, #3, {#4}] ... 4 OK, as an after-meal exercise, I fixed your code. The main modifications I've done are: 1. Based on trick mentioned in this post, change your pattern-matching function into pure function. 2. Change qsum = MapThread[Plus, #] &@Rq(for some unclear reason it can't be compiled, maybe it's because Rq isn't a "explicit" list? ) into qsum=Total@Rq. 3. ... 3 It looks like Compile doesn't handle 1;;All in Span, so why not just use explicit total number of rows? Compile[{{matrix, _Real, 2}, {lag, _Integer}}, Module[{rows, columns}, {rows, columns} = Dimensions[matrix]; Join[ {Table[1., {columns - lag + 1}]}, Flatten[ Table[ matrix[[1 ... 2 The reason about change only the argument of the external function, the behavior changes may be related to the setting of "ExpressionOptimization" under CompilationOptions. There is a related function called OptimizeExpression under Experimental context, which I believe, according to this post by Daniel Lichtblau, is the one used by Compile for expression ... 6 You have 2 sources of inefficiency in your code. One is that you don't use the machine-precision for your dx (and therefore xls), and another one is that Band is not the fastest way to build a SparseArray object, and in the time-dependent case you have to build a new one for every time point. Here is the code which is on the same level of performance as ... 4 I won't use your specific set of equations, but will answer more generally. Suppose we have the following set of first order equations with forcing: $$\frac{d\vec{x}}{dt}=A(t,\vec{x}(t))\vec{x}(t)+f(t)$$ Suppose further that we have$A$and$f\$ already as Mathematica functions, for example, here is something random: d = 2; A[t_, x_] := {{-1, -1 ...

3

Not every function can be compiled by Compile, and those functions which are supported are often supported only partially, for numerical arguments only. Gather cannot be compiled. The reason for this is that Gather will usually return a ragged array and compiled functions can only work with full (i.e. rectangular), homogeneous numerical arrays.

Top 50 recent answers are included