tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.02k stars 48 forks source link

Linear algebra lib #146

Closed porky11 closed 7 years ago

porky11 commented 7 years ago

I started to write a lib for linear algebra, but don't know how to get it work (i.e. how to get the type-information of the types) see https://github.com/porky11/dale-linear-algebra/blob/master/src/linear-algebra.dt

Is this already possible in a proper way, and how should this be done?

tomhrr commented 7 years ago

value-type is defined in the linked file like so:

(def value-type (macro extern ((arrp (p (Array (uq T) (uq N))))) (q (uq T))))

but the existing value-type definitions take a pointer to the defined type as their single argument. For example, for vector:

(def value-type
  (macro extern ((vecp (p (Vector (uq T)))))
    (qq do (uq T))))

The definition here looks like it should instead be:

(def value-type (macro extern ((arrp (p (Matrix (uq T) (uq N) (uq M))))) (q (uq T))))
porky11 commented 7 years ago

This is not the problem I had. I just don't think, this will be useful for what i want to do later (insantiating concept macros) I tried to create some test which instantiates some Matrix instance. There are sometimes errors like this: <unknown>:0:0: error: unquoting null node

tomhrr commented 7 years ago

Some of these errors are happening because of type mismatches, e.g. in the for loop in the definition of +: the < call has arguments of int and size, which means that the transitive < from the operator macros module is called, which fails because there are only two arguments and the varargs-list is null. I tried updating the operator macros module to report an error when the varargs-list is null, but it doesn't appear to be working correctly with other parts of the code. I'll keep looking at this and let you know what I find.

porky11 commented 7 years ago

thanks but I hope, i'll find some errors myself Some error messages are yet difficult to know, ehat they mean. And I dont think the macros will work in later concept macros for * (you see in the comment)

tomhrr commented 7 years ago

https://github.com/tomhrr/dale-linear-algebra/commit/8ba43ddd4eb5bf88a6c0315a31713227ad8d1c17 has + and the first * working. I think the problem with the second * is mostly to do with referring to a and b, instead of Mat1 and Mat2, but yet to confirm, obviously enough.

tomhrr commented 7 years ago

https://github.com/tomhrr/dale-linear-algebra/commit/1ab5fed15efca023f12f6583eab8006c57f3b38a has the second * instantiating, but not implemented. Attempting to dereference a and b within the previous macro calls was the immediate problem, with the error checking around that being insufficient. Using a macro where a numeric value was expected was causing some problems, too, but those are now fixed.

porky11 commented 7 years ago

nice, using macros for size even allows me to use my in-range macro