core/ndstrides: remove unnecessary Result<_, String>
This commit is contained in:
parent
28e6f23034
commit
ac7cc15d90
@ -2244,7 +2244,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
|
|||||||
ctx,
|
ctx,
|
||||||
sizet_model.constant(tyctx, ctx.ctx, dst_ndims as u64),
|
sizet_model.constant(tyctx, ctx.ctx, dst_ndims as u64),
|
||||||
"subndarray",
|
"subndarray",
|
||||||
)?;
|
);
|
||||||
|
|
||||||
// Prepare the subscripts
|
// Prepare the subscripts
|
||||||
let (num_ndindexes, ndindexes) = RustNDIndex::alloca_ndindexes(tyctx, ctx, &rust_ndindexes);
|
let (num_ndindexes, ndindexes) = RustNDIndex::alloca_ndindexes(tyctx, ctx, &rust_ndindexes);
|
||||||
|
@ -43,7 +43,7 @@ where
|
|||||||
let shape_writer = make_shape_writer(generator, ctx, shape, shape_ty);
|
let shape_writer = make_shape_writer(generator, ctx, shape, shape_ty);
|
||||||
let ndims = shape_writer.len;
|
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)?;
|
init_ndarray_shape(generator, ctx, ndarray, &shape_writer)?;
|
||||||
|
|
||||||
let itemsize = ctx.get_llvm_type(generator, elem_ty).size_of().unwrap();
|
let itemsize = ctx.get_llvm_type(generator, elem_ty).size_of().unwrap();
|
||||||
|
@ -34,7 +34,7 @@ pub fn alloca_ndarray<'ctx, G>(
|
|||||||
ctx: &mut CodeGenContext<'ctx, '_>,
|
ctx: &mut CodeGenContext<'ctx, '_>,
|
||||||
ndims: Int<'ctx, SizeT>,
|
ndims: Int<'ctx, SizeT>,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Result<Ptr<'ctx, StructModel<NpArray>>, String>
|
) -> Ptr<'ctx, StructModel<NpArray>>
|
||||||
where
|
where
|
||||||
G: CodeGenerator + ?Sized,
|
G: CodeGenerator + ?Sized,
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ where
|
|||||||
ndarray_ptr.gep(ctx, |f| f.shape).store(ctx, shape);
|
ndarray_ptr.gep(ctx, |f| f.shape).store(ctx, shape);
|
||||||
ndarray_ptr.gep(ctx, |f| f.strides).store(ctx, strides);
|
ndarray_ptr.gep(ctx, |f| f.strides).store(ctx, strides);
|
||||||
|
|
||||||
Ok(ndarray_ptr)
|
ndarray_ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize an ndarray's `shape` and asserts on.
|
/// Initialize an ndarray's `shape` and asserts on.
|
||||||
@ -107,7 +107,7 @@ pub fn as_ndarray<'ctx, G: CodeGenerator + ?Sized>(
|
|||||||
ctx: &mut CodeGenContext<'ctx, '_>,
|
ctx: &mut CodeGenContext<'ctx, '_>,
|
||||||
input: BasicValueEnum<'ctx>,
|
input: BasicValueEnum<'ctx>,
|
||||||
input_ty: Type,
|
input_ty: Type,
|
||||||
) -> Result<(Ptr<'ctx, StructModel<NpArray>>, Type), String> {
|
) -> (Ptr<'ctx, StructModel<NpArray>>, Type) {
|
||||||
let tyctx = generator.type_context(ctx.ctx);
|
let tyctx = generator.type_context(ctx.ctx);
|
||||||
let sizet_model = IntModel(SizeT);
|
let sizet_model = IntModel(SizeT);
|
||||||
let pbyte_model = PtrModel(IntModel(Byte));
|
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 pndarray = pndarray_model.check_value(tyctx, ctx.ctx, input).unwrap();
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, input_ty);
|
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 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.
|
// 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();
|
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();
|
let itemsize = sizet_model.check_value(tyctx, ctx.ctx, itemsize).unwrap();
|
||||||
pndarray.gep(ctx, |f| f.itemsize).store(ctx, itemsize);
|
pndarray.gep(ctx, |f| f.itemsize).store(ctx, itemsize);
|
||||||
|
|
||||||
Ok((pndarray, input_ty))
|
(pndarray, input_ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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");
|
let end_bb = ctx.ctx.insert_basic_block_after(else_bb, "end_bb");
|
||||||
|
|
||||||
// Inserting into current_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
|
// Set shape - directly from user input
|
||||||
init_ndarray_shape(generator, ctx, dst_ndarray, new_shape)?;
|
init_ndarray_shape(generator, ctx, dst_ndarray, new_shape)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user