File size: 25,599 Bytes
68ce2fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-    */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */

/*

  Author(s):  Daniel Li, Ofri Sadowsky, Anton Deguet
  Created on: 2006-07-10

  (C) Copyright 2006-2009 Johns Hopkins University (JHU), All Rights
  Reserved.

--- begin cisst license - do not edit ---

This software is provided "as is" under an open source license, with
no warranty.  The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.

--- end cisst license ---
*/

#pragma once
#ifndef _vctDynamicNArray_h
#define _vctDynamicNArray_h

/*!
  \file
  \brief Declaration of vctDynamicNArray
*/

#include <cisstVector/vctDynamicNArrayBase.h>
#include <cisstVector/vctDynamicNArrayOwner.h>
#include <cisstVector/vctDynamicNArrayRef.h>

/*!
  \ingroup cisstVector

  \brief An nArray object of dynamic size.

  This class defines a nArray object of dynamic size with memory
  allocation.

  The algebraic operations are mostly inherited from the base classes
  vctDynamicNArrayBase and vctDynamicConstNArrayBase.  Here, we will
  briefly describe the specific properties of vctDynamicNArray, with a
  few usage examples.

  <ol>
  <li> The class is templated by its element type, that is, the nArray
  element.  Normally, the element should be an arithmetic type, that
  is, support all the standard arithmetic operations: +, -, *, /, =,
  ==, <, >, <=, >=, ...
  <li> The class is templated by dimension, i.e. for a vector-like
  nArray the dimension would be 1, 2 for a matrix-like nArray, 3 for a
  volume, ...
  <li>The types <code>nsize_type</code>, <code>nindex_type</code> and
  <code>nstride_type</code> are defined within the scope of the nArray
  classes and used in their interfaces to set the sizes, access
  elements or manipulate the layout.
  <li> The class uses dynamically allocated memory, and, more
  importantly, \em owns the memory.  That is, a vctDynamicNArray
  object automatically frees the allocated memory it owns when it is
  destroyed.
  <li>To allocate the memory, use one of the following operations.
  \code
  // define a typical element type and a couple of useful other types
  typedef double ElementType;
  enum {DIMENSION = 3};
  typedef vctDynamicNArray<ElementType, DIMENSION> ArrayType;
  typedef typename ArrayType::nsize_type SizeType;

  // constructor allocation, empty array
  ArrayType a1;

  // Create an empty nArray and later allocate memory.
  ArrayType a2;
  a2.SetSize(SizeType(5, 7, 8));
  vctRandom(a2, ElementType(0), ElementType(10));

  // Create an nArray of some size and change it later.
  // This operation does not preserve any elements in the resized
  // nArray
  ArrayType a3(SizeType(7, 8, 9));
  a3.SetSize(a2.sizes());
  vctRandom(a3, ElementType(-10), ElementType(0));

  // Store an algebraic result to a new nArray.  In this case,
  // memory is allocated by the algebraic operation, and then
  // attached to the nArray object.
  ArrayType a4 = a3 - a2;
  \endcode
  <li> NArray assignment can be facilitated through the Assign method
  (defined in the base class) or as follows.
  \code
  // Initialize all elements to the same value
  ArrayType a5(a3.sizes(), 2.0);

  // Assign one matrix to another.
  vctDynamicNArray<int, DIMENSION> nArrayInt;
  nArrayInt.Assign(a5); // preferred syntax
  nArrayInt = a5; // same operation
  \endcode
  </ol>

  A few more notes.
  <ul>
  <li> The elements lie in contiguous increasing memory addresses.
  <li> There is no direct way of ``disowning'' a vctDynamicNArray,
  that is taking ownership of its memory.
  <li> When a function returns an allocating dynamic nArray object, it
  is better to return a vctReturnDynamicNArray, which is a helper
  class designed for transfering the ownership of the allocated memory
  without reallocation.
  </ul>

  \param _elementType the type of an element in the nArray.

  \param _dimension the dimension the multi-dimensional array.

  \sa vctDynamicNArrayBase vctDynamicConstNArrayBase
*/
template<class _elementType, vct::size_type _dimension>
class vctDynamicNArray :
    public vctDynamicNArrayBase<vctDynamicNArrayOwner<_elementType, _dimension>, _elementType, _dimension>
{

    friend class vctReturnDynamicNArray<_elementType, _dimension>;

public:
    /* define most types from vctContainerTraits and vctNArrayTraits */
    VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
    VCT_NARRAY_TRAITS_TYPEDEFS(_dimension);

    typedef vctDynamicNArrayBase<vctDynamicNArrayOwner<_elementType, _dimension>, _elementType, _dimension> BaseType;
    typedef vctDynamicNArray<_elementType, _dimension> ThisType;

    /*! Default constructor. Initialize an empty nArray. */
    vctDynamicNArray()
        // The default initialization of vctDynamicNArrayOwner is empty.
    {}

    /*! Constructor: Create an nArray of the specified sizes.  Elements
       initialized with default constructor. */
    vctDynamicNArray(const nsize_type & sizes)
    {
        this->NArray.SetSize(sizes);
    }

    /*! Constructor: Create an nArray of the specified size and assign all
      elements a specific value. */
    vctDynamicNArray(const nsize_type & sizes, value_type value)
    {
        this->NArray.SetSize(sizes);
        SetAll(value);
    }

    /*! Special copy constructor: Take ownership of the data of a
      temporary nArray object of type vctReturnDynamicNArray.  Disown
      the other nArray.
    */
    vctDynamicNArray(const vctReturnDynamicNArray<value_type, _dimension> & otherNArray);


    /*! Copy constructor: Allocate memory to store a copy of the other
      nArray, and copy the elements of the other nArray to this nArray. */
    //@{
    vctDynamicNArray(const ThisType & otherNArray):
        BaseType()
    {
        SetSize(otherNArray.sizes());
        this->Assign(otherNArray);
    }
    template <class _otherNArrayOwnerType>
    vctDynamicNArray(const vctDynamicConstNArrayBase<_otherNArrayOwnerType, value_type, _dimension> & otherNArray)
    {
        SetSize(otherNArray.sizes());
        this->Assign(otherNArray);
    }
    //@}

    /*! Copy constructor: Allocate memory and copy all the elements
      from the other nArray.  This constructor can also be used for
      type conversions.
    */
    template <class _otherNArrayOwnerType, typename _otherNArrayElementType>
    explicit vctDynamicNArray(const vctDynamicConstNArrayBase<_otherNArrayOwnerType, _otherNArrayElementType, _dimension> & otherNArray)
    {
        SetSize(otherNArray.sizes());
        this->Assign(otherNArray);
    }


    /*!  Assignment from an nArray to this nArray.  The operation discards
         the old memory allocated for this nArray and allocates new memory
         the size of the input nArray.  Then the elements of the input nArray
         are copied into this nArray.
     */
    template <class __nArrayOwnerType, typename __elementType>
    ThisType & operator = (const vctDynamicConstNArrayBase<__nArrayOwnerType, __elementType, _dimension> & otherNArray)
    {
        SetSize(otherNArray.sizes());
        this->Assign(otherNArray);
        return *this;
    }

    /*!  Equals operator: Assignment from a vctDynamicNArray to this nArray
         (also a vctDynamicNArray). The operation discards the old memory
         allocated for this nArray and allocates new memory the size of the
         input vctDynamicNArray. Then the elements of the input vctDynamicNArray
         are copied into this nArray.
     */
    ThisType & operator = (const ThisType & otherNArray)
    {
        SetSize(otherNArray.sizes());
        this->Assign(otherNArray);
        return *this;
    }


    /*!  Assignment from a transitional vctReturnDynamicNArray to a
      vctDynamicNArray variable.  This specialized operation does not
      perform any element copy.  Instead it transfers ownership of the
      data from the other nArray to this nArray, and disowns the other
      nArray.  The right hand side operand must be a temporary object
      returned, e.g., from a function or overloaded operator.

      \todo This operator needs some revisions.
    */
    ThisType & operator = (const vctReturnDynamicNArray<value_type, _dimension> & otherNArray);

    /*! Assignment of a scalar to all elements.  See also SetAll. */
    inline ThisType & operator = (const value_type & value)
    {
        this->SetAll(value);
        return *this;
    }

    // documented in base class
    template <class __nArrayOwnerType, typename __elementType>
    inline ThisType & ForceAssign(const vctDynamicConstNArrayBase<__nArrayOwnerType, __elementType, _dimension> & other) {
        this->SetSize(other.size());
        return this->Assign(other);
    }

    /*! Destructive size change.  Change the size to the specified
      size. Discard all of the old values. */
    //@{
    void SetSize(const nsize_type & sizes)
    {
        this->NArray.SetSize(sizes);
    }
    //@}
};


