-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add linear map semantics and safe transformations #9
base: master
Are you sure you want to change the base?
Conversation
Thanks for this Andrey 😄 As I said in my email, it would be very nice if a version of |
@bolt12 I think we can implement As for |
They are indeed relations I decided to use 1 and 0's because I could work with other quantitative matrices. I also have a This seems promising! There must be a cool way to work with arbitrary generic types! |
Ah, indeed, got it!
Good, hope you'll manage to make it work :) |
The way I see it work with your implementation is to use Generics to create a deconstructor similar to |
I think I was able to do it! toNorm :: (Enum a, Enum (Normalize a)) => a -> Normalize a
toNorm = toEnum . fromEnum
fromNorm :: (Enum a, Enum (Normalize a)) =>Normalize a -> a
fromNorm = toEnum . fromEnum There's no need for the type-class anymore I think! Since |
@bolt12 Awesome! Could you show the full code? |
@snowleopard sure! type ConstructNorm a = (Enum a, Enum (Normalize a))
toNorm :: ConstructNorm a => a -> Normalize a
toNorm = toEnum . fromEnum
fromNorm :: ConstructNorm a => Normalize a -> a
fromNorm = toEnum . fromEnum
rowN :: (Construct (Normalize a), ConstructNorm a, Num e) => Vector e a -> Matrix e (Normalize a) ()
rowN = row' . contramap fromNorm
linearMapN :: (Construct (Normalize a), Construct (Normalize b), ConstructNorm a, ConstructNorm b, Num e)
=> LinearMap e a b -> Matrix e (Normalize a) (Normalize b)
linearMapN = linearMap . dimap (contramap toNorm) (contramap fromNorm)
columnN :: (Construct (Normalize a), ConstructNorm a, Num e) => Vector e a -> Matrix e () (Normalize a)
columnN = tr . rowN
functionN :: (Construct (Normalize a), Construct (Normalize b), ConstructNorm a, ConstructNorm b, Enumerable a, Num e)
=> (a -> b -> e) -> Matrix e (Normalize a) (Normalize b)
functionN f = linearMapN $ \v -> Vector $ \b -> dot v $ Vector $ \a -> f a b Everything is the same as your code but without the type class. What do you think? Thank you once again for all your help! 😄 |
@bolt12 Thanks but I meant the full code, including the implementation of various other key functions like |
I'm still working on the refactoring! I hope to open a PR soon with all the changes! |
@snowleopard please see #11 for the full code! I think we are getting there 😄 the |
@bolt12 This replaces my previous PR #7. You don't have to merge it -- it's just an illustration of how the ideas from my experiment can be translated to your data type.