50
50
51
51
Base. length (x:: _UnsafeVectorView ) = x. len
52
52
53
+ Base. size (x:: _UnsafeVectorView ) = (x. len,)
54
+
53
55
function _UnsafeVectorView (x:: Vector , N:: Int )
54
56
if length (x) < N
55
57
resize! (x, N)
@@ -88,17 +90,20 @@ valid during the usage of `_UnsafeHessianView`.
88
90
"""
89
91
struct _UnsafeHessianView <: AbstractMatrix{Float64}
90
92
N:: Int
91
- x :: _UnsafeVectorView{T }
93
+ ptr :: Ptr{Float64 }
92
94
end
93
95
94
96
Base. size (x:: _UnsafeHessianView ) = (x. N, x. N)
95
97
96
98
_linear_index (i, j) = i >= j ? div ((i - 1 ) * i, 2 ) + j : _linear_index (j, i)
97
99
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
99
103
100
104
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
102
107
end
103
108
104
109
function _UnsafeHessianView (x:: Vector , N:: Int )
@@ -109,7 +114,7 @@ function _UnsafeHessianView(x::Vector, N::Int)
109
114
for i in 1 : z
110
115
x[i] = 0.0
111
116
end
112
- return _UnsafeHessianView (N, _UnsafeVectorView ( 0 , z, pointer (x) ))
117
+ return _UnsafeHessianView (N, pointer (x))
113
118
end
114
119
115
120
"""
0 commit comments