/*!
  Class vctReturnDynamicNArray is specialized to store a temporary
  nArray object by transferring ownership.  An object of this class has
  all the methods inherited from vctDynamicNArray, but can only be
  constructed in one way -- taking the ownership from another
  vctDynamicNArray (or vctReturnDynamicNArray) object.  In turn, when
  an assignment occurs from a vctReturnDynamicNArray to a
  vctDynamicNArray (or likewise construction), the LHS
  vctDynamicNArray strips this object from the ownership of the data.

  Use this class only when you want to return a newly created dynamic
  nArray from a function, without going through memory allocation and
  deallocation.  Never use it on an object that is going to remain in
  scope after constructing the vctReturnDynamicNArray.
*/
template <class _elementType, vct::size_type _dimension>
class vctReturnDynamicNArray : public vctDynamicNArray<_elementType, _dimension>
{
public:
    VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
    VCT_NARRAY_TRAITS_TYPEDEFS(_dimension);

    /*! Base type of vctReturnDynamicNArray. */
    typedef vctDynamicNArray<_elementType, _dimension> BaseType;

    explicit vctReturnDynamicNArray(const BaseType & other)
    {
        BaseType & nonConstOther = const_cast<BaseType &>(other);
        // if we don't save it in a variable, it will be destroyed in the Release operation

        const nsize_type sizes = other.sizes();
        this->NArray.Own(sizes, nonConstOther.NArray.Release());
    }
};


