From 2d498de6c105e57c32c9048e5901955556ab38bf Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Thu, 13 Jan 2022 20:33:51 +0000 Subject: =?UTF-8?q?Implement=20dyadic=20(integer=20only)=20version=20of=20?= =?UTF-8?q?+=20-=20=C3=97=20=C3=B7=20*=20=E2=8D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'array.c') diff --git a/array.c b/array.c index 4913112..a2afc44 100644 --- a/array.c +++ b/array.c @@ -41,3 +41,41 @@ simplescalar(Array *a) { return simplearray(a) && a->rank == 0; } + +Array * +extend(Array *a, Array *b) +{ + /* extend the singleton a to the shape of b */ + Array *shape = fnShape(b); + Array *res = fnReshape(shape, a); + freearray(shape); + return res; +} + +int +scalarextend(Array *a, Array *b, Array **aa, Array **bb) +{ + /* Extend the arrays a and b to have the same shape. + The resulting arrays are stored in aa and bb, + except when the ranks don't match or extension can't + happen, in which case the function returns 0 and + aa and bb are unchanged. + */ + + if(a->size == 1 && b->size != 1){ + *aa = extend(a, b); + *bb = fnSame(b); + }else if(b->size == 1 && a->size != 1){ + *aa = fnSame(a); + *bb = extend(b, a); + }else if(a->size == b->size && a->rank == b->rank){ + /* Check that each dimension matches */ + for(int i = 0; i < a->rank; i++) + if(a->shape[i] != b->shape[i]) + return 0; + *aa = fnSame(a); + *bb = fnSame(b); + }else + return 0; + return 1; +} \ No newline at end of file -- cgit v1.2.3