Questions tagged [haskell-linear]

Questions about linear, a Haskell library for linear algebra.

7 questions
7
votes
1 answer

How do I use variable size vectors in Edward Kmett's "Linear" library?

I'm trying to use ekmett's linear library, and I'm having some trouble with variable length vectors, in Linear.V. How do I use the dim function to get the size of a vector? How do I use trace on a large square matrix made of nested Vs ? I get errors…
Christian Oudard
  • 48,140
  • 25
  • 66
  • 69
5
votes
1 answer

How to derive Additive generically on Haskell, without defining an Applicative instance?

Given a type, there is only one obvious way to implement an Additive instance, from the Linear library, to it. Conveniently, Additive has a generic implementation, so we can use deriving for it. Unfortunately, it depends on the existence of an…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
5
votes
1 answer

How do you scale a vector using the Haskell library, Linear?

This is a simple question about style. I've been using: import Linear point = V3 1 2 3 scaled = fmap (* 2) point Or... scaled = (* 2) <$> point Is this the intended way, or is there a proper multiplication by scalar operator?
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
3
votes
1 answer

"Linear" package truncating values close to 0 when using `normalize`

I've spent a few minutes debugging a problem that tracked down to "Linear" truncating values that are close to zero when using "Linear.normalize". Specifically, I was taking the cross product of very small triangles and normalizing the result,…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
3
votes
0 answers

Optimizing this haskell linear algebra code

I have this Haskell code for testing collisions between shapes (it depends on the linear and lens packages) import Linear hiding (trace) import Control.Lens.Getter ((^.)) type Vec3 = V3 Float data Tri = Tri Vec3 Vec3 Vec3 data Box = Box Vec3…
Dan
  • 12,409
  • 3
  • 50
  • 87
2
votes
0 answers

Haskell Linear + AD, implementing Metric for Forward?

I'm trying to use diff from the ad package on a function Quaternion a -> Quaternion a or more generally Metric a => a -> a relying on quadrance. I'm not sure what the best way to go about this is, since Forward doesn't have a Metric instance and…
0
votes
1 answer

Haskell code won't compile with certain variable names

I'm getting an error from GHCi that I can't explain. I'm working with the following code (the vast majority of which is seemingly-irrelevant to the issue, but I can't replicate the issue with less code; commented-out lines are ones that I would like…
zjs
  • 327
  • 1
  • 9