nncombinator 0.9.0

A library of neural networks that can be written type-safely
Documentation
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//! This module is related to the cuda implementation of the activation function

use std::marker::PhantomData;
use libc::{c_void, size_t};
use crate::cuda::{AsKernelPtr, CudaConstPtr, CudaTensor1dPtr, CudaTensor1dPtrView, CudaVec, CudaVecView, DataTypeInfo, Kernel, KernelArgs};
use crate::ope::UnitValue;

extern "C" {
    fn sigmoid_forward_float(input: *const f32, output: *mut f32, len: size_t, units_len: size_t) -> c_void;
    fn relu_forward_float(input: *const f32, output: *mut f32, len: size_t, units_len: size_t) -> c_void;
    fn swish_forward_float(input: *const f32, output: *mut f32, len: size_t, units_len: size_t) -> c_void;
    fn tanh_forward_float(input: *const f32, output: *mut f32, len: size_t, units_len: size_t) -> c_void;
    fn softmax_forward_float(input: *const f32, output: *mut f32, len: size_t, batch_size: size_t) -> c_void;
    fn sigmoid_backward_float(o: *const f32, u: *const f32, loss: *const f32, output: *mut f32, units_len: size_t, batch_size: size_t) -> c_void;
    fn relu_backward_float(o: *const f32, u: *const f32, loss: *const f32, output: *mut f32, units_len: size_t, batch_size: size_t) -> c_void;
    fn swish_backward_float(o: *const f32, u: *const f32, loss: *const f32, output: *mut f32, units_len: size_t, batch_size: size_t) -> c_void;
    fn tanh_backward_float(o: *const f32, u: *const f32, loss: *const f32, output: *mut f32, units_len: size_t, batch_size: size_t) -> c_void;
    fn softmax_backward_float(o: *const f32, u: *const f32, loss: *const f32, output: *mut f32, units_len: size_t, batch_size: size_t) -> c_void;
    fn sigmoid_forward_double(input: *const f64, output: *mut f64, len: size_t, units_len: size_t) -> c_void;
    fn relu_forward_double(input: *const f64, output: *mut f64, len: size_t, units_len: size_t) -> c_void;
    fn swish_forward_double(input: *const f64, output: *mut f64, len: size_t, units_len: size_t) -> c_void;
    fn tanh_forward_double(input: *const f64, output: *mut f64, len: size_t, units_len: size_t) -> c_void;
    fn softmax_forward_double(input: *const f64, output: *mut f64, len: size_t, batch_size: size_t) -> c_void;
    fn sigmoid_backward_double(o: *const f64, u: *const f64, loss: *const f64, output: *mut f64, units_len: size_t, batch_size: size_t) -> c_void;
    fn relu_backward_double(o: *const f64, u: *const f64, loss: *const f64, output: *mut f64, units_len: size_t, batch_size: size_t) -> c_void;
    fn swish_backward_double(o: *const f64, u: *const f64, loss: *const f64, output: *mut f64, units_len: size_t, batch_size: size_t) -> c_void;
    fn tanh_backward_double(o: *const f64, u: *const f64, loss: *const f64, output: *mut f64, units_len: size_t, batch_size: size_t) -> c_void;
    fn softmax_backward_double(o: *const f64, u: *const f64, loss: *const f64, output: *mut f64, units_len: size_t, batch_size: size_t) -> c_void;
}
/// Defines the list of passed to the cuda kernel function for the arguments of the activation function.
pub struct ActivationForwardArgs<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    input: CudaConstPtr<'a,CudaTensor1dPtrView<'a,T,N>>,
    /// Output buffer
    pub output: CudaTensor1dPtr<T,N>,
    units_len: usize,
    batch_size: usize,
}
/// Create an instance of an object representing the argument list at the time of activation function forward.
impl<'a,T,const N:usize> ActivationForwardArgs<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ActivationForwardArgs instance
    /// # Arguments
    /// * `input` - Input buffer
    /// * `output` - Output buffer
    pub fn new(input:&'a CudaTensor1dPtrView<'a,T,N>,output:CudaTensor1dPtr<T,N>) -> ActivationForwardArgs<'a,T,N> {
        ActivationForwardArgs {
            input: CudaConstPtr::new(input),
            output: output,
            units_len: N,
            batch_size: 1
        }
    }
}
impl<'a,T,const N:usize> KernelArgs for ActivationForwardArgs<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    fn as_vec(&mut self) -> Vec<&mut dyn AsKernelPtr> {
        vec![
            &mut self.input,
            &mut self.output,
            &mut self.units_len,
            &mut self.batch_size
        ]
    }
}
/// Create an instance of an object representing the argument list during error back propagation of the activation function.
pub struct ActivationBackwardArgs<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    o: CudaConstPtr<'a,CudaTensor1dPtrView<'a,T,N>>,
    u: CudaConstPtr<'a,CudaTensor1dPtrView<'a,T,N>>,
    loss: CudaConstPtr<'a,CudaTensor1dPtrView<'a,T,N>>,
    /// Output of error back propagation
    pub output: CudaTensor1dPtr<T,N>,
    units_len: usize,
    batch_size: usize,
}
/// Create an instance of an object representing the list of arguments during error back propagation of the activation function.
impl<'a,T,const N:usize> ActivationBackwardArgs<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ActivationBackwardArgs instance
    /// # Arguments
    /// * `o` - Output values
    /// * `u` - Input values from upper layers
    /// * `loss` - loss value
    /// * `output` - Output of error back propagation
    pub fn new(o: &'a CudaTensor1dPtrView<'a,T,N>,
               u: &'a CudaTensor1dPtrView<'a,T,N>,
               loss: &'a CudaTensor1dPtrView<'a,T,N>,
               output: CudaTensor1dPtr<T,N>) -> ActivationBackwardArgs<'a,T,N> {
        ActivationBackwardArgs {
            o: CudaConstPtr::new(o),
            u: CudaConstPtr::new(u),
            loss: CudaConstPtr::new(loss),
            output: output,
            units_len: N,
            batch_size: 1
        }
    }
}
impl<'a,T,const N:usize> KernelArgs for ActivationBackwardArgs<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    fn as_vec(&mut self) -> Vec<&mut dyn AsKernelPtr> {
        vec![
            &mut self.o,
            &mut self.u,
            &mut self.loss,
            &mut self.output,
            &mut self.units_len,
            &mut self.batch_size
        ]
    }
}
/// Defines the list of arguments passed to the cuda kernel function as arguments
/// to the activation function during batch execution.
pub struct ActivationBatchForwardArgs<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    input: CudaConstPtr<'a,CudaVecView<'a,T,CudaTensor1dPtr<T,N>>>,
    /// Output buffer
    pub output: CudaVec<T,CudaTensor1dPtr<T,N>>,
    units_len: usize,
    batch_size: usize,
}
/// Create an instance of an object representing the argument list
/// of the forward propagation of the activation function during batch execution.
impl<'a,T,const N:usize> ActivationBatchForwardArgs<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ActivationBatchForwardArgs instance
    /// # Arguments
    /// * `input` - Input buffer
    /// * `output` - Output buffer
    /// * `batch_size` - batches count
    pub fn new(input:&'a CudaVecView<'a,T,CudaTensor1dPtr<T,N>>,output:CudaVec<T,CudaTensor1dPtr<T,N>>, batch_size: usize)
        -> ActivationBatchForwardArgs<'a,T,N> {
        ActivationBatchForwardArgs {
            input: CudaConstPtr::new(input),
            output: output,
            units_len: N,
            batch_size: batch_size
        }
    }
}
impl<'a,T,const N:usize> KernelArgs for ActivationBatchForwardArgs<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    fn as_vec(&mut self) -> Vec<&mut dyn AsKernelPtr> {
        vec![
            &mut self.input,
            &mut self.output,
            &mut self.units_len,
            &mut self.batch_size
        ]
    }
}
/// Create an instance of an object representing the list of arguments during error back propagation
/// of the activation function during batch execution.
pub struct ActivationBatchBackwardArgs<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    o: CudaConstPtr<'a,CudaVecView<'a,T,CudaTensor1dPtr<T,N>>>,
    u: CudaConstPtr<'a,CudaVecView<'a,T,CudaTensor1dPtr<T,N>>>,
    loss: CudaConstPtr<'a,CudaVecView<'a,T,CudaTensor1dPtr<T,N>>>,
    /// Output of error back propagation
    pub output: CudaVec<T,CudaTensor1dPtr<T,N>>,
    units_len: usize,
    batch_size: usize,
}
/// Instantiate an object representing the list of arguments during error back propagation
/// of the activation function during batch execution.
impl<'a,T,const N:usize> ActivationBatchBackwardArgs<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ActivationBatchBackwardArgs instance
    /// # Arguments
    /// * `o` - Output values
    /// * `u` - Input values from upper layers
    /// * `loss` - loss value
    /// * `output` - Output of error back propagation
    /// * `batch_size` - batch count
    pub fn new(o: &'a CudaVecView<'a,T,CudaTensor1dPtr<T,N>>,
               u: &'a CudaVecView<'a,T,CudaTensor1dPtr<T,N>>,
               loss: &'a CudaVecView<'a,T,CudaTensor1dPtr<T,N>>,
               output: CudaVec<T,CudaTensor1dPtr<T,N>>,batch_size: usize) -> ActivationBatchBackwardArgs<'a, T, N> {
        ActivationBatchBackwardArgs {
            o: CudaConstPtr::new(o),
            u: CudaConstPtr::new(u),
            loss: CudaConstPtr::new(loss),
            output: output,
            units_len: N,
            batch_size: batch_size
        }
    }
}
impl<'a,T,const N:usize> KernelArgs for ActivationBatchBackwardArgs<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    fn as_vec(&mut self) -> Vec<&mut dyn AsKernelPtr> {
        vec![
            &mut self.o,
            &mut self.u,
            &mut self.loss,
            &mut self.output,
            &mut self.units_len,
            &mut self.batch_size
        ]
    }
}
/// Sigmoid activation function implementation
pub struct SigmoidForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SigmoidForward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SigmoidForward instance
    pub fn new() -> SigmoidForward<'a,T,N> {
        SigmoidForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SigmoidForward<'a,f32,N> {
    const FUNC_PTR: *const c_void = sigmoid_forward_float as *const c_void;
    type Args = ActivationForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SigmoidForward<'a,f64,N> {
    const FUNC_PTR: *const c_void = sigmoid_forward_double as *const c_void;
    type Args = ActivationForwardArgs<'a,f64,N>;
}
/// Implementation of derivatives of the sigmoid activation function
pub struct SigmoidBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SigmoidBackward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SigmoidBackward instance
    pub fn new() -> SigmoidBackward<'a,T,N> {
        SigmoidBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SigmoidBackward<'a,f32,N> {
    const FUNC_PTR: *const c_void = sigmoid_backward_float as *const c_void;
    type Args = ActivationBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SigmoidBackward<'a,f64,N> {
    const FUNC_PTR: *const c_void = sigmoid_backward_double as *const c_void;
    type Args = ActivationBackwardArgs<'a,f64,N>;
}
/// Implementation of sigmoid activation functions for batch execution
pub struct SigmoidBatchForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SigmoidBatchForward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SigmoidForwardForBatch instance
    pub fn new() -> SigmoidBatchForward<'a, T, N> {
        SigmoidBatchForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SigmoidBatchForward<'a, f32, N> {
    const FUNC_PTR: *const c_void = sigmoid_forward_float as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SigmoidBatchForward<'a, f64, N> {
    const FUNC_PTR: *const c_void = sigmoid_forward_double as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f64,N>;
}
/// Implement derivatives of the sigmoid activation function for batch execution
pub struct SigmoidBatchBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SigmoidBatchBackward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SigmoidBackwardForBatch instance
    pub fn new() -> SigmoidBatchBackward<'a, T, N> {
        SigmoidBatchBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SigmoidBatchBackward<'a, f32, N> {
    const FUNC_PTR: *const c_void = sigmoid_backward_float as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SigmoidBatchBackward<'a, f64, N> {
    const FUNC_PTR: *const c_void = sigmoid_backward_double as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f64,N>;
}
/// ReLu activation function implementation activation function implementation
pub struct ReLuForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> ReLuForward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ReLuForward instance
    pub fn new() -> ReLuForward<'a,T,N> {
        ReLuForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for ReLuForward<'a,f32,N> {
    const FUNC_PTR: *const c_void = relu_forward_float as *const c_void;
    type Args = ActivationForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for ReLuForward<'a,f64,N> {
    const FUNC_PTR: *const c_void = relu_forward_double as *const c_void;
    type Args = ActivationForwardArgs<'a,f64,N>;
}
/// Implementation of derivatives of the ReLu activation function
pub struct ReLuBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> ReLuBackward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ReLuBackward instance
    pub fn new() -> ReLuBackward<'a,T,N> {
        ReLuBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for ReLuBackward<'a,f32,N> {
    const FUNC_PTR: *const c_void = relu_backward_float as *const c_void;
    type Args = ActivationBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for ReLuBackward<'a,f64,N> {
    const FUNC_PTR: *const c_void = relu_backward_double as *const c_void;
    type Args = ActivationBackwardArgs<'a,f64,N>;
}
/// Implementation of ReLu activation functions for batch execution
pub struct ReLuBatchForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> ReLuBatchForward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ReLuForwardBatch instance
    pub fn new() -> ReLuBatchForward<'a, T, N> {
        ReLuBatchForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for ReLuBatchForward<'a, f32, N> {
    const FUNC_PTR: *const c_void = relu_forward_float as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for ReLuBatchForward<'a, f64, N> {
    const FUNC_PTR: *const c_void = relu_forward_double as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f64,N>;
}
/// Implement derivatives of the ReLu activation function for batch execution
pub struct ReLuBatchBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> ReLuBatchBackward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a ReLuBackwardForBatch instance
    pub fn new() -> ReLuBatchBackward<'a, T, N> {
        ReLuBatchBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for ReLuBatchBackward<'a, f32, N> {
    const FUNC_PTR: *const c_void = relu_backward_float as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for ReLuBatchBackward<'a, f64, N> {
    const FUNC_PTR: *const c_void = relu_backward_double as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f64,N>;
}
/// Swish activation function implementation
pub struct SwishForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SwishForward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SwishForward instance
    pub fn new() -> SwishForward<'a,T,N> {
        SwishForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SwishForward<'a,f32,N> {
    const FUNC_PTR: *const c_void = swish_forward_float as *const c_void;
    type Args = ActivationForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SwishForward<'a,f64,N> {
    const FUNC_PTR: *const c_void = swish_forward_double as *const c_void;
    type Args = ActivationForwardArgs<'a,f64,N>;
}
/// Implementation of derivatives of the Swish activation function
pub struct SwishBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SwishBackward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SwishBackward instance
    pub fn new() -> SwishBackward<'a,T,N> {
        SwishBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SwishBackward<'a,f32,N> {
    const FUNC_PTR: *const c_void = swish_backward_float as *const c_void;
    type Args = ActivationBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SwishBackward<'a,f64,N> {
    const FUNC_PTR: *const c_void = swish_backward_double as *const c_void;
    type Args = ActivationBackwardArgs<'a,f64,N>;
}
/// Implementation of Swish activation functions for batch execution
pub struct SwishBatchForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SwishBatchForward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SwishForwardForBatch instance
    pub fn new() -> SwishBatchForward<'a, T, N> {
        SwishBatchForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SwishBatchForward<'a, f32, N> {
    const FUNC_PTR: *const c_void = swish_forward_float as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SwishBatchForward<'a, f64, N> {
    const FUNC_PTR: *const c_void = swish_forward_double as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f64,N>;
}
/// Implement derivatives of the Swish activation function for batch execution
pub struct SwishBatchBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SwishBatchBackward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SwishBackwardForBatch instance
    pub fn new() -> SwishBatchBackward<'a, T, N> {
        SwishBatchBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SwishBatchBackward<'a, f32, N> {
    const FUNC_PTR: *const c_void = swish_backward_float as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SwishBatchBackward<'a, f64, N> {
    const FUNC_PTR: *const c_void = swish_backward_double as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f64,N>;
}
/// Tanh activation function implementation
pub struct TanhForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> TanhForward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a TanhForward instance
    pub fn new() -> TanhForward<'a,T,N> {
        TanhForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for TanhForward<'a,f32,N> {
    const FUNC_PTR: *const c_void = tanh_forward_float as *const c_void;
    type Args = ActivationForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for TanhForward<'a,f64,N> {
    const FUNC_PTR: *const c_void = tanh_forward_double as *const c_void;
    type Args = ActivationForwardArgs<'a,f64,N>;
}
/// Implementation of derivatives of the Tanh activation function
pub struct TanhBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> TanhBackward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a TanhBackward instance
    pub fn new() -> TanhBackward<'a,T,N> {
        TanhBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for TanhBackward<'a,f32,N> {
    const FUNC_PTR: *const c_void = tanh_backward_float as *const c_void;
    type Args = ActivationBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for TanhBackward<'a,f64,N> {
    const FUNC_PTR: *const c_void = tanh_backward_double as *const c_void;
    type Args = ActivationBackwardArgs<'a,f64,N>;
}
/// Implementation of Tanh activation functions for batch execution
pub struct TanhBatchForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> TanhBatchForward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a TanhForwardForBatch instance
    pub fn new() -> TanhBatchForward<'a, T, N> {
        TanhBatchForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for TanhBatchForward<'a, f32, N> {
    const FUNC_PTR: *const c_void = tanh_forward_float as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for TanhBatchForward<'a, f64, N> {
    const FUNC_PTR: *const c_void = tanh_forward_double as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f64,N>;
}
/// Implement derivatives of the Tanh activation function for batch execution
pub struct TanhBatchBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> TanhBatchBackward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a TanhBackwardForBatch instance
    pub fn new() -> TanhBatchBackward<'a, T, N> {
        TanhBatchBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for TanhBatchBackward<'a, f32, N> {
    const FUNC_PTR: *const c_void = tanh_backward_float as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for TanhBatchBackward<'a, f64, N> {
    const FUNC_PTR: *const c_void = tanh_backward_double as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f64,N>;
}
/// SoftMax activation function implementation
pub struct SoftMaxForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SoftMaxForward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SoftMaxForward instance
    pub fn new() -> SoftMaxForward<'a,T,N> {
        SoftMaxForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SoftMaxForward<'a,f32,N> {
    const FUNC_PTR: *const c_void = softmax_forward_float as *const c_void;
    type Args = ActivationForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SoftMaxForward<'a,f64,N> {
    const FUNC_PTR: *const c_void = softmax_forward_double as *const c_void;
    type Args = ActivationForwardArgs<'a,f64,N>;
}
/// Implementation of derivatives of the softmax activation function
pub struct SoftMaxBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SoftMaxBackward<'a,T,N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SoftMaxForward instance
    pub fn new() -> SoftMaxBackward<'a,T,N> {
        SoftMaxBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SoftMaxBackward<'a,f32,N> {
    const FUNC_PTR: *const c_void = softmax_backward_float as *const c_void;
    type Args = ActivationBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SoftMaxBackward<'a,f64,N> {
    const FUNC_PTR: *const c_void = softmax_backward_double as *const c_void;
    type Args = ActivationBackwardArgs<'a,f64,N>;
}
/// Implementation of Softmax activation functions for batch execution
pub struct SoftMaxBatchForward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SoftMaxBatchForward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SoftMaxForwardForBatch instance
    pub fn new() -> SoftMaxBatchForward<'a, T, N> {
        SoftMaxBatchForward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SoftMaxBatchForward<'a, f32, N> {
    const FUNC_PTR: *const c_void = softmax_forward_float as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SoftMaxBatchForward<'a, f64, N> {
    const FUNC_PTR: *const c_void = softmax_forward_double as *const c_void;
    type Args = ActivationBatchForwardArgs<'a,f64,N>;
}
/// Implement derivatives of the Softmax activation function for batch execution
pub struct SoftMaxBatchBackward<'a,T,const N:usize> where T: DataTypeInfo + UnitValue<T> {
    t:PhantomData<T>,
    l:PhantomData<&'a ()>
}
impl<'a,T,const N:usize> SoftMaxBatchBackward<'a, T, N> where T: DataTypeInfo + UnitValue<T> {
    /// Create a SoftMaxForwardForBatch instance
    pub fn new() -> SoftMaxBatchBackward<'a, T, N> {
        SoftMaxBatchBackward {
            t: PhantomData::<T>,
            l: PhantomData::<&'a ()>
        }
    }
}
impl<'a,const N:usize> Kernel for SoftMaxBatchBackward<'a, f32, N> {
    const FUNC_PTR: *const c_void = softmax_backward_float as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f32,N>;
}
impl<'a,const N:usize> Kernel for SoftMaxBatchBackward<'a, f64, N> {
    const FUNC_PTR: *const c_void = softmax_backward_double as *const c_void;
    type Args = ActivationBatchBackwardArgs<'a,f64,N>;
}