forked from M-Labs/nac3
1
0
Fork 0

core/ndstrides: remove unnecessary Result<_, String>

This commit is contained in:
lyken 2024-07-29 17:20:54 +08:00
parent 28e6f23034
commit ac7cc15d90
4 changed files with 9 additions and 9 deletions

View File

@ -2244,7 +2244,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
ctx,
sizet_model.constant(tyctx, ctx.ctx, dst_ndims as u64),
"subndarray",
)?;
);
// Prepare the subscripts
let (num_ndindexes, ndindexes) = RustNDIndex::alloca_ndindexes(tyctx, ctx, &rust_ndindexes);

View File

@ -43,7 +43,7 @@ where
let shape_writer = make_shape_writer(generator, ctx, shape, shape_ty);
let ndims = shape_writer.len;
let ndarray = alloca_ndarray(generator, ctx, ndims, name)?;
let ndarray = alloca_ndarray(generator, ctx, ndims, name);
init_ndarray_shape(generator, ctx, ndarray, &shape_writer)?;
let itemsize = ctx.get_llvm_type(generator, elem_ty).size_of().unwrap();

View File

@ -34,7 +34,7 @@ pub fn alloca_ndarray<'ctx, G>(
ctx: &mut CodeGenContext<'ctx, '_>,
ndims: Int<'ctx, SizeT>,
name: &str,
) -> Result<Ptr<'ctx, StructModel<NpArray>>, String>
) -> Ptr<'ctx, StructModel<NpArray>>
where
G: CodeGenerator + ?Sized,
{
@ -54,7 +54,7 @@ where
ndarray_ptr.gep(ctx, |f| f.shape).store(ctx, shape);
ndarray_ptr.gep(ctx, |f| f.strides).store(ctx, strides);
Ok(ndarray_ptr)
ndarray_ptr
}
/// Initialize an ndarray's `shape` and asserts on.
@ -107,7 +107,7 @@ pub fn as_ndarray<'ctx, G: CodeGenerator + ?Sized>(
ctx: &mut CodeGenContext<'ctx, '_>,
input: BasicValueEnum<'ctx>,
input_ty: Type,
) -> Result<(Ptr<'ctx, StructModel<NpArray>>, Type), String> {
) -> (Ptr<'ctx, StructModel<NpArray>>, Type) {
let tyctx = generator.type_context(ctx.ctx);
let sizet_model = IntModel(SizeT);
let pbyte_model = PtrModel(IntModel(Byte));
@ -120,11 +120,11 @@ pub fn as_ndarray<'ctx, G: CodeGenerator + ?Sized>(
{
let pndarray = pndarray_model.check_value(tyctx, ctx.ctx, input).unwrap();
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, input_ty);
Ok((pndarray, elem_ty))
(pndarray, elem_ty)
}
_ => {
let ndims = sizet_model.const_0(tyctx, ctx.ctx);
let pndarray = alloca_ndarray(generator, ctx, ndims, "ndarray")?;
let pndarray = alloca_ndarray(generator, ctx, ndims, "ndarray");
// We have to put `input` onto the stack to get a data pointer.
let data = ctx.builder.build_alloca(input.get_type(), "as_ndarray_scalar").unwrap();
@ -137,7 +137,7 @@ pub fn as_ndarray<'ctx, G: CodeGenerator + ?Sized>(
let itemsize = sizet_model.check_value(tyctx, ctx.ctx, itemsize).unwrap();
pndarray.gep(ctx, |f| f.itemsize).store(ctx, itemsize);
Ok((pndarray, input_ty))
(pndarray, input_ty)
}
}
}

View File

@ -37,7 +37,7 @@ fn gen_reshape_ndarray_or_copy<'ctx, G: CodeGenerator + ?Sized>(
let end_bb = ctx.ctx.insert_basic_block_after(else_bb, "end_bb");
// Inserting into current_bb
let dst_ndarray = alloca_ndarray(generator, ctx, new_shape.len, "ndarray").unwrap();
let dst_ndarray = alloca_ndarray(generator, ctx, new_shape.len, "ndarray");
// Set shape - directly from user input
init_ndarray_shape(generator, ctx, dst_ndarray, new_shape)?;