simit icon indicating copy to clipboard operation
simit copied to clipboard

Feature requests (simple operations & functions)

Open VikingScientist opened this issue 8 years ago • 6 comments

There are a number of simple functions which I would like to see added support for

  • [x] A = a * B scalar-matrix multiplication
  • [x] A = B * a matrix-scalar multiplication
  • [x] b = a * c scalar-vector multiplication
  • [x] b = c * a vector-scalar multiplication
  • [ ] det(A : matrix[2,2](float) ) 2x2 determinant
  • [ ] det(A : matrix[4,4](float) ) 4x4 determinant
  • [ ] inv(A : matrix[2,2](float) ) 2x2 inverse
  • [ ] inv(A : matrix[4,4](float) ) 4x4 inverse
  • [ ] eye(n : int) -> matrix[n,n](float) returns identity matrix
  • [ ] min(vector[V](float)) -> float returns minimum value
  • [ ] max(vector[V](float)) -> float returns maximum value
  • [ ] abs(float) -> float returns absolute value
  • [ ] abs(int) -> int returns absolute value
  • [ ] abs(vector[V](float)) -> vector[V](float) returns absolute value
  • [ ] abs(vector[V](int)) -> vector[V](int) returns absolute value
  • [ ] cbrt(float) -> float returns cube root
  • [ ] size(Set) -> int returns size of set

VikingScientist avatar Aug 24 '16 08:08 VikingScientist

Thanks for the suggestions! Multiplication of a scalar by a matrix or vector (and vice versa) is actually already supported; the website should be updated to reflect that. I can look into implementing the other intrinsics you have suggested.eye as you have proposed probably can't be incorporated into Simit since the type of the return value would not be inferable at compile-time, but something like this can probably be implemented instead:

eye<0:N>() -> matrix[N,N](float)

stephenchouca avatar Aug 26 '16 17:08 stephenchouca

I thought about eye in the past and was playing with the idea of reserving I as a keyword. Is this too extreme?

In many cases it seems that we can infer it. If I use it in an expression A = I*b, why do I have to declare it, since I know it from the context? Specifically, I know it as long as the index variables used to index it are also used to index any known dimension. @stephenchouca will this be too tricky to infer?

fredrikbk avatar Aug 29 '16 17:08 fredrikbk

The keyword I might be confused with both general running index i and complex numbers i. If you continue with the mission statement of designing a "matlab-like" language, I think it would be in your best interest to use syntax as close to matlab as possible, and matlab is using eye().

By the way, if you manage to get the identity matrix working for arbitrary sizes and map the solver operator successfully mapped to LU solvers (issue #50), then you can make an arbitrary size inverse function by returning A_inv = A \ eye(n)

VikingScientist avatar Aug 30 '16 07:08 VikingScientist

@fredrikbk Adding support for a reserved I identity matrix should be feasible though it would probably require a non-trivial amount of changes to the type checker, since the compiler currently only supports inferring an expression's type from the types of its subexpressions and not the other way around. One potential practical concern is that, depending on what the precise semantics are, having arbitrary-sized identity matrices can potentially complicate specialization of generic functions if a generic function is called with an identity matrix (of unknown size) as a parameter.

stephenchouca avatar Aug 30 '16 17:08 stephenchouca

I was playing around with simit again and from what I can tell it seems like these have been fixed since 2016.

Am I right to assume that all of them have been fixed? Is this issue ready to closed?

VikingScientist avatar Sep 04 '18 08:09 VikingScientist

I don't think we've fixed all of them, but I'm not sure which ones are done and not.

fredrikbk avatar Sep 10 '18 14:09 fredrikbk