Skip to content

Commit

Permalink
Asds
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Nov 2, 2024
1 parent 2cad42a commit 727faf5
Showing 1 changed file with 51 additions and 68 deletions.
119 changes: 51 additions & 68 deletions src/flint/fmpz_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1784,89 +1784,72 @@ end
addmul!(z::ZZMatrixOrPtr, a::ZZMatrixOrPtr, b::Integer) = addmul!(z, a, flintify(b))
addmul!(z::ZZMatrixOrPtr, a::IntegerUnionOrPtr, b::ZZMatrixOrPtr) = addmul!(z, b, a)

function mul!(z::Vector{ZZRingElem}, a::ZZMatrixOrPtr, b::Vector{ZZRingElem})
bb = Nemo.@new_struct(ZZMatrix)
be = zeros(Int, length(b))
zz = Nemo.@new_struct(ZZMatrix)
ze = zeros(Int, length(z))

GC.@preserve z b bb be zz ze begin
bb.entries = reinterpret(Ptr{ZZRingElem}, pointer(be))
bb.rows = reinterpret(Ptr{Ptr{ZZRingElem}}, pointer([pointer(be) + i for i in 0:length(b) - 1]))
bb.r = length(b)
bb.c = 1
@show b
for i in 1:length(be)
be[i] = b[i].d
end
@show bb

zz.entries = reinterpret(Ptr{ZZRingElem}, pointer(ze))
@show zz.entries
zz.rows = reinterpret(Ptr{Ptr{ZZRingElem}}, pointer([zz.entries + i for i in 0:length(z) - 1]))
zz.r = length(z)
zz.c = 1
@show zz

for i in 1:length(ze)
ze[i] = z[i].d
end
@show zz
mul!(zz, a, bb)
@show zz
for i in 1:length(ze)
z[i].d = ze[i]
end
return z
function _very_unsafe_convert(::Type{ZZMatrix}, a::Vector{ZZRingElem}, row = true)
# a must be GC.@preserved
# row = true -> make it a row
# row = false -> make it a column
M = Nemo.@new_struct(ZZMatrix)
Me = zeros(Int, length(a))
M.entries = reinterpret(Ptr{ZZRingElem}, pointer(Me))
if row
Mep = [pointer(Me)]
M.rows = reinterpret(Ptr{Ptr{ZZRingElem}}, pointer(Mep))
M.r = 1
M.c = length(a)
else
M.r = length(a)
M.c = 1
Mep = [pointer(Me) + 8*(i - 1) for i in 1:length(a)]
M.rows = reinterpret(Ptr{Ptr{ZZRingElem}}, pointer(Mep))
end
for i in 1:length(a)
Me[i] = a[i].d
end
#ccall((:fmpz_mat_mul_fmpz_vec_ptr, libflint), Nothing,
# (Ptr{Ref{ZZRingElem}}, Ref{ZZMatrix}, Ptr{Ref{ZZRingElem}}, Int),
# z, a, b, length(b))
#return z
return M, Me, Mep
end

function mul!(z::Vector{ZZRingElem}, a::Vector{ZZRingElem}, b::ZZMatrixOrPtr)
if true false
aa = Nemo.@new_struct(ZZMatrix)
ae = zeros(Int, length(a))
if length(z) != length(a)
zz = Nemo.@new_struct(ZZMatrix)
ze = zeros(Int, length(z))
else
zz = aa
ze = ae
end
GC.@preserve z a aa ae zz ze begin
for i in 1:length(ae)
ae[i] = a[i].d
end
aa.entries = reinterpret(Ptr{ZZRingElem}, pointer(ae))
aa.rows = reinterpret(Ptr{Ptr{ZZRingElem}}, pointer([aa.entries]))
aa.r = 1
aa.c = length(ae)
if length(z) != length(a)
zz.entries = reinterpret(Ptr{ZZRingElem}, pointer(ze))
zz.rows = reinterpret(Ptr{Ptr{ZZRingElem}}, pointer([zz.entries]))
zz.r = 1
zz.c = length(ze)
for i in 1:length(ze)
ze[i] = z[i].d
function mul!(z::Vector{ZZRingElem}, a::ZZMatrixOrPtr, b::Vector{ZZRingElem})
GC.@preserve z b begin
bb, dk1, dk2 = _very_unsafe_convert(ZZMatrix, b, false)
zz, dk3, dk4 = _very_unsafe_convert(ZZMatrix, z, false)
GC.@preserve dk1 dk2 dk3 dk4 begin
mul!(zz, a, bb)
for i in 1:length(z)
z[i].d = unsafe_load(zz.entries, i).d
end
end
mul!(zz, aa, b)
for i in 1:length(ze)
z[i].d = ze[i]
end
end
return z
end

function mul!_old(z::Vector{ZZRingElem}, a::ZZMatrixOrPtr, b::Vector{ZZRingElem})
ccall((:fmpz_mat_mul_fmpz_vec_ptr, libflint), Nothing,

Check warning on line 1826 in src/flint/fmpz_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz_mat.jl#L1825-L1826

Added lines #L1825 - L1826 were not covered by tests
(Ptr{Ref{ZZRingElem}}, Ref{ZZMatrix}, Ptr{Ref{ZZRingElem}}, Int),
z, a, b, length(b))
return z

Check warning on line 1829 in src/flint/fmpz_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz_mat.jl#L1829

Added line #L1829 was not covered by tests
end

function mul!_old(z::Vector{ZZRingElem}, a::Vector{ZZRingElem}, b::ZZMatrixOrPtr)
ccall((:fmpz_mat_fmpz_vec_mul_ptr, libflint), Nothing,

Check warning on line 1833 in src/flint/fmpz_mat.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz_mat.jl#L1832-L1833

Added lines #L1832 - L1833 were not covered by tests
(Ptr{Ref{ZZRingElem}}, Ptr{Ref{ZZRingElem}}, Int, Ref{ZZMatrix}),
z, a, length(a), b)
return z
end

function mul!(z::Vector{ZZRingElem}, a::Vector{ZZRingElem}, b::ZZMatrixOrPtr)
GC.@preserve z a begin
aa, dk1, dk2 = _very_unsafe_convert(ZZMatrix, a)
zz, dk3, dk4 = _very_unsafe_convert(ZZMatrix, z)
GC.@preserve dk1 dk2 dk3 dk4 begin
mul!(zz, aa, b)
for i in 1:length(z)
z[i].d = unsafe_load(zz.entries, i).d
end
end
end
return z
end

function Generic.add_one!(a::ZZMatrix, i::Int, j::Int)
@boundscheck _checkbounds(a, i, j)
GC.@preserve a begin
Expand Down

0 comments on commit 727faf5

Please sign in to comment.