Le samedi 26 décembre 2015 à 16:04 -0500, Stuart Brorson a écrit :
> Hi again --
>
> Another question. I want to create a sparse matrix whose non-zero
> elements are BigFloats. Neither of the two approaches I tried
> (below)
> seem to work.
>
> julia> Asp = spzeros(4,4)
> 4x4 sparse matrix with 0 Float64 entries:
>
> julia> Asp[1,1] = BigFloat(3.4)
> 3.3999999999999999111821580299874767661094665527343750000000000000000
> 00000000000
>
> julia> Asp
> 4x4 sparse matrix with 1 Float64 entries:
> [1, 1] = 3.4
>
> julia> Asp = BigFloat(spzeros(4,4))
> ERROR: MethodError: `convert` has no method matching
> convert(::Type{BigFloat}, ::SparseMatrixCSC{Float64,Int64})
> This may have arisen from a call to the constructor BigFloat(...),
> since type constructors fall back to convert methods.
> Closest candidates are:
> call{T}(::Type{T}, ::Any)
> convert{T<:Real}(::Type{T<:Real}, ::Complex{T<:Real})
> convert(::Type{BigFloat}, ::Rational{T<:Integer})
> ...
> in call at essentials.jl:56
>
>
> I tried fiddling around with using SparseMatrixCSC{Tv,Ti<:Integer} as
> a constructor, but no joy there since it probably is a type, and
> can't be used as a constructor.
>
> What's the easiest way to create a sparse matrix whose entries are
> not doubles?
One solution is
sparse(Int[], Int[], BigInt[], 4, 4)
We could imagine adding methods for spzeros() and spones() taking the
element type as the first argument. Indeed, such a method exists for
speye() already.
Regards
> Thanks,
>
> Stuart