Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Linalg 4 - Added trait bounded generics as example (not hacspec compliant!) #275

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

rasmus-kirk
Copy link
Contributor

Generalized the linear algebra library using trait bounded generics. This should be seen as an example of how traits could eventually be used in hacspec. Feel free to comment/review.

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look too bad. See inline comments.

type DimType = usize;
type Dims = (DimType, DimType);
type MatRes<T> = Result<Matrix<T>, u8>;
type ScalRes<T> = Result<T, u8>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the type of generics we would need a lot.

type MatRes<T> = Result<Matrix<T>, u8>;
type ScalRes<T> = Result<T, u8>;

pub type Matrix<T> = (Dims, Seq<T>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could restrict T here for the translation.

/// Generate a n*m matrix filled with a given scalar.
pub fn repeat<T>(n: DimType, m: DimType, scalar: T) -> Matrix<T>
where
T: hacspec_lib::Integer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we need this here. But it would be nice if we could get away without where clauses.
The question is what is the easiest and tightest bound we could put on T in general here.

@franziskuskiefer franziskuskiefer added the blocked Status: marked as blocked on something else. label Oct 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked Status: marked as blocked on something else.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants