Small vector and matrix proposed for phobos2 now on github

Robert Jacques sandford at jhu.edu
Mon Apr 26 07:44:41 PDT 2010


On Mon, 26 Apr 2010 03:46:47 -0300, Gareth Charnock <gareth.tpc at gmail.com>  
wrote:

> Thanks. To quickly answer this:
>
>  > - The version I'm seeing on github doesn't seem to have all the  
> features
>  > you're referencing (i.e. v*v). Why are some ops limited to */ and  
> other +-?
>
> It was quite late (3am) when I typed up that email. I'm sorry if I got  
> the ops wrong. v*v was actually rejected in favour of dot(v,v). Unless  
> I've made another mistake the implemented operators are:
>
> v*s    v/s    v*=s
> v/=s   v+v    v-v
> v+=v   v-=v   m+m
> m-m    m*m    m*v
>
> (where v is a vector, m a matrix, s a scalar)
>
> The reason the feature set is very limited is I wanted to get feedback  
> before implementing a large set of features and then having to change  
> things. The idea was to implement just enough so that it would be clear  
> where I was going. For example, I wasn't aware that compile time foreach  
> was a bad way to unroll loops (perhaps I should build a mixin string?).

- Element wise *, etc are important operators that you need to cleanly  
support. Design-wise, since we can't do Matlab style operators, I prefer  
*/+- to be element wise, and then use dot/cross/solve for matrix ops. This  
seems to avoid the confusion of as having some ops be matrix style and  
some ops be array style. Since D is unicode, you could also add the real  
inner product operator as an alias. Also, don't forget the outer product,  
aka broadcasting, i.e. v.dot(v.T).
- static foreach seems to add some overhead, although I don't know why.  
What you should really do is write some benchmarks and test static  
foreach, array ops and hand-unrolling for several vector sizes.


More information about the Digitalmars-d-announce mailing list