Skip to content

Commit

Permalink
Add some methods for CxxMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Jun 21, 2024
1 parent 0a485cb commit f464977
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/array_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mutable struct CxxMatrix{T} <: AbstractMatrix{T}
x = new{T}(alloc_mat(T, n, m), n, m)
return finalizer(cxx_mat_finalizer, x)
end
function CxxMatrix{T}(Y::Matrix{T}) where {T<:Real}
function CxxMatrix{T}(Y::AbstractMatrix{T}) where {T<:Real}
check_type_mat(T)
n, m = size(Y)
X = new{T}(alloc_mat(T, n, m), n, m)
Expand All @@ -70,6 +70,10 @@ mutable struct CxxMatrix{T} <: AbstractMatrix{T}
end
end

Base.size(A::CxxMatrix)=(A.n, A.m)
Base.setindex!(A::CxxMatrix{T}, v, i,j) where T= setindex!(A.data,T(v),i,j)
Base.getindex(A::CxxMatrix,i,j) = getindex(A.data,i,j)

function check_type_mat(::Type{T}) where {T<:Real}
if !(T <: Union{Cdouble})
throw("Not implemented for type $T")
Expand Down

0 comments on commit f464977

Please sign in to comment.