Question: Problem with codegen applied to a rectangular (Array) matrix.

Hey,

I am using codegen to generate code from Maple expressions. More specifically I want to export non quadratic matix. The export works for matrices that have more columns than rows, but not for matrices with more rows than columns. There I receive the error:

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

A workaround would be to transpose the matrix before the export, and to transpose on the import (in Matlab) but I don't want to overcomplicate my code. Thanks for your help!

I have attached a demonstration worksheet below.

 

## test codegen non quadratic returnarray

## works
#Myfun := Matrix(3,3)

## works
#Myfun := Matrix(2,3):Myfun(2,3):= 3*b;

## does not work
Myfun := Matrix(3,2):Myfun(3,2):= 3*b;

Myfun := Matrix(3, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})

(1)

Myfun(1):= 7*a;

Myfun := Matrix(3, 2, {(1, 1) = 7*a, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})

(2)

## codegen works best with arraybased matrices, and call by reference becomes possible

returnArray:= convert(Myfun,matrix)

returnArray := Matrix(3, 2, {(1, 1) = 7*a, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})

(3)

codegen[makeproc](Myfun,[a,b])

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

 

codegen[makeproc](returnArray,[returnArray,a,b])

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

 

codegen[makeproc](returnArray,[a,b])

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

 

 


 

Download codegen_rectangular_matrix.mw

 

Please Wait...