// implementation of the special copy constructor of vctDynamicNArray
template <class _elementType, vct::size_type _dimension>
vctDynamicNArray<_elementType, _dimension>::vctDynamicNArray(const vctReturnDynamicNArray<_elementType, _dimension> & other)
{
    vctReturnDynamicNArray<_elementType, _dimension> & nonConstOther =
        const_cast< vctReturnDynamicNArray<_elementType, _dimension> & >(other);
    // if we don't save it in a variable, it will be destroyed in the Release operation

    const nsize_type sizes = other.sizes();
    this->NArray.Own(sizes, nonConstOther.NArray.Release());
}


// implementation of the special assignment operator from vctReturnDynamicNArray to vctDynamicNArray
template <class _elementType, vct::size_type _dimension>
vctDynamicNArray<_elementType, _dimension> &
vctDynamicNArray<_elementType, _dimension>::operator = (const vctReturnDynamicNArray<_elementType, _dimension> & other)
{
    vctReturnDynamicNArray<_elementType, _dimension> & nonConstOther =
        const_cast< vctReturnDynamicNArray<_elementType, _dimension> & >(other);
    // if we don't save it in a variable, it will be destroyed in the Release operation

    const nsize_type sizes = other.sizes();
    this->NArray.clear();
    this->NArray.Own(sizes, nonConstOther.NArray.Release());
    return *this;
}


/*! \name Elementwise operations between nArrays. */
//@{
/*! Operation between nArrays (same size).
  \param inputNArray1 The first operand of the binary operation.
  \param inputNArray2 The second operand of the binary operation.
  \return The nArray result of \f$op(nArray1, nArray2)\f$.
*/
template <class _nArrayOwnerType1, class _nArrayOwnerType2, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator + (const vctDynamicConstNArrayBase<_nArrayOwnerType1, _elementType, _dimension> & inputNArray1,
            const vctDynamicConstNArrayBase<_nArrayOwnerType2, _elementType, _dimension> & inputNArray2)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray1);
    resultStorage.Add(inputNArray2);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented above */
template <class _nArrayOwnerType1, class _nArrayOwnerType2, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator - (const vctDynamicConstNArrayBase<_nArrayOwnerType1, _elementType, _dimension> & inputNArray1,
            const vctDynamicConstNArrayBase<_nArrayOwnerType2, _elementType, _dimension> & inputNArray2)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray1);
    resultStorage.Subtract(inputNArray2);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}
//@}



/*! \name Elementwise operations between an nArray and a
  scalar. */
//@{
/*! Operation between an nArray and a scalar.
  \param inputNArray The first operand of the binary operation.
  \param inputScalar The second operand of the binary operation.
  \return The nArray result of \f$op(nArray, scalar)\f$.
*/
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator + (const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray,
            const _elementType & inputScalar)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
    resultStorage.Add(inputScalar);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented above */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator - (const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray,
            const _elementType & inputScalar)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
    resultStorage.Subtract(inputScalar);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented above */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator * (const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray,
            const _elementType & inputScalar)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
    resultStorage.Multiply(inputScalar);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented above */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator / (const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray,
            const _elementType & inputScalar)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray);
    resultStorage.Divide(inputScalar);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}
//@}



/*! \name Elementwise operations between a scalar and an nArray. */
//@{
/*! Operation between a scalar and an nArray.
  \param inputScalar The first operand of the binary operation.
  \param inputNArray The second operand of the binary operation.
  \return The nArray result of \f$op(scalar, nArray)\f$.
*/
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator + (const _elementType & inputScalar,
            const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
    resultStorage.SumOf(inputScalar, inputNArray);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented above */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator - (const _elementType & inputScalar,
            const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
    resultStorage.DifferenceOf(inputScalar, inputNArray);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented above */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator * (const _elementType & inputScalar,
            const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
    resultStorage.ProductOf(inputScalar, inputNArray);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented above */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator / (const _elementType & inputScalar,
            const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
    resultStorage.RatioOf(inputScalar, inputNArray);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}
//@}


/*! \name Elementwise operations on an nArray. */
//@{
/*! Unary operation on an nArray.
  \param inputNArray The operand of the unary operation
  \return The nArray result of \f$op(nArray)\f$.
*/
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator - (const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & inputNArray)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray.sizes());
    resultStorage.NegationOf(inputNArray);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}
//@}



#ifndef DOXYGEN
template <class _nArrayOwnerType1, class _nArrayOwnerType2, class _elementType, vct::size_type _dimension>
vctReturnDynamicNArray<_elementType, _dimension>
operator * (const vctDynamicConstNArrayBase<_nArrayOwnerType1, _elementType, _dimension> & inputNArray1,
            const vctDynamicConstNArrayBase<_nArrayOwnerType2, _elementType, _dimension> & inputNArray2)
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(inputNArray1.sizes());
    resultStorage.ProductOf(inputNArray1, inputNArray2);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}


