MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / _py_to_lean_array

Method _py_to_lean_array

lean_py/marshal.py:468–477  ·  view source on GitHub ↗

Build a Lean Array from a Python iterable. Returns owned ptr.

(self, xs, elem_w: TypeWrapper)

Source from the content-addressed store, hash-verified

466 return out
467
468 def _py_to_lean_array(self, xs, elem_w: TypeWrapper) -> Any:
469 """Build a Lean Array from a Python iterable. Returns owned ptr."""
470 items = list(xs)
471 arr = self.ffi.lean_alloc_array(len(items), len(items))
472 # arr's m_data[i] holds owned pointers.
473 for i, x in enumerate(items):
474 child = elem_w.to_lean(x)
475 # Use lean_array_set_core (sets without bumping refcounts).
476 self.ffi.lean_array_set_core(arr, i, child)
477 return arr
478
479 def _ctor_field_layout(self, ctor: CtorInfo):
480 """Compute the ABI memory layout for a constructor's fields.

Callers 1

to_leanMethod · 0.95

Calls 1

to_leanMethod · 0.80

Tested by

no test coverage detected