Upsurge icon indicating copy to clipboard operation
Upsurge copied to clipboard

Scalar arithmetic

Open carsonfarmer opened this issue 7 years ago • 0 comments

I may be missing something obvious, but is there a 'trick' to performing arithmetic on Matrices with scalars? Simple things like 1.0 + exp(A) seems to require working with a matrix's elements directly (which isn't very aesthetically pleasing), and a very specific ordering of arguments:

let A = Matrix<Double>([[1,  1], [1, -1]])
let B = A.copy()
A.elements = exp(A.elements) + 1.0  // works
A.elements = 1.0 + exp(A.elements)  // build error
print(1.0 + exp(A))  // build error
print(A)

Am I missing something obvious here? I can always add functions myself (e.g., exp), but I'd rather not if there is a 'right' way to do things here. I'm also interested in arithmetic on Tensors, which seem to have the same 'issues'. The Surge library from which Upsurge is forked had a few functions for things like exp on matrices, but these don't seem to be part of Upsurge, so I figured there must be an alternative?

carsonfarmer avatar May 22 '17 23:05 carsonfarmer