Skip to content

Commit

Permalink
Merge pull request #268 from Nemocas/th/matspace
Browse files Browse the repository at this point in the history
Add nrows and ncols for matrix spaces
  • Loading branch information
wbhart authored Feb 12, 2019
2 parents 0071a3d + 40f0fe5 commit 84fbee2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/generic/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ end
#
###############################################################################

@doc Markdown.doc"""
nrows(a::Generic.MatrixSpace)
> Return the number of rows of the given matrix space.
"""
nrows(a::MatSpace) = a.nrows

@doc Markdown.doc"""
ncols(a::Generic.MatrixSpace)
> Return the number of columns of the given matrix space.
"""
ncols(a::MatSpace) = a.ncols

function Base.hash(a::AbstractAlgebra.MatElem, h::UInt)
b = 0x3e4ea81eb31d94f4%UInt
for i in 1:nrows(a)
Expand All @@ -151,7 +163,7 @@ end

@doc Markdown.doc"""
nrows(a::Generic.MatrixElem)
> Return the number of nrows of the given matrix.
> Return the number of rows of the given matrix.
"""
nrows(a::MatrixElem) = size(a.entries, 1)

Expand Down
3 changes: 3 additions & 0 deletions test/generic/Matrix-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ function test_gen_mat_constructors()
@test elem_type(S) == Generic.Mat{elem_type(R)}
@test elem_type(Generic.MatSpace{elem_type(R)}) == Generic.Mat{elem_type(R)}
@test parent_type(Generic.Mat{elem_type(R)}) == Generic.MatSpace{elem_type(R)}
@test base_ring(S) == R
@test nrows(S) == 3
@test ncols(S) == 3

@test typeof(S) <: Generic.MatSpace

Expand Down

0 comments on commit 84fbee2

Please sign in to comment.