/*
  Methods declared previously and implemented here because they require vctReturnDynamicNArray
*/


/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
inline typename vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::NArrayReturnType
vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::Abs(void) const
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
    vctDynamicNArrayLoopEngines<_dimension>::template
        NoNi<typename vctUnaryOperations<value_type>::AbsValue>::
        Run(resultStorage, *this);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
inline typename vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::NArrayReturnType
vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::Negation(void) const
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
    vctDynamicNArrayLoopEngines<_dimension>::template
        NoNi<typename vctUnaryOperations<value_type>::Negation>::
        Run(resultStorage, *this);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
inline typename vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::NArrayReturnType
vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::Floor(void) const
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
    vctDynamicNArrayLoopEngines<_dimension>::template
        NoNi<typename vctUnaryOperations<value_type>::Floor>::
        Run(resultStorage, *this);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
inline typename vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::NArrayReturnType
vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension>::Ceil(void) const
{
    typedef _elementType value_type;
    vctDynamicNArray<value_type, _dimension> resultStorage(this->sizes());
    vctDynamicNArrayLoopEngines<_dimension>::template
        NoNi<typename vctUnaryOperations<value_type>::Ceil>::
        Run(resultStorage, *this);
    return vctReturnDynamicNArray<value_type, _dimension>(resultStorage);
}

/* Documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class __nArrayOwnerType, class _elementType,
         class _elementOperationType, vct::size_type _dimension>
inline vctReturnDynamicNArray<bool, _dimension>
vctDynamicNArrayElementwiseCompareNArray(const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & nArray1,
                                         const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & nArray2)
{
    vctDynamicNArray<bool, _dimension> result(nArray1.sizes());
    vctDynamicNArrayLoopEngines<_dimension>::template
        NoNiNi<_elementOperationType>::Run(result, nArray1, nArray2);
    return vctReturnDynamicNArray<bool, _dimension>(result);
}

/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType, class _elementOperationType, vct::size_type _dimension>
inline vctReturnDynamicNArray<bool, _dimension>
vctDynamicNArrayElementwiseCompareScalar(const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & nArray,
                                         const _elementType & scalar)
{
    vctDynamicNArray<bool, _dimension> result(nArray.sizes());
    vctDynamicNArrayLoopEngines<_dimension>::template
        NoNiSi<_elementOperationType>::Run(result, nArray, scalar);
    return vctReturnDynamicNArray<bool, _dimension>(result);
}


/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
inline vctDynamicNArrayRef<_elementType, _dimension - 1>
vctDynamicNArrayNArraySlice(vctDynamicNArrayBase<_nArrayOwnerType, _elementType, _dimension> & input,
                            vct::size_type dimension,
                            vct::index_type index)
{
    vctDynamicNArrayRef<_elementType, _dimension - 1> slice;
    slice.SliceOf(input, dimension, index);
    return slice;
}

/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType>
inline _elementType &
vctDynamicNArrayElementSlice(vctDynamicNArrayBase<_nArrayOwnerType, _elementType, 1> & input,
                             vct::index_type index)
{
    return input.Element(vctFixedSizeVector<vct::index_type, 1>(index));
}

/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType, vct::size_type _dimension>
inline vctDynamicConstNArrayRef<_elementType, _dimension - 1>
vctDynamicNArrayConstNArraySlice(const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, _dimension> & input,
                                 vct::size_type dimension,
                                 vct::index_type index)
{
    vctDynamicConstNArrayRef<_elementType, _dimension - 1> slice;
    slice.SliceOf(input, dimension, index);
    return slice;
}

/* documented in class vctDynamicConstNArrayBase */
template <class _nArrayOwnerType, class _elementType>
inline const _elementType &
vctDynamicNArrayConstElementSlice(const vctDynamicConstNArrayBase<_nArrayOwnerType, _elementType, 1> & input,
                                  vct::index_type index)
{
    return input.Element(vctFixedSizeVector<vct::index_type, 1>(index));
}

#endif // DOXYGEN


#endif // _vctDynamicNArray_h