Skip to content

Commit 91e082f

Browse files
committed
Fix
1 parent aaf35c8 commit 91e082f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Diff for: src/Nonlinear/ReverseAD/utils.jl

+9-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ end
5050

5151
Base.length(x::_UnsafeVectorView) = x.len
5252

53+
Base.size(x::_UnsafeVectorView) = (x.len,)
54+
5355
function _UnsafeVectorView(x::Vector, N::Int)
5456
if length(x) < N
5557
resize!(x, N)
@@ -88,17 +90,20 @@ valid during the usage of `_UnsafeHessianView`.
8890
"""
8991
struct _UnsafeHessianView <: AbstractMatrix{Float64}
9092
N::Int
91-
x::_UnsafeVectorView{T}
93+
ptr::Ptr{Float64}
9294
end
9395

9496
Base.size(x::_UnsafeHessianView) = (x.N, x.N)
9597

9698
_linear_index(i, j) = i >= j ? div((i - 1) * i, 2) + j : _linear_index(j, i)
9799

98-
Base.getindex(x::_UnsafeHessianView, i, j) = x.x[_linear_index(i, j)]
100+
function Base.getindex(x::_UnsafeHessianView, i, j)
101+
return unsafe_load(x.ptr, _linear_index(i, j))
102+
end
99103

100104
function Base.setindex!(x::_UnsafeHessianView, value, i, j)
101-
return x[_linear_index(i, j)] = value
105+
unsafe_store!(x.ptr, value, _linear_index(i, j))
106+
return value
102107
end
103108

104109
function _UnsafeHessianView(x::Vector, N::Int)
@@ -109,7 +114,7 @@ function _UnsafeHessianView(x::Vector, N::Int)
109114
for i in 1:z
110115
x[i] = 0.0
111116
end
112-
return _UnsafeHessianView(N, _UnsafeVectorView(0, z, pointer(x)))
117+
return _UnsafeHessianView(N, pointer(x))
113118
end
114119

115120
"""

0 commit comments

Comments
 (0)