mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add syntactic sugar to Eigen tensors to allow more natural syntax.
Specifically, this enables expressions involving: scalar + tensor scalar * tensor scalar / tensor scalar - tensor
This commit is contained in:
@@ -215,6 +215,13 @@ class TensorBase<Derived, ReadOnlyAccessors>
|
||||
return unaryExpr(internal::scalar_add_op<Scalar>(rhs));
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE friend
|
||||
const TensorCwiseUnaryOp<internal::scalar_add_op<Scalar>, const Derived>
|
||||
operator+ (Scalar lhs, const Derived& rhs) {
|
||||
return rhs + lhs;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_sub_op<Scalar>, const Derived>
|
||||
operator- (Scalar rhs) const {
|
||||
@@ -222,18 +229,41 @@ class TensorBase<Derived, ReadOnlyAccessors>
|
||||
return unaryExpr(internal::scalar_sub_op<Scalar>(rhs));
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE friend
|
||||
const TensorCwiseUnaryOp<internal::scalar_add_op<Scalar>,
|
||||
const TensorCwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> >
|
||||
operator- (Scalar lhs, const Derived& rhs) {
|
||||
return -rhs + lhs;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Derived>
|
||||
operator* (Scalar rhs) const {
|
||||
return unaryExpr(internal::scalar_multiple_op<Scalar>(rhs));
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE friend
|
||||
const TensorCwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Derived>
|
||||
operator* (Scalar lhs, const Derived& rhs) {
|
||||
return rhs * lhs;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, const Derived>
|
||||
operator/ (Scalar rhs) const {
|
||||
return unaryExpr(internal::scalar_quotient1_op<Scalar>(rhs));
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE friend
|
||||
const TensorCwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
|
||||
const TensorCwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> >
|
||||
operator/ (Scalar lhs, const Derived& rhs) {
|
||||
return rhs.inverse() * lhs;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_mod_op<Scalar>, const Derived>
|
||||
operator% (Scalar rhs) const {
|
||||
|
||||
Reference in New Issue
Block a user