mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare] Require same vector orientation for dot and cross products
Change-Id: I4cf248cf564899314a1efb1c5e39a041395ba583
This commit is contained in:
committed by
EmilieNumworks
parent
cb54e22272
commit
c0413709b7
@@ -509,8 +509,8 @@ Expression Matrix::norm(ExpressionNode::ReductionContext reductionContext) const
|
||||
}
|
||||
|
||||
Expression Matrix::dot(Matrix * b, ExpressionNode::ReductionContext reductionContext) const {
|
||||
// Dot product is defined between two vectors of same size
|
||||
assert(isVector() && b->isVector() && numberOfChildren() == b->numberOfChildren());
|
||||
// Dot product is defined between two vectors of same size and orientation
|
||||
assert(isVector() && b->isVector() && numberOfChildren() == b->numberOfChildren() && numberOfRows() == b->numberOfRows());
|
||||
Addition sum = Addition::Builder();
|
||||
for (int j = 0; j < numberOfChildren(); j++) {
|
||||
Expression product = Multiplication::Builder(const_cast<Matrix *>(this)->childAtIndex(j).clone(), const_cast<Matrix *>(b)->childAtIndex(j).clone());
|
||||
@@ -521,8 +521,9 @@ Expression Matrix::dot(Matrix * b, ExpressionNode::ReductionContext reductionCon
|
||||
}
|
||||
|
||||
Matrix Matrix::cross(Matrix * b, ExpressionNode::ReductionContext reductionContext) const {
|
||||
// Cross product is defined between two vectors of size 3
|
||||
assert(isVector() && b->isVector() && numberOfChildren() == 3 && b->numberOfChildren() == 3);
|
||||
/* Cross product is defined between two vectors of size 3 and of same
|
||||
* orientation */
|
||||
assert(isVector() && b->isVector() && numberOfChildren() == 3 && b->numberOfChildren() == 3 && numberOfRows() == b->numberOfRows());
|
||||
Matrix matrix = Matrix::Builder();
|
||||
for (int j = 0; j < 3; j++) {
|
||||
int j1 = (j+1)%3;
|
||||
@@ -535,7 +536,7 @@ Matrix Matrix::cross(Matrix * b, ExpressionNode::ReductionContext reductionConte
|
||||
matrix.addChildAtIndexInPlace(difference, matrix.numberOfChildren(), matrix.numberOfChildren());
|
||||
difference.shallowReduce(reductionContext);
|
||||
}
|
||||
matrix.setDimensions(3, 1);
|
||||
matrix.setDimensions(numberOfRows(), numberOfColumns());
|
||||
return matrix;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ std::complex<T> MatrixComplexNode<T>::dot(Evaluation<T> * e) const {
|
||||
return std::complex<T>(NAN, NAN);
|
||||
}
|
||||
MatrixComplex<T> * b = static_cast<MatrixComplex<T>*>(e);
|
||||
if (!isVector() || !b->isVector() || numberOfChildren() != b->numberOfChildren()) {
|
||||
if (!isVector() || !b->isVector() || numberOfChildren() != b->numberOfChildren() || numberOfRows() != b->numberOfRows()) {
|
||||
return std::complex<T>(NAN, NAN);
|
||||
}
|
||||
std::complex<T> sum = 0;
|
||||
@@ -169,14 +169,14 @@ Evaluation<T> MatrixComplexNode<T>::cross(Evaluation<T> * e) const {
|
||||
return MatrixComplex<T>::Undefined();
|
||||
}
|
||||
MatrixComplex<T> * b = static_cast<MatrixComplex<T>*>(e);
|
||||
if (!isVector() || !b->isVector() || numberOfChildren() != 3 || b->numberOfChildren() != 3) {
|
||||
if (!isVector() || !b->isVector() || numberOfChildren() != 3 || b->numberOfChildren() != 3 || numberOfRows() != b->numberOfRows()) {
|
||||
return MatrixComplex<T>::Undefined();
|
||||
}
|
||||
std::complex<T> operandsCopy[3];
|
||||
operandsCopy[0] = complexAtIndex(1) * b->complexAtIndex(2) - complexAtIndex(2) * b->complexAtIndex(1);
|
||||
operandsCopy[1] = complexAtIndex(2) * b->complexAtIndex(0) - complexAtIndex(0) * b->complexAtIndex(2);
|
||||
operandsCopy[2] = complexAtIndex(0) * b->complexAtIndex(1) - complexAtIndex(1) * b->complexAtIndex(0);
|
||||
return MatrixComplex<T>::Builder(operandsCopy, 3, 1);
|
||||
return MatrixComplex<T>::Builder(operandsCopy, numberOfRows(), numberOfColumns());
|
||||
}
|
||||
|
||||
// MATRIX COMPLEX REFERENCE
|
||||
|
||||
@@ -45,7 +45,7 @@ Expression VectorCross::shallowReduce(ExpressionNode::ReductionContext reduction
|
||||
Matrix matrixChild0 = static_cast<Matrix&>(c0);
|
||||
Matrix matrixChild1 = static_cast<Matrix&>(c1);
|
||||
// Cross product is defined between two vectors of size 3
|
||||
if (!matrixChild0.isVector() || !matrixChild1.isVector() || matrixChild0.numberOfChildren() != 3 || matrixChild1.numberOfChildren() != 3) {
|
||||
if (!matrixChild0.isVector() || !matrixChild1.isVector() || matrixChild0.numberOfChildren() != 3 || matrixChild1.numberOfChildren() != 3 || matrixChild0.numberOfRows() != matrixChild1.numberOfRows()) {
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Expression a = matrixChild0.cross(&matrixChild1, reductionContext);
|
||||
|
||||
@@ -44,8 +44,9 @@ Expression VectorDot::shallowReduce(ExpressionNode::ReductionContext reductionCo
|
||||
if (c0.type() == ExpressionNode::Type::Matrix && c1.type() == ExpressionNode::Type::Matrix) {
|
||||
Matrix matrixChild0 = static_cast<Matrix&>(c0);
|
||||
Matrix matrixChild1 = static_cast<Matrix&>(c1);
|
||||
// Dot product is defined between two vectors of the same dimensions
|
||||
if (!matrixChild0.isVector() || !matrixChild1.isVector() || matrixChild0.numberOfChildren() != matrixChild1.numberOfChildren()) {
|
||||
/* Dot product is defined between two vectors of the same dimension and
|
||||
* orientation */
|
||||
if (!matrixChild0.isVector() || !matrixChild1.isVector() || matrixChild0.numberOfChildren() != matrixChild1.numberOfChildren() || matrixChild0.numberOfRows() != matrixChild1.numberOfRows()) {
|
||||
return replaceWithUndefinedInPlace();
|
||||
}
|
||||
Expression a = matrixChild0.dot(&matrixChild1, reductionContext);
|
||||
|
||||
@@ -440,15 +440,11 @@ QUIZ_CASE(poincare_approximation_function) {
|
||||
|
||||
assert_expression_approximates_to<float>("cross([[1][2][3]],[[4][7][8]])", "[[-5][4][-1]]");
|
||||
assert_expression_approximates_to<double>("cross([[1][2][3]],[[4][7][8]])", "[[-5][4][-1]]");
|
||||
assert_expression_approximates_to<float>("cross([[1,2,3]],[[4][7][8]])", "[[-5][4][-1]]");
|
||||
assert_expression_approximates_to<double>("cross([[1,2,3]],[[4][7][8]])", "[[-5][4][-1]]");
|
||||
assert_expression_approximates_to<float>("cross([[1,2,3]],[[4,7,8]])", "[[-5][4][-1]]");
|
||||
assert_expression_approximates_to<double>("cross([[1,2,3]],[[4,7,8]])", "[[-5][4][-1]]");
|
||||
assert_expression_approximates_to<float>("cross([[1,2,3]],[[4,7,8]])", "[[-5,4,-1]]");
|
||||
assert_expression_approximates_to<double>("cross([[1,2,3]],[[4,7,8]])", "[[-5,4,-1]]");
|
||||
|
||||
assert_expression_approximates_to<float>("dot([[1][2][3]],[[4][7][8]])", "42");
|
||||
assert_expression_approximates_to<double>("dot([[1][2][3]],[[4][7][8]])", "42");
|
||||
assert_expression_approximates_to<float>("dot([[1,2,3]],[[4][7][8]])", "42");
|
||||
assert_expression_approximates_to<double>("dot([[1,2,3]],[[4][7][8]])", "42");
|
||||
assert_expression_approximates_to<float>("dot([[1,2,3]],[[4,7,8]])", "42");
|
||||
assert_expression_approximates_to<double>("dot([[1,2,3]],[[4,7,8]])", "42");
|
||||
|
||||
|
||||
@@ -1091,12 +1091,14 @@ QUIZ_CASE(poincare_simplification_matrix) {
|
||||
|
||||
// Cross product
|
||||
assert_parsed_expression_simplify_to("cross([[0][1/√(2)][0]],[[0][0][1]])", "[[√(2)/2][0][0]]");
|
||||
assert_parsed_expression_simplify_to("cross([[1,2,3]],[[4][7][8]])", "[[-5][4][-1]]");
|
||||
assert_parsed_expression_simplify_to("cross([[1,π,𝐢]],[[𝐢π,𝐢π^2,-π]])", "[[0][0][0]]");
|
||||
assert_parsed_expression_simplify_to("cross([[1,2,3]],[[4][7][8]])", Undefined::Name());
|
||||
assert_parsed_expression_simplify_to("cross([[1,2,3]],[[4,7,8]])", "[[-5,4,-1]]");
|
||||
assert_parsed_expression_simplify_to("cross([[1,π,𝐢]],[[𝐢π,𝐢π^2,-π]])", "[[0,0,0]]");
|
||||
|
||||
// Dot product
|
||||
assert_parsed_expression_simplify_to("dot([[1/√(2)][0][0]],[[1][0][0]])", "√(2)/2");
|
||||
assert_parsed_expression_simplify_to("dot([[1,1,0]],[[0][0][1]])", "0");
|
||||
assert_parsed_expression_simplify_to("dot([[1,1,0]],[[0][0][1]])", Undefined::Name());
|
||||
assert_parsed_expression_simplify_to("dot([[1,1,0]],[[0,0,1]])", "0");
|
||||
assert_parsed_expression_simplify_to("dot([[1,1,1]],[[0,π,𝐢]])", "π+𝐢");
|
||||
|
||||
// Vector norm
|
||||
|
||||
Reference in New Issue
Block a user