I'm trying to do something which is maybe a little weird, but with Julia
being homoiconic it should be more feasible here than in other languages. I
want a type that holds symbolic placeholders for unevaluated variables, but
with mathematical operators defined to build up an expression tree around
those unevaluated variables. I found an example of this in the Sims.jl
package, it has an Unknown() type that does exactly what I want in the
simple scalar case. If anyone can point me towards other implementations of
similar functionality floating around out there, that would be cool too.
The trouble comes when I start trying to use these Unknown() objects as the
nonzero elements in a sparse matrix. Here's my first crack at that:
julia> using Sims
... some warnings
julia> A = sparse(1:2, 1:2, [Unknown() for i=1:2])
ERROR: no method convert(Type{Unknown{DefaultUnknown}}, Int64) in sparse at
sparse/csparse.jl:30
Okay, zero(Tv) doesn't work for the Unknown type (I have a feeling the
backtrace should be longer?). How about
julia> A = sparse(1:2, 1:2, Any[Unknown() for i=1:2])
ERROR: type: non-boolean (MExpr) used in boolean context in sparse at
sparse/csparse.jl:30
Same line, different problem. The != operator produces unevaluated
expression objects instead of boolean, not too surprising. I can overwrite
that for my purposes.
julia> !=(::Unknown, ::Number) = true
julia> A = sparse(1:2, 1:2, Any[Unknown() for i=1:2])
2x2 sparse matrix with 2 Any entries:
[1, 1] = <<`549`,0.0>>
[2, 2] = <<`550`,0.0>>
Awesome. But will sparse matrix multiplication work with this thing?
julia> A * A
ERROR: access to undefined reference in unsafe_copy! at array.jl:41
Now I'm confused. This was on Windows from a recent binary installer,
Julia Version 0.3.0-prerelease+1570
Commit a6f6461* (2014-02-14 21:07 UTC)
Platform Info:
System: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
LAPACK: libopenblas
LIBM: libopenlibm
If I go over to a from-source Linux build,
Julia Version 0.3.0-prerelease+1622
Commit eeb2b00* (2014-02-18 07:07 UTC)
Platform Info:
System: Linux (x86_64-redhat-linux6E)
CPU: Intel(R) Xeon(R) CPU E5410 @ 2.33GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
LAPACK: libopenblas
LIBM: libopenlibm
then the backtrace for that last error is slightly different, it says "in *
at linalg/sparse.jl:171." So, something having to do with splice! then?
Anyone have any recommendations how to figure out what's going on?
Thanks,
Tony