-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Remove copy requirement from Scalar trait #491
Conversation
Thank you for to addressing this! Here are some remarks:
Do you mean all the existing methods taking a |
To say a little more about the performance implications: This: use std::ops::Add;
pub fn add<N>(a: &N, b: &N) -> <N as Add<N>>::Output
where
N: Add + Clone
{
a.clone() + b.clone()
}
pub fn test(a: i32, b: i32) -> i32 {
add(&a, &b)
} ...compiles to this: <i32 as core::ops::arith::Add>::add:
lea eax, [rdi + rsi]
ret
core::clone::impls::<impl core::clone::Clone for i32>::clone:
mov eax, dword ptr [rdi]
ret
example::add:
push rbp
push rbx
push rax
mov rbx, rsi
call core::clone::impls::<impl core::clone::Clone for i32>::clone
mov ebp, eax
mov rdi, rbx
call core::clone::impls::<impl core::clone::Clone for i32>::clone
mov edi, ebp
mov esi, eax
add rsp, 8
pop rbx
pop rbp
jmp <i32 as core::ops::arith::Add>::add
example::test:
push rax
mov dword ptr [rsp], edi
mov dword ptr [rsp + 4], esi
mov rdi, rsp
lea rsi, [rsp + 4]
call qword ptr [rip + example::add@GOTPCREL]
pop rcx
ret At the very least, this seems like it may significantly increase the number of emitted instructions. |
So first, there will be no breaking change, the methods that currently exist will stay. I'll probably just create new methods with different names.
And of course I'll fix glm and lapack. |
Cargo's debug/development profile uses |
While working on this PR, I found that there is a type called real in alga that is Copy. I've made a PR dimforge/alga#56 which adds a variant of Real called CloneReal, which allows non-copy types to implement it. |
Hi, |
Fixes #282.
This is the first of two parts, if you accept the PR, I'll work on accepting references for functions/methods that have a scalar as a parameter.
There are two macros I defined,
c
, ando
. runningc!(x)
doesx.clone()
, ando!(x)
doesx.to_owned()
. These make the source code quite a bit more clean than writingclone
andto_owned
out every time.