Skip to content

Behavior of ^(::Matrix{<:Integer}, ::Integer) inconsistent with behavior of ^(::Integer, ::Integer) #459

Description

@afniedermayer

^(::Matrix{Int64}, ::Int64) is type unstable. See e.g.

fibonacci_Q = [1 1;1 0]
@code_warntype fibonacci_Q^2

which shows Union{Array{Float64,2}, Array{Int64,2}}. The reason seems to be that ^(A::Matrix{Int64}, p::Int64) returns a Matrix{Float64} if p<0.

This is inconsistent with the behavior of ^(x::Int64, p::Int64), which returns an Int64 if p>=0 or if x==1 or x==-1. Otherwise, it throws a DomainError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions