5050
5151Base. length (x:: _UnsafeVectorView ) = x. len
5252
53+ Base. size (x:: _UnsafeVectorView ) = (x. len,)
54+
5355function _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"""
8991struct _UnsafeHessianView <: AbstractMatrix{Float64}
9092 N:: Int
91- x :: _UnsafeVectorView{T }
93+ ptr :: Ptr{Float64 }
9294end
9395
9496Base. 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
100104function 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
102107end
103108
104109function _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))
113118end
114119
115120"""
0 commit comments