In this example, I repeat na::SVector<f64, NumStates>
a bunch, can I define a type
type StateVector = na::SVector<f64, NumStates>;
like this? I get an error that associated type defaults are unstable
. Is there another way?
use nalgebra as na;
pub trait Cost<const NumStates: usize, const NumControls: usize> {
fn stage_cost(&self, x: &na::SVector<f64, NumStates>, u: &na::SVector<f64, NumControls>)
-> f64;
fn stage_grad(
&self,
x: &na::SVector<f64, NumStates>,
u: &na::SVector<f64, NumControls>,
grad_x: &mut na::SVector<f64, NumStates>,
grad_u: &mut na::SVector<f64, NumControls>,
);
fn terminal_cost(&self, x: &na::SVector<f64, NumStates>) -> f64;
fn terminal_grad(
&self,
x: &na::SVector<f64, NumStates>,
grad: &mut na::SVector<f64, NumStates>,
);
}
As a commenter points out, position matters. I suspect your codeblock creating the error looks like this:
This creates an associated type which cannot have a default type on stable.
Define your type alias outside of the
trait
body and you've solved your problem: