From 202a63274daf6fc1f677cdb24dd5c06e5a0d6e29 Mon Sep 17 00:00:00 2001 From: David Mak Date: Mon, 17 Jun 2024 14:38:06 +0800 Subject: [PATCH] artiq: Implement pyty-to-ty conversion --- nac3artiq/src/symbol_resolver.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index e06ed4d2..b9fb6ba8 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -493,7 +493,23 @@ impl InnerResolver { ))); } - todo!() + // npt.NDArray[T] == np.ndarray[Any, np.dtype[T]] + let ndarray_dtype_pyty = + self.helper.args_ty_fn.call1(py, (args.get_item(1)?,))?; + let dtype = ndarray_dtype_pyty.downcast::(py)?.get_item(0)?; + + let ty = match self.get_pyty_obj_type(py, dtype, unifier, defs, primitives)? { + Ok(ty) => ty, + Err(err) => return Ok(Err(err)), + }; + + if !unifier.is_concrete(ty.0, &[]) && !ty.1 { + return Ok(Err( + "type `ndarray` should take concrete parameters for dtype".into() + )); + } + + Ok(Ok((make_ndarray_ty(unifier, primitives, Some(ty.0), None), true))) } TypeEnum::TTuple { .. } => { let args = match args