mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 17:50:04 +01:00
[poincare] Evaluation return numerical matrix
Change-Id: I58dbc93ad22a086580a77318b2524db9c70e47d2
This commit is contained in:
@@ -19,49 +19,15 @@ Function::Function(const char * name, int requiredNumberOfArguments) :
|
||||
}
|
||||
|
||||
void Function::setArgument(Expression ** args, int numberOfArguments, bool clone) {
|
||||
if (m_args != nullptr) {
|
||||
for (int i = 0; i < m_numberOfArguments; i++) {
|
||||
delete m_args[i];
|
||||
}
|
||||
free(m_args);
|
||||
}
|
||||
m_numberOfArguments = numberOfArguments;
|
||||
m_args = (Expression **)malloc(numberOfArguments*sizeof(Expression *));
|
||||
for (int i = 0; i < numberOfArguments; i++) {
|
||||
assert(args[i] != nullptr);
|
||||
if (clone) {
|
||||
m_args[i] = args[i]->clone();
|
||||
} else {
|
||||
m_args[i] = args[i];
|
||||
}
|
||||
}
|
||||
build(args, numberOfArguments, clone);
|
||||
}
|
||||
|
||||
void Function::setArgument(ListData * listData, bool clone) {
|
||||
if (m_args != nullptr) {
|
||||
for (int i = 0; i < m_numberOfArguments; i++) {
|
||||
delete m_args[i];
|
||||
}
|
||||
free(m_args);
|
||||
}
|
||||
m_numberOfArguments = listData->numberOfOperands();
|
||||
m_args = (Expression **)malloc(m_numberOfArguments*sizeof(Expression *));
|
||||
for (int i = 0; i < m_numberOfArguments; i++) {
|
||||
if (clone) {
|
||||
m_args[i] = (Expression *)listData->operand(i)->clone();
|
||||
} else {
|
||||
m_args[i] = (Expression *)listData->operand(i);
|
||||
}
|
||||
}
|
||||
build(listData->operands(), listData->numberOfOperands(), clone);
|
||||
}
|
||||
|
||||
Function::~Function() {
|
||||
if (m_args != nullptr) {
|
||||
for (int i = 0; i < m_numberOfArguments; i++) {
|
||||
delete m_args[i];
|
||||
}
|
||||
free(m_args);
|
||||
}
|
||||
clean();
|
||||
}
|
||||
|
||||
bool Function::hasValidNumberOfArguments() const {
|
||||
@@ -76,28 +42,6 @@ bool Function::hasValidNumberOfArguments() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
Expression * Function::clone() const {
|
||||
return this->cloneWithDifferentOperands(m_args, m_numberOfArguments, true);
|
||||
}
|
||||
|
||||
ExpressionLayout * Function::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
assert(complexFormat != ComplexFormat::Default);
|
||||
ExpressionLayout ** grandChildrenLayouts = (ExpressionLayout **)malloc((2*m_numberOfArguments-1)*sizeof(ExpressionLayout *));
|
||||
int layoutIndex = 0;
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[0]->createLayout(floatDisplayMode, complexFormat);
|
||||
for (int i = 1; i < m_numberOfArguments; i++) {
|
||||
grandChildrenLayouts[layoutIndex++] = new StringLayout(",", 1);
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[i]->createLayout(floatDisplayMode, complexFormat);
|
||||
}
|
||||
ExpressionLayout * argumentLayouts = new HorizontalLayout(grandChildrenLayouts, 2*m_numberOfArguments-1);
|
||||
free(grandChildrenLayouts);
|
||||
ExpressionLayout * childrenLayouts[2];
|
||||
childrenLayouts[0] = new StringLayout(m_name, strlen(m_name));
|
||||
childrenLayouts[1] = new ParenthesisLayout(argumentLayouts);
|
||||
return new HorizontalLayout(childrenLayouts, 2);
|
||||
}
|
||||
|
||||
const Expression * Function::operand(int i) const {
|
||||
assert(i >= 0 && i < m_numberOfArguments);
|
||||
return m_args[i];
|
||||
@@ -107,10 +51,73 @@ int Function::numberOfOperands() const {
|
||||
return m_numberOfArguments;
|
||||
}
|
||||
|
||||
Expression * Function::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
assert(angleUnit != AngleUnit::Default);
|
||||
/* Default function evaluation works for reel function */
|
||||
return new Complex(Complex::Float(approximate(context, angleUnit)));
|
||||
Expression * Function::clone() const {
|
||||
return this->cloneWithDifferentOperands(m_args, m_numberOfArguments, true);
|
||||
}
|
||||
|
||||
Complex Function::computeComplex(const Complex c, AngleUnit angleUnit) const {
|
||||
return Complex::Float(NAN);
|
||||
}
|
||||
|
||||
Evaluation * Function::privateEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
if (m_numberOfArguments != 1) {
|
||||
return new Complex(Complex::Float(NAN));
|
||||
}
|
||||
Evaluation * input = m_args[0]->evaluate(context, angleUnit);
|
||||
Complex * operands = new Complex[input->numberOfRows()*input->numberOfColumns()];
|
||||
for (int i = 0; i < input->numberOfOperands(); i++) {
|
||||
operands[i] = computeComplex(*input->complexOperand(i), angleUnit);
|
||||
}
|
||||
Evaluation * result = nullptr;
|
||||
if (input->numberOfOperands() == 1) {
|
||||
result = new Complex(operands[0]);
|
||||
} else {
|
||||
result = new ComplexMatrix(operands, input->numberOfRows(), input->numberOfColumns());
|
||||
}
|
||||
delete input;
|
||||
delete[] operands;
|
||||
return result;
|
||||
}
|
||||
|
||||
ExpressionLayout * Function::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
|
||||
assert(floatDisplayMode != FloatDisplayMode::Default);
|
||||
assert(complexFormat != ComplexFormat::Default);
|
||||
ExpressionLayout ** grandChildrenLayouts = new ExpressionLayout *[2*m_numberOfArguments-1];
|
||||
int layoutIndex = 0;
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[0]->createLayout(floatDisplayMode, complexFormat);
|
||||
for (int i = 1; i < m_numberOfArguments; i++) {
|
||||
grandChildrenLayouts[layoutIndex++] = new StringLayout(",", 1);
|
||||
grandChildrenLayouts[layoutIndex++] = m_args[i]->createLayout(floatDisplayMode, complexFormat);
|
||||
}
|
||||
ExpressionLayout * argumentLayouts = new HorizontalLayout(grandChildrenLayouts, 2*m_numberOfArguments-1);
|
||||
delete [] grandChildrenLayouts;
|
||||
ExpressionLayout * childrenLayouts[2];
|
||||
childrenLayouts[0] = new StringLayout(m_name, strlen(m_name));
|
||||
childrenLayouts[1] = new ParenthesisLayout(argumentLayouts);
|
||||
return new HorizontalLayout(childrenLayouts, 2);
|
||||
}
|
||||
|
||||
void Function::build(Expression ** args, int numberOfArguments, bool clone) {
|
||||
clean();
|
||||
m_numberOfArguments = numberOfArguments;
|
||||
m_args = new Expression * [numberOfArguments];
|
||||
for (int i = 0; i < numberOfArguments; i++) {
|
||||
assert(args[i] != nullptr);
|
||||
if (clone) {
|
||||
m_args[i] = args[i]->clone();
|
||||
} else {
|
||||
m_args[i] = args[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Function::clean() {
|
||||
if (m_args != nullptr) {
|
||||
for (int i = 0; i < m_numberOfArguments; i++) {
|
||||
delete m_args[i];
|
||||
}
|
||||
delete[] m_args;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user