Skip to content
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 reshape function #55

Closed
Tracked by #127
coreylowman opened this issue Jun 22, 2022 · 2 comments · Fixed by #90
Closed
Tracked by #127

Add reshape function #55

coreylowman opened this issue Jun 22, 2022 · 2 comments · Fixed by #90
Labels

Comments

@coreylowman
Copy link
Owner

This would only work for two tensors with the same number of elements. This can be used for #34

@coreylowman
Copy link
Owner Author

coreylowman commented Jun 22, 2022

First working version in 1215ed5. Note that this requires nightly because a type Flat = [(); M * T::NUM_ELEMENTS] was added for arrays that allows you to check that two arrays have the same ::Flat.

@coreylowman coreylowman mentioned this issue Jun 25, 2022
@coreylowman
Copy link
Owner Author

Another approach that is slightly more readable and self contained (but still requires #![feature(generic_const_exprs)]):

struct True;

trait ConstAssert {
    type Result;
}

struct ConstEq<const A: usize, const B: usize>;

impl<const A: usize> ConstAssert for ConstEq<A, A> {
    type Result = True;
}

fn copy<Lhs: Count, Rhs: Count>(lhs: &Lhs, rhs: &mut Rhs)
where
    ConstEq<{ Lhs::NUM_ELEMENTS }, { Rhs::NUM_ELEMENTS }>: ConstAssert<Result = True>,
{
    let l = lhs.ref_first() as *const f32;
    let r = rhs.mut_first() as *mut f32;
    unsafe {
        std::ptr::copy_nonoverlapping(l, r, Lhs::NUM_ELEMENTS);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant