mech_interpreter/stdlib/assign/op_assign/
sub_assign.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#[macro_use]
use crate::stdlib::*;

// Sub Assign -----------------------------------------------------------------

// We will mostly use the assign macros for this

#[macro_export]
macro_rules! impl_sub_assign_match_arms {
  ($fxn_name:ident,$macro_name:ident, $arg:expr) => {
    paste!{
      //VVVVVVVVV right there is where the assign macros come in.
      [<impl_set_ $macro_name _match_arms>]!(
        $fxn_name,
        $arg,
        U8, "U8";
        U16, "U16";
        U32, "U32";
        U64, "U64";
        U128, "U128";
        I8, "I8";
        I16, "I16";
        I32, "I32";
        I64, "I64";
        U128, "U128";
        F32, "F32"; 
        F64, "F64" ;
      )
    }
  }
}

macro_rules! impl_sub_assign_fxn {
  ($struct_name:ident, $matrix_shape:ident, $source_matrix_shape:ty, $op:ident, $ix:ty) => {
    #[derive(Debug)]
    struct $struct_name<T> {
      source: Ref<$source_matrix_shape>,
      ixes: Ref<DVector<$ix>>,
      sink: Ref<$matrix_shape<T>>,
    }
    impl<T> MechFunction for $struct_name<T>
    where
      T: Copy + Debug + Clone + Sync + Send + 'static +
      Sub<Output = T> + SubAssign +
      Zero + One +
      PartialEq + PartialOrd,
      Ref<$matrix_shape<T>>: ToValue
    {
      fn solve(&self) {
        unsafe {
          let ix_ptr = (*(self.ixes.as_ptr())).clone();
          let mut sink_ptr = (&mut *(self.sink.as_ptr()));
          let source_ptr = (*(self.source.as_ptr())).clone();
          $op!(source_ptr,ix_ptr,sink_ptr);
        }
      }
      fn out(&self) -> Value { self.sink.to_value() }
      fn to_string(&self) -> String { format!("{:#?}", self) }
    }};}

// x = 1 ----------------------------------------------------------------------

#[derive(Debug)]
struct SubAssignVV<T> {
  sink: Ref<T>,
  source: Ref<T>,
}
impl<T> MechFunction for SubAssignVV<T> 
where
  T: Debug + Clone + Sync + Send + 'static +
  Sub<Output = T> + SubAssign +
  PartialEq + PartialOrd,
  Ref<T>: ToValue
{
  fn solve(&self) {
    let sink_ptr = self.sink.as_ptr();
    let source_ptr = self.source.as_ptr();
    unsafe {
      *sink_ptr -= (*source_ptr).clone();
    }
  }
  fn out(&self) -> Value { self.sink.to_value() }
  fn to_string(&self) -> String { format!("{:#?}", self) }
}

pub struct SubAssignValue {}
impl NativeFunctionCompiler for SubAssignValue {
  fn compile(&self, arguments: &Vec<Value>) -> MResult<Box<dyn MechFunction>> {
    if arguments.len() <= 1 {
      return Err(MechError{file: file!().to_string(), tokens: vec![], msg: "".to_string(), id: line!(), kind: MechErrorKind::IncorrectNumberOfArguments});
    }
    let sink = arguments[0].clone();
    let source = arguments[1].clone();
    match (sink,source) {
      (Value::U8(sink),Value::U8(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::U16(sink),Value::U16(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::U32(sink),Value::U32(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::U64(sink),Value::U64(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::U128(sink),Value::U128(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::I8(sink),Value::I8(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::I16(sink),Value::I16(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::I32(sink),Value::I32(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::I64(sink),Value::I64(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::I128(sink),Value::I128(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::F32(sink),Value::F32(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::F64(sink),Value::F64(source)) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Matrix1(sink)),Value::MatrixF64(Matrix::Matrix1(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Matrix2(sink)),Value::MatrixF64(Matrix::Matrix2(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Matrix2x3(sink)),Value::MatrixF64(Matrix::Matrix2x3(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Matrix3x2(sink)),Value::MatrixF64(Matrix::Matrix3x2(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Matrix3(sink)),Value::MatrixF64(Matrix::Matrix3(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Matrix4(sink)),Value::MatrixF64(Matrix::Matrix4(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::DMatrix(sink)),Value::MatrixF64(Matrix::DMatrix(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Vector2(sink)),Value::MatrixF64(Matrix::Vector2(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Vector3(sink)),Value::MatrixF64(Matrix::Vector3(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::Vector4(sink)),Value::MatrixF64(Matrix::Vector4(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::DVector(sink)),Value::MatrixF64(Matrix::DVector(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::RowVector2(sink)),Value::MatrixF64(Matrix::RowVector2(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::RowVector3(sink)),Value::MatrixF64(Matrix::RowVector3(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::RowVector4(sink)),Value::MatrixF64(Matrix::RowVector4(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      (Value::MatrixF64(Matrix::RowDVector(sink)),Value::MatrixF64(Matrix::RowDVector(source))) => Ok(Box::new(SubAssignVV{sink: sink.clone(), source: source.clone()})),
      x => Err(MechError{file: file!().to_string(),  tokens: vec![], msg: format!("{:?}",x), id: line!(), kind: MechErrorKind::UnhandledFunctionArgumentKind }),
    }
  }
}

// x[1..3] -= 1 ----------------------------------------------------------------

macro_rules! sub_assign_1d_range {
  ($source:expr, $ix:expr, $sink:expr) => {
    unsafe { 
      for i in 0..($ix).len() {
        ($sink)[($ix)[i] - 1] -= ($source);
      }
    }
  };}

macro_rules! sub_assign_1d_range_b {
  ($source:expr, $ix:expr, $sink:expr) => {
    unsafe { 
      for i in 0..($ix).len() {
        if $ix[i] == true {
          ($sink)[i] -= ($source);
        }
      }
    }
  };}  

macro_rules! sub_assign_1d_range_vec {
  ($source:expr, $ix:expr, $sink:expr) => {
    unsafe { 
      for i in 0..($ix).len() {
        ($sink)[($ix)[i] - 1] -= ($source)[i];
      }
    }
  };}

impl_sub_assign_fxn!(SubAssign1DRRD,RowDVector,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRVD,DVector,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRMD,DMatrix,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRR4,RowVector4,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRR3,RowVector3,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRR2,RowVector2,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRV4,Vector4,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRV3,Vector3,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRV2,Vector2,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRM4,Matrix4,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRM3,Matrix3,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRM2,Matrix2,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRM1,Matrix1,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRM2x3,Matrix2x3,T,sub_assign_1d_range,usize);
impl_sub_assign_fxn!(SubAssign1DRM3x2,Matrix3x2,T,sub_assign_1d_range,usize);

impl_sub_assign_fxn!(SubAssign1DRRDB,RowDVector,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRVDB,DVector,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRMDB,DMatrix,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRR4B,RowVector4,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRR3B,RowVector3,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRR2B,RowVector2,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRV4B,Vector4,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRV3B,Vector3,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRV2B,Vector2,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRM4B,Matrix4,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRM3B,Matrix3,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRM2B,Matrix2,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRM1B,Matrix1,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRM2x3B,Matrix2x3,T,sub_assign_1d_range_b,bool);
impl_sub_assign_fxn!(SubAssign1DRM3x2B,Matrix3x2,T,sub_assign_1d_range_b,bool);

impl_sub_assign_fxn!(SubAssign1DRR4R4,RowVector4,RowVector4<T>,sub_assign_1d_range_vec,usize);
impl_sub_assign_fxn!(SubAssign1DRR4R3,RowVector4,RowVector3<T>,sub_assign_1d_range_vec,usize);
impl_sub_assign_fxn!(SubAssign1DRR4R2,RowVector4,RowVector2<T>,sub_assign_1d_range_vec,usize);
impl_sub_assign_fxn!(SubAssign1DRV4V4,Vector4,Vector4<T>,sub_assign_1d_range_vec,usize);
impl_sub_assign_fxn!(SubAssign1DRV4V3,Vector4,Vector3<T>,sub_assign_1d_range_vec,usize);
impl_sub_assign_fxn!(SubAssign1DRV4V2,Vector4,Vector2<T>,sub_assign_1d_range_vec,usize);

impl_sub_assign_fxn!(SubAssign1DRMDMD,DMatrix,DMatrix<T>,sub_assign_1d_range_vec,usize);


fn sub_assign_range_fxn(sink: Value, source: Value, ixes: Vec<Value>) -> Result<Box<dyn MechFunction>, MechError> {
  impl_sub_assign_match_arms!(SubAssign1DR, range, (sink, ixes.as_slice(), source))
}

pub struct SubAssignRange {}
impl NativeFunctionCompiler for SubAssignRange {
  fn compile(&self, arguments: &Vec<Value>) -> MResult<Box<dyn MechFunction>> {
    if arguments.len() <= 1 {
      return Err(MechError{file: file!().to_string(), tokens: vec![], msg: "".to_string(), id: line!(), kind: MechErrorKind::IncorrectNumberOfArguments});
    }
    let sink: Value = arguments[0].clone();
    let source: Value = arguments[1].clone();
    let ixes = arguments.clone().split_off(2);
    match sub_assign_range_fxn(sink.clone(),source.clone(),ixes.clone()) {
      Ok(fxn) => Ok(fxn),
      Err(x) => {
        match (sink,ixes,source) {
          (Value::MutableReference(sink),ixes,Value::MutableReference(source)) => { sub_assign_range_fxn(sink.borrow().clone(),source.borrow().clone(),ixes.clone()) },
          (sink,ixes,Value::MutableReference(source)) => { sub_assign_range_fxn(sink.clone(),source.borrow().clone(),ixes.clone()) },
          (Value::MutableReference(sink),ixes,source) => { sub_assign_range_fxn(sink.borrow().clone(),source.clone(),ixes.clone()) },
          x => Err(MechError{file: file!().to_string(),  tokens: vec![], msg: format!("{:?}",x), id: line!(), kind: MechErrorKind::UnhandledFunctionArgumentKind }),
        }
      }
    }
  }
}

// x[1..3,:] -= 1 ------------------------------------------------------------------

macro_rules! sub_assign_2d_vector_all {
  ($source:expr, $ix:expr, $sink:expr) => {
      for cix in 0..($sink).ncols() {
        for rix in &$ix {
          ($sink).column_mut(cix)[rix - 1] -= ($source);
        }
      }
    };}

macro_rules! sub_assign_2d_vector_all_b {
  ($source:expr, $ix:expr, $sink:expr) => {
    for cix in 0..($sink).ncols() {
      for rix in 0..$ix.len() {
        if $ix[rix] == true {
          ($sink).column_mut(cix)[rix] -= ($source);
        }
      }
    }
  };} 


#[derive(Debug)]
struct SubAssign2DRAMDMD<T> {
  source: Ref<DMatrix<T>>,
  ixes: Ref<DVector<usize>>,
  sink: Ref<DMatrix<T>>,
}
impl<T> MechFunction for SubAssign2DRAMDMD<T>
where
  T: Copy + Debug + Clone + Sync + Send + 'static +
  Sub<Output = T> + SubAssign +
  Zero + One +
  PartialEq + PartialOrd,
  Ref<DMatrix<T>>: ToValue
{
  fn solve(&self) {
    unsafe {
      let ix_ptr = &(*(self.ixes.as_ptr()));
      let mut sink_ptr = (&mut *(self.sink.as_ptr()));
      let source_ptr = &(*(self.source.as_ptr()));
      for (i,rix) in (ix_ptr).iter().enumerate() {
        let mut row = sink_ptr.row_mut(rix - 1);
        row -= (source_ptr).row(i);
      }
    }
  }
  fn out(&self) -> Value { self.sink.to_value() }
  fn to_string(&self) -> String { format!("{:#?}", self) }
}


macro_rules! sub_assign_2d_vector_all_mat {
  ($source:expr, $ix:expr, $sink:expr) => {

  };}

macro_rules! sub_assign_2d_vector_all_mat_b {
  ($source:expr, $ix:expr, $sink:expr) => {
    for (i,rix) in (&$ix).iter().enumerate() {
      if *rix == true {
        let mut row = ($sink).row_mut(i);
        row -= ($source).row(i);
      }
    }
  };} 

impl_sub_assign_fxn!(SubAssign2DRAMD,DMatrix,T,sub_assign_2d_vector_all,usize);
impl_sub_assign_fxn!(SubAssign2DRAM4,Matrix4,T,sub_assign_2d_vector_all,usize);
impl_sub_assign_fxn!(SubAssign2DRAM3,Matrix3,T,sub_assign_2d_vector_all,usize);
impl_sub_assign_fxn!(SubAssign2DRAM2,Matrix2,T,sub_assign_2d_vector_all,usize);
impl_sub_assign_fxn!(SubAssign2DRAM1,Matrix1,T,sub_assign_2d_vector_all,usize);
impl_sub_assign_fxn!(SubAssign2DRAM2x3,Matrix2x3,T,sub_assign_2d_vector_all,usize);
impl_sub_assign_fxn!(SubAssign2DRAM3x2,Matrix3x2,T,sub_assign_2d_vector_all,usize);

//impl_sub_assign_fxn!(SubAssign2DRAMDMD,DMatrix,DMatrix<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAMDM2,DMatrix,Matrix2<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAMDM2x3,DMatrix,Matrix2x3<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAMDM3,DMatrix,Matrix3<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAMDM3x2,DMatrix,Matrix3x2<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAMDM4,DMatrix,Matrix4<T>,sub_assign_2d_vector_all_mat,usize);

impl_sub_assign_fxn!(SubAssign2DRAM2M2,Matrix2,Matrix2<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM2M3x2,Matrix2,Matrix3x2<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM2MD,Matrix2,DMatrix<T>,sub_assign_2d_vector_all_mat,usize);

impl_sub_assign_fxn!(SubAssign2DRAM3M3,Matrix3,Matrix3<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM3M2x3,Matrix3,Matrix2x3<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM3MD,Matrix3,DMatrix<T>,sub_assign_2d_vector_all_mat,usize);

impl_sub_assign_fxn!(SubAssign2DRAM3x2M3x2,Matrix3x2,Matrix3x2<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM3x2M2,Matrix3x2,Matrix2<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM3x2MD,Matrix3x2,DMatrix<T>,sub_assign_2d_vector_all_mat,usize);

impl_sub_assign_fxn!(SubAssign2DRAM2x3M2x3,Matrix2x3,Matrix2x3<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM2x3M3,Matrix2x3,Matrix3<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM2x3MD,Matrix2x3,DMatrix<T>,sub_assign_2d_vector_all_mat,usize);

impl_sub_assign_fxn!(SubAssign2DRAM4M4,Matrix4,Matrix4<T>,sub_assign_2d_vector_all_mat,usize);
impl_sub_assign_fxn!(SubAssign2DRAM4MD,Matrix4,DMatrix<T>,sub_assign_2d_vector_all_mat,usize);

impl_sub_assign_fxn!(SubAssign2DRAMDB,DMatrix,T,sub_assign_2d_vector_all_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM4B,Matrix4,T,sub_assign_2d_vector_all_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM3B,Matrix3,T,sub_assign_2d_vector_all_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM2B,Matrix2,T,sub_assign_2d_vector_all_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM1B,Matrix1,T,sub_assign_2d_vector_all_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM2x3B,Matrix2x3,T,sub_assign_2d_vector_all_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM3x2B,Matrix3x2,T,sub_assign_2d_vector_all_b,bool);

impl_sub_assign_fxn!(SubAssign2DRAMDMDB,DMatrix,DMatrix<T>,sub_assign_2d_vector_all_mat_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM2M2B,Matrix2,Matrix2<T>,sub_assign_2d_vector_all_mat_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM3M3B,Matrix3,Matrix3<T>,sub_assign_2d_vector_all_mat_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM4M4B,Matrix4,Matrix4<T>,sub_assign_2d_vector_all_mat_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM3x2M3x2B,Matrix3x2,Matrix3x2<T>,sub_assign_2d_vector_all_mat_b,bool);
impl_sub_assign_fxn!(SubAssign2DRAM2x3M2x3B,Matrix2x3,Matrix2x3<T>,sub_assign_2d_vector_all_mat_b,bool);

fn sub_assign_vec_all_fxn(sink: Value, source: Value, ixes: Vec<Value>) -> Result<Box<dyn MechFunction>, MechError> {
  impl_sub_assign_match_arms!(SubAssign2DRA, range_all, (sink, ixes.as_slice(), source))
}

pub struct SubAssignRangeAll {}
impl NativeFunctionCompiler for SubAssignRangeAll {
  fn compile(&self, arguments: &Vec<Value>) -> MResult<Box<dyn MechFunction>> {
    if arguments.len() <= 1 {
      return Err(MechError{file: file!().to_string(), tokens: vec![], msg: "".to_string(), id: line!(), kind: MechErrorKind::IncorrectNumberOfArguments});
    }
    let sink: Value = arguments[0].clone();
    let source: Value = arguments[1].clone();
    let ixes = arguments.clone().split_off(2);
    match sub_assign_vec_all_fxn(sink.clone(),source.clone(),ixes.clone()) {
      Ok(fxn) => Ok(fxn),
      Err(_) => {
        match (sink,ixes,source) {
          (Value::MutableReference(sink),ixes,Value::MutableReference(source)) => { sub_assign_vec_all_fxn(sink.borrow().clone(),source.borrow().clone(),ixes.clone()) },
          (sink,ixes,Value::MutableReference(source)) => { sub_assign_vec_all_fxn(sink.clone(),source.borrow().clone(),ixes.clone()) },
          (Value::MutableReference(sink),ixes,source) => { sub_assign_vec_all_fxn(sink.borrow().clone(),source.clone(),ixes.clone()) },
          x => Err(MechError{file: file!().to_string(),  tokens: vec![], msg: format!("{:?}",x), id: line!(), kind: MechErrorKind::UnhandledFunctionArgumentKind }),
        }
      }
    }
  }
}