That's because the typeof(Float32) == DataType, so isa(Float32,DataType) ==
true.

On Tue, Feb 17, 2015 at 11:48 AM, J Luis <jmfl...@gmail.com> wrote:

>
>
> In this particular use case, you can use isa(eltype(x), Float32), which
>> will work for both scalars and arrays.
>>
>
> Checked it now and it would be good but actually it oddly does not work
>
> julia> eltype([1.0f0])
> Float32
>
> julia> isa(eltype([1.0f0]), Float32)
> false
>
> (I'' use Patrick's solution, but just to let you know)
>
>
>
>>
>> Thanks,
>>
>> Jiahao Chen
>> Staff Research Scientist
>> MIT Computer Science and Artificial Intelligence Laboratory
>>
>> On Tue, Feb 17, 2015 at 9:40 AM, Abel Siqueira <nepp...@gmail.com> wrote:
>>
>>>  What Tim was trying to point out is that `isa` a builtin, and many
>>> things
>>> depend on it being able to differentiate a scalar from an array.
>>>
>>> However, if you, in your code, wants to ignore this, you can define
>>> a function that does what you want, and it won't break anything because
>>> only your code depends on it.
>>>
>>> Regards,
>>> Abel
>>>
>>>
>>> On 02/17/2015 02:33 PM, J Luis wrote:
>>>
>>>
>>> You'd break the julia type system by doing so.
>>>>
>>>> You can define jluis_isa() to do whatever you want, however.
>>>>
>>>
>>> Hmm, well I guess I could but according to your first statement I would
>>> be braking the julia type sysyem :)
>>>
>>>
>>>>
>>>> --Tim
>>>>
>>>> On Tuesday, February 17, 2015 08:16:03 AM J Luis wrote:
>>>> > Yes, I know that but couldn't isa be made to return also 'true' in my
>>>> > second example?
>>>> >
>>>> > terça-feira, 17 de Fevereiro de 2015 às 16:07:03 UTC, Tim Holy
>>>> escreveu:
>>>> > > This has nothing to do with isa. In julia, a scalar is different
>>>> from a 1-
>>>> > > element array. Matlab doesn't make that distinction, because in
>>>> Matlab
>>>> > > _everything_ is an array. Which is much of why Matlab is slow for
>>>> many
>>>> > > things.
>>>> > >
>>>> > > --Tim
>>>> > >
>>>> > > On Tuesday, February 17, 2015 08:03:12 AM J Luis wrote:
>>>> > > > julia> isa(1.0f0, Float32)
>>>> > > > true
>>>> > > >
>>>> > > > julia> isa([1.0f0], Float32)
>>>> > > > false
>>>> > > >
>>>> > > > julia> isa([1.0f0], Array{Float32})
>>>> > > > true
>>>> > > >
>>>> > > > It means that to know the data type one must first test if the
>>>> variable
>>>> > >
>>>> > > is
>>>> > >
>>>> > > > scalar or array. Not nice. I find the Matlab equivalent much
>>>> easier to
>>>> > >
>>>> > > use.
>>>>
>>>>
>>>
>>

Reply via email to