Skip to content

Commit c587952

Browse files
DOC: Add docstrings to quantlib/math/array.pyx
This commit adds numpydoc-style docstrings to the `Array` class and its methods in `quantlib/math/array.pyx`. The docstrings are based on the documentation from the original QuantLib C++ library and are adapted for Python style.
1 parent 137b85f commit c587952

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

quantlib/math/array.pyx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@ cimport numpy as np
1515
np.import_array()
1616

1717
cdef class Array:
18-
"""
19-
1D array for linear algebra
18+
"""1D array for linear algebra.
19+
20+
This class implements the concept of a vector as used in linear algebra.
21+
22+
Parameters
23+
----------
24+
size : int, optional
25+
The size of the array.
26+
value : float, optional
27+
The value to fill the array with.
28+
2029
"""
2130

2231
def __init__(self, Size size=0, value=None):
@@ -39,6 +48,7 @@ cdef class Array:
3948
return self._thisptr.size()
4049

4150
def to_ndarray(self):
51+
"""Returns a view of the array as a numpy array."""
4252
cdef np.npy_intp[1] dims
4353
dims[0] = self._thisptr.size()
4454
cdef arr = np.PyArray_SimpleNewFromData(1, &dims[0], np.NPY_DOUBLE, <void*>(self._thisptr.begin()))
@@ -47,10 +57,12 @@ cdef class Array:
4757
return arr
4858

4959
cpdef qlarray_from_pyarray(p):
60+
"""Create a QuantLib Array from a Python array."""
5061
cdef Array x = Array(len(p))
5162
for i in range(len(p)):
5263
x._thisptr[i] = p[i]
5364
return x
5465

5566
cpdef pyarray_from_qlarray(a):
67+
"""Create a Python array from a QuantLib Array."""
5668
return [a[i] for i in range(a.size)]

0 commit comments

Comments
 (0)