NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
normalize.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <cmath>
32#include <complex>
33
35#include "NumCpp/Core/Types.hpp"
37#include "NumCpp/NdArray.hpp"
38#include "NumCpp/Utils/sqr.hpp"
39
40namespace nc
41{
42 //============================================================================
43 // Method Description:
51 template<typename dtype>
53 {
55
56 switch (inAxis)
57 {
58 case Axis::NONE:
59 {
60 return inArray / norm(inArray, Axis::NONE);
61 }
62 case Axis::COL:
63 {
65 const auto cSlice = returnArray.cSlice();
66 for (uint32 row = 0; row < inArray.numRows(); ++row)
67 {
68 returnArray.put(row, cSlice, normalize(inArray.row(row), Axis::NONE));
69 }
70
71 return returnArray;
72 }
73 case Axis::ROW:
74 {
75 return normalize(inArray.transpose(), Axis::COL).transpose();
76 }
77 default:
78 {
79 THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
80 return {}; // get rid of compiler warning
81 }
82 }
83 }
84
85 //============================================================================
86 // Method Description:
94 template<typename dtype>
96 {
98
99 switch (inAxis)
100 {
101 case Axis::NONE:
102 {
103 return inArray / norm(inArray, Axis::NONE);
104 }
105 case Axis::COL:
106 {
108 const auto cSlice = returnArray.cSlice();
109 for (uint32 row = 0; row < inArray.numRows(); ++row)
110 {
111 returnArray.put(row, cSlice, normalize(inArray.row(row), Axis::NONE));
112 }
113
114 return returnArray;
115 }
116 case Axis::ROW:
117 {
118 return normalize(inArray.transpose(), Axis::COL).transpose();
119 }
120 default:
121 {
122 THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
123 return {}; // get rid of compiler warning
124 }
125 }
126 }
127} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
self_type transpose() const
Definition NdArrayCore.hpp:4958
Definition Cartesian.hpp:40
NdArray< double > norm(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition norm.hpp:51
Axis
Enum To describe an axis.
Definition Enums.hpp:36
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
NdArray< double > normalize(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition normalize.hpp:52
std::uint32_t uint32
Definition Types.hpp:40