From 191dd662866e9035051bdd40a45236bfbda3f958 Mon Sep 17 00:00:00 2001 From: Vincent Favre-Nicolin Date: Tue, 3 Nov 2026 12:03:01 +0100 Subject: [PATCH 1/7] feat: port March-Dollase texture (#119) and TOF profile (#120) to nanobind - Bind TextureMarchDollase and PowderPatternDiffraction.GetTextureMarchDollase. SetPhasePar is bound directly (no RefinablePar workaround) since the objcryst submodule (ba6ca89, vincefn/objcryst#105) now clicks the texture clock; DeletePhase is also exposed. - TextureMarchDollase has RefinableObj as a second (non-zero offset) base, so it is registered standalone with bind_refinableobj_forwarding and added to extractRefinableObjArg. - Bind ReflectionProfileDoubleExponentialPseudoVoigt; SetProfile gives a TOF profile copy the crystal's unit cell. - Port tests and news items, with extra DeletePhase tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- nanobind_migration_notes.md | 6 + news/march-dollase-texture.rst | 23 ++ news/tof-profile.rst | 23 ++ .../nb_powderpatterndiffraction.cpp | 63 +++++- src/extensions/nb_refinableobj.cpp | 3 + src/extensions/nb_reflectionprofile.cpp | 26 +++ src/pyobjcryst/powderpattern.py | 2 + src/pyobjcryst/reflectionprofile.py | 7 + tests/test_powderpattern.py | 202 +++++++++++++++++- tests/test_reflectionprofile.py | 139 ++++++++++++ 10 files changed, 490 insertions(+), 4 deletions(-) create mode 100644 news/march-dollase-texture.rst create mode 100644 news/tof-profile.rst diff --git a/nanobind_migration_notes.md b/nanobind_migration_notes.md index ffc2e35..ac2c1f0 100644 --- a/nanobind_migration_notes.md +++ b/nanobind_migration_notes.md @@ -203,6 +203,12 @@ is fine and should still use nanobind's automatic base declaration (e.g. `Scatte public ScatteringPower`, no `virtual`, is safely `nb::class_`). +The same applies to *non-virtual multiple inheritance* where the base is not the first one, e.g. +`TextureMarchDollase : public ScatteringCorr, public RefinableObj`: `RefinableObj` sits at a +non-zero offset, and `nb::class_` silently returns garbage +(`GetNbPar()` was 0). Register it standalone, call `bind_refinableobj_forwarding()`, and add it to +`extractRefinableObjArg`. + ### Four ways this bites, and the fix for each **1. Return direction** — a function returns a base-typed reference/pointer diff --git a/news/march-dollase-texture.rst b/news/march-dollase-texture.rst new file mode 100644 index 0000000..3a891a0 --- /dev/null +++ b/news/march-dollase-texture.rst @@ -0,0 +1,23 @@ +**Added:** + +* Expose the March-Dollase preferred-orientation correction TextureMarchDollase (AddPhase, SetPhasePar, DeletePhase and getters) and PowderPatternDiffraction.GetTextureMarchDollase. SetPhasePar and DeletePhase rely on the upstream ObjCryst++ fix (vincefn/objcryst#105) which recalculates the powder pattern when the texture changes. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/news/tof-profile.rst b/news/tof-profile.rst new file mode 100644 index 0000000..ad9d2c6 --- /dev/null +++ b/news/tof-profile.rst @@ -0,0 +1,23 @@ +**Added:** + +* Expose the time-of-flight reflection profile ReflectionProfileDoubleExponentialPseudoVoigt. + +**Changed:** + +* PowderPatternDiffraction.SetProfile gives a ReflectionProfileDoubleExponentialPseudoVoigt the unit cell of the component's crystal. + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/extensions/nb_powderpatterndiffraction.cpp b/src/extensions/nb_powderpatterndiffraction.cpp index 92df37c..df8627f 100644 --- a/src/extensions/nb_powderpatterndiffraction.cpp +++ b/src/extensions/nb_powderpatterndiffraction.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "helpers_nb.hpp" @@ -18,6 +19,38 @@ namespace nb = nanobind; using namespace ObjCryst; +namespace { + +void SetProfileCopy(PowderPatternDiffraction& pdiff, + const ReflectionProfile& profile) +{ + ReflectionProfile* copy = profile.CreateCopy(); + // The TOF profile needs a unit cell to compute d_hkl, as in + // PowderPatternDiffraction::SetCrystal and XMLInput. + auto* tofprofile = + dynamic_cast(copy); + if (tofprofile != nullptr && pdiff.HasCrystal()) + tofprofile->SetUnitCell(pdiff.GetCrystal()); + pdiff.SetProfile(copy); +} + +// PowderPatternDiffraction has no public accessor for its texture +// correction, but registers it as a sub-object. +TextureMarchDollase& GetTextureMarchDollase(PowderPatternDiffraction& pdiff) +{ + ObjRegistry& subobjs = pdiff.GetSubObjRegistry(); + for (long i = 0; i < subobjs.GetNb(); ++i) + { + auto* texture = dynamic_cast(&subobjs.GetObj(i)); + if (texture != nullptr) return *texture; + } + throw ObjCrystException("PowderPatternDiffraction has no " + "TextureMarchDollase sub-object. Please report " + "this as a pyobjcryst bug."); +} + +} // namespace + void wrap_powderpatterndiffraction(nb::module_& m) { nb::enum_(m, "ReflectionProfileType") @@ -72,9 +105,7 @@ void wrap_powderpatterndiffraction(nb::module_& m) nb::overload_cast<>(&PowderPatternDiffraction::GetProfile), nb::rv_policy::reference_internal) .def("SetProfile", - [](PowderPatternDiffraction& d, ReflectionProfile& p) { - d.SetProfile(p.CreateCopy()); - }, + &SetProfileCopy, nb::arg("profile"), "Install an independent copy of the given profile.") .def("SetExtractionMode", @@ -94,5 +125,31 @@ void wrap_powderpatterndiffraction(nb::module_& m) [](PowderPatternDiffraction& d){ return crystvec_to_array(d.GetFhklObsSq()); }) .def("X2XCorrPhase", &PowderPatternDiffraction::X2XCorrPhase, "Apply the flat-detector displacement correction for this phase's offset.") + .def("GetTextureMarchDollase", &GetTextureMarchDollase, + nb::rv_policy::reference_internal, + "Return the March-Dollase preferred-orientation correction.") + ; + + // TextureMarchDollase : public ScatteringCorr, public RefinableObj -- + // RefinableObj is a second base at a non-zero offset, which nanobind's + // base casting cannot handle (same failure mode as the virtual bases in + // nanobind_migration_notes.md). Register it standalone and forward the + // RefinableObj surface through T instead. + auto texture = nb::class_(m, "TextureMarchDollase"); + bind_refinableobj_forwarding(texture); + texture + .def("AddPhase", &TextureMarchDollase::AddPhase, + nb::arg("fraction"), nb::arg("coeffMarch"), + nb::arg("h"), nb::arg("k"), nb::arg("l")) + .def("SetPhasePar", &TextureMarchDollase::SetPhasePar, + nb::arg("i"), nb::arg("fraction"), nb::arg("coeffMarch"), + nb::arg("h"), nb::arg("k"), nb::arg("l")) + .def("DeletePhase", &TextureMarchDollase::DeletePhase, nb::arg("i")) + .def("GetNbPhase", &TextureMarchDollase::GetNbPhase) + .def("GetFraction", &TextureMarchDollase::GetFraction, nb::arg("i")) + .def("GetMarchCoeff", &TextureMarchDollase::GetMarchCoeff, nb::arg("i")) + .def("GetPhaseH", &TextureMarchDollase::GetPhaseH, nb::arg("i")) + .def("GetPhaseK", &TextureMarchDollase::GetPhaseK, nb::arg("i")) + .def("GetPhaseL", &TextureMarchDollase::GetPhaseL, nb::arg("i")) ; } diff --git a/src/extensions/nb_refinableobj.cpp b/src/extensions/nb_refinableobj.cpp index 4bdb782..322678d 100644 --- a/src/extensions/nb_refinableobj.cpp +++ b/src/extensions/nb_refinableobj.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "helpers_nb.hpp" @@ -154,6 +155,8 @@ RefinableObj& extractRefinableObjArg(nb::object obj) try { return static_cast(nb::cast(obj)); } catch (...) {} try { return static_cast(nb::cast(obj)); } catch (...) {} try { return static_cast(nb::cast(obj)); } catch (...) {} + // Non-virtual, but RefinableObj is its second base (non-zero offset). + try { return static_cast(nb::cast(obj)); } catch (...) {} // Nothing matched -- let this raise a clear nanobind TypeError rather // than silently returning a dangling reference. return nb::cast(obj); diff --git a/src/extensions/nb_reflectionprofile.cpp b/src/extensions/nb_reflectionprofile.cpp index 14e442f..1252fd7 100644 --- a/src/extensions/nb_reflectionprofile.cpp +++ b/src/extensions/nb_reflectionprofile.cpp @@ -10,6 +10,7 @@ #undef B0 #include +#include #include #include "helpers_nb.hpp" @@ -133,6 +134,31 @@ void wrap_reflectionprofile(nb::module_& m) "Set the TCH pseudo-Voigt U, V, W, X, Y, Z, P and LGmix parameters.") ; + nb::class_( + m, "ReflectionProfileDoubleExponentialPseudoVoigt", + nb::is_weak_referenceable()) + .def(nb::init<>()) + .def(nb::init(), nb::arg("cell"), nb::keep_alive<1, 2>()) + .def(nb::init(), + nb::arg("old"), nb::keep_alive<1, 2>()) + .def("CreateCopy", + &ReflectionProfileDoubleExponentialPseudoVoigt::CreateCopy, + nb::rv_policy::take_ownership, nb::keep_alive<0, 1>(), + "Return an independent copy of this profile.") + .def("SetProfilePar", + &ReflectionProfileDoubleExponentialPseudoVoigt::SetProfilePar, + nb::arg("instrumentAlpha0"), nb::arg("instrumentAlpha1"), + nb::arg("instrumentBeta0"), nb::arg("instrumentBeta1"), + nb::arg("gaussianSigma0"), nb::arg("gaussianSigma1"), + nb::arg("gaussianSigma2"), nb::arg("lorentzianGamma0"), + nb::arg("lorentzianGamma1"), nb::arg("lorentzianGamma2"), + "Set the double-exponential pseudo-Voigt TOF profile parameters.") + .def("SetUnitCell", + &ReflectionProfileDoubleExponentialPseudoVoigt::SetUnitCell, + nb::arg("cell"), nb::keep_alive<1, 2>(), + "Set the unit cell used to compute d_hkl for reflections.") + ; + nb::class_( m, "ReflectionProfilePseudoVoigtAnisotropic") .def(nb::init<>()) diff --git a/src/pyobjcryst/powderpattern.py b/src/pyobjcryst/powderpattern.py index a044024..0b74b26 100644 --- a/src/pyobjcryst/powderpattern.py +++ b/src/pyobjcryst/powderpattern.py @@ -30,6 +30,7 @@ "PowderPatternDiffraction", "ReflectionProfileType", "SpaceGroupExplorer", + "TextureMarchDollase", ] from pyobjcryst._pyobjcryst import ( @@ -45,6 +46,7 @@ PowderPatternDiffraction, ReflectionProfileType, SpaceGroupExplorer, + TextureMarchDollase, ) from pyobjcryst.general import ObjCrystException from pyobjcryst.refinableobj import refpartype_scattdata_background diff --git a/src/pyobjcryst/reflectionprofile.py b/src/pyobjcryst/reflectionprofile.py index c3d9d3b..cf90ebd 100644 --- a/src/pyobjcryst/reflectionprofile.py +++ b/src/pyobjcryst/reflectionprofile.py @@ -43,6 +43,11 @@ aniso.SetProfilePar(fwhmCagliotiW=1e-4) ppd3.SetProfile(aniso) +For time-of-flight neutron data, use the double-exponential pseudo-Voigt +profile ``ReflectionProfileDoubleExponentialPseudoVoigt``. It needs the +unit cell to compute ``d_hkl``, which ``PowderPatternDiffraction.SetProfile`` +sets from the component's crystal. + Example ------- @@ -76,11 +81,13 @@ "ReflectionProfilePseudoVoigt", "ReflectionProfilePseudoVoigtTCH", "ReflectionProfilePseudoVoigtAnisotropic", + "ReflectionProfileDoubleExponentialPseudoVoigt", "ReflectionProfileType", ] from pyobjcryst._pyobjcryst import ( ReflectionProfile, + ReflectionProfileDoubleExponentialPseudoVoigt, ReflectionProfilePseudoVoigt, ReflectionProfilePseudoVoigtAnisotropic, ReflectionProfilePseudoVoigtTCH, diff --git a/tests/test_powderpattern.py b/tests/test_powderpattern.py index 507734f..44531d6 100644 --- a/tests/test_powderpattern.py +++ b/tests/test_powderpattern.py @@ -23,7 +23,11 @@ from pyobjcryst import ObjCrystException from pyobjcryst.indexing import CrystalCentering, CrystalSystem, quick_index -from pyobjcryst.powderpattern import PowderPattern, SpaceGroupExplorer +from pyobjcryst.powderpattern import ( + PowderPattern, + SpaceGroupExplorer, + TextureMarchDollase, +) from pyobjcryst.radiation import RadiationType, WavelengthType from pyobjcryst.reflectionprofile import ReflectionProfileType @@ -497,5 +501,201 @@ def test_X2XCorrPhase_flat_detector_displacement(self): # ---------------------------------------------------------------------------- + +def build_textured_pattern(crystal, phases): + """Return an X-ray powder pattern of crystal with March-Dollase + phases.""" + pattern = PowderPattern() + pattern.SetWavelength(1.54) + x = np.deg2rad(np.linspace(5, 40, 2001)) + pattern.SetPowderPatternX(x) + pattern.SetPowderPatternObs(np.ones_like(x)) + diffraction = pattern.AddPowderPatternDiffraction(crystal) + texture = diffraction.GetTextureMarchDollase() + for phase in phases: + texture.AddPhase(*phase) + return pattern + + +@pytest.mark.parametrize( + "phases, expected_par_names", + [ + # Test that AddPhase stores a texture phase and its refinable + # parameters + # C1: One phase with a fraction, March coefficient and hkl is + # added. + # Expected: The getters return the phase's values, and its five + # parameters are named with the suffix _0. + ( + [(1.0, 0.5, 0, 0, 1)], + ["Fraction_0", "MarchCoeff_0", "H_0", "K_0", "L_0"], + ), + # C2: Two phases are added. + # Expected: The getters return each phase's values, and the second + # phase's parameters are named with the suffix _1. + ( + [(0.7, 0.5, 0, 0, 1), (0.3, 2.0, 1, 1, 0)], + [ + "Fraction_0", + "MarchCoeff_0", + "H_0", + "K_0", + "L_0", + "Fraction_1", + "MarchCoeff_1", + "H_1", + "K_1", + "L_1", + ], + ), + ], +) +def test_add_phase(loadcifdata, phases, expected_par_names): + crystal = loadcifdata("paracetamol.cif") + pattern = build_textured_pattern(crystal, phases) + texture = pattern.GetPowderPatternComponent(0).GetTextureMarchDollase() + actual_type = type(texture) + expected_type = TextureMarchDollase + actual_phases = [ + ( + texture.GetFraction(i), + texture.GetMarchCoeff(i), + texture.GetPhaseH(i), + texture.GetPhaseK(i), + texture.GetPhaseL(i), + ) + for i in range(texture.GetNbPhase()) + ] + expected_phases = phases + actual_par_names = [ + texture.GetPar(i).GetName() for i in range(texture.GetNbPar()) + ] + assert actual_type == expected_type + assert actual_phases == [pytest.approx(e) for e in expected_phases] + assert actual_par_names == expected_par_names + + +@pytest.mark.parametrize( + "initial_phases, method_name, method_args, expected_phases", + [ + # Test that changing the texture of an existing pattern + # recalculates it + # C1: A phase is added to an untextured pattern. + # Expected: The pattern equals one built with that phase. + ([], "AddPhase", (1.0, 0.5, 0, 0, 1), [(1.0, 0.5, 0, 0, 1)]), + # C2: SetPhasePar changes the March coefficient of a phase. + # Expected: The pattern equals one built with the new March + # coefficient. + ( + [(1.0, 0.5, 0, 0, 1)], + "SetPhasePar", + (0, 1.0, 2.0, 0, 0, 1), + [(1.0, 2.0, 0, 0, 1)], + ), + # C3: DeletePhase removes the second of two phases. + # Expected: The pattern equals one built with only the first phase. + ( + [(0.7, 0.5, 0, 0, 1), (0.3, 2.0, 1, 1, 0)], + "DeletePhase", + (1,), + [(0.7, 0.5, 0, 0, 1)], + ), + ], +) +def test_get_powder_pattern_calc_after_texture_change( + loadcifdata, initial_phases, method_name, method_args, expected_phases +): + crystal = loadcifdata("paracetamol.cif") + pattern = build_textured_pattern(crystal, initial_phases) + pattern.GetPowderPatternCalc() + texture = pattern.GetPowderPatternComponent(0).GetTextureMarchDollase() + getattr(texture, method_name)(*method_args) + actual_calc = pattern.GetPowderPatternCalc() + expected_calc = build_textured_pattern( + crystal, expected_phases + ).GetPowderPatternCalc() + assert np.allclose(actual_calc, expected_calc) + + +@pytest.mark.parametrize( + "method_name, method_args", + [ + # Test texture methods with the index of a phase that does not exist + # C1: SetPhasePar is called with index 1 on a single-phase texture. + # Expected: An ObjCrystException is raised. + ("SetPhasePar", (1, 1.0, 2.0, 0, 0, 1)), + # C2: DeletePhase is called with index 1 on a single-phase texture. + # Expected: An ObjCrystException is raised. + ("DeletePhase", (1,)), + ], +) +def test_texture_phase_index_out_of_range( + loadcifdata, method_name, method_args +): + crystal = loadcifdata("paracetamol.cif") + pattern = build_textured_pattern(crystal, [(1.0, 0.5, 0, 0, 1)]) + texture = pattern.GetPowderPatternComponent(0).GetTextureMarchDollase() + with pytest.raises(ObjCrystException): + getattr(texture, method_name)(*method_args) + + +@pytest.mark.parametrize( + "phases, deleted_index, expected_phases, expected_par_names", + [ + # Test that DeletePhase removes a phase and its refinable parameters + # C1: The only phase is deleted. + # Expected: No phase and no parameter remain. + ([(1.0, 0.5, 0, 0, 1)], 0, [], []), + # C2: The first of two phases is deleted. + # Expected: The second phase remains, and its parameters are + # renamed with the suffix _0. + ( + [(0.7, 0.5, 0, 0, 1), (0.3, 2.0, 1, 1, 0)], + 0, + [(0.3, 2.0, 1, 1, 0)], + ["Fraction_0", "MarchCoeff_0", "H_0", "K_0", "L_0"], + ), + ], +) +def test_delete_phase( + loadcifdata, phases, deleted_index, expected_phases, expected_par_names +): + crystal = loadcifdata("paracetamol.cif") + pattern = build_textured_pattern(crystal, phases) + texture = pattern.GetPowderPatternComponent(0).GetTextureMarchDollase() + texture.DeletePhase(deleted_index) + actual_phases = [ + ( + texture.GetFraction(i), + texture.GetMarchCoeff(i), + texture.GetPhaseH(i), + texture.GetPhaseK(i), + texture.GetPhaseL(i), + ) + for i in range(texture.GetNbPhase()) + ] + actual_par_names = [ + texture.GetPar(i).GetName() for i in range(texture.GetNbPar()) + ] + assert actual_phases == [pytest.approx(e) for e in expected_phases] + assert actual_par_names == expected_par_names + + +def test_get_powder_pattern_calc_after_march_coeff_par_change(loadcifdata): + # Test refining the March coefficient through its RefinablePar + # Expected: The pattern equals one built with the new March + # coefficient. + crystal = loadcifdata("paracetamol.cif") + pattern = build_textured_pattern(crystal, [(1.0, 0.5, 0, 0, 1)]) + pattern.GetPowderPatternCalc() + texture = pattern.GetPowderPatternComponent(0).GetTextureMarchDollase() + texture.GetPar("MarchCoeff_0").SetValue(2.0) + actual_calc = pattern.GetPowderPatternCalc() + expected_calc = build_textured_pattern( + crystal, [(1.0, 2.0, 0, 0, 1)] + ).GetPowderPatternCalc() + assert np.allclose(actual_calc, expected_calc) + + if __name__ == "__main__": unittest.main() diff --git a/tests/test_reflectionprofile.py b/tests/test_reflectionprofile.py index f4cfc48..067e165 100644 --- a/tests/test_reflectionprofile.py +++ b/tests/test_reflectionprofile.py @@ -1,13 +1,17 @@ """Unit tests for pyobjcryst.reflectionprofile bindings.""" +import gc import unittest +import weakref import numpy as np import pytest from pyobjcryst.powderpattern import PowderPattern +from pyobjcryst.radiation import RadiationType, WavelengthType from pyobjcryst.refinableobj import RefinableObj from pyobjcryst.reflectionprofile import ( + ReflectionProfileDoubleExponentialPseudoVoigt, ReflectionProfilePseudoVoigt, ReflectionProfilePseudoVoigtAnisotropic, ReflectionProfilePseudoVoigtTCH, @@ -230,5 +234,140 @@ def test_anisotropic_set_profile_par(self): self.assertAlmostEqual(aniso.GetPar("G_KK").GetValue(), 2e-5) +def build_tof_pattern(crystal, profile): + """Return a TOF neutron powder pattern of crystal using profile.""" + pattern = PowderPattern() + pattern.SetRadiationType(RadiationType.RAD_NEUTRON) + pattern.GetRadiation().SetWavelengthType(WavelengthType.WAVELENGTH_TOF) + # TOF decreases with sin(theta)/lambda, so x is in descending order. + x = np.linspace(120000, 20000, 2001) + pattern.SetPowderPatternX(x) + pattern.SetPowderPatternObs(np.ones_like(x)) + diffraction = pattern.AddPowderPatternDiffraction(crystal) + diffraction.SetProfile(profile) + return pattern + + +def test_set_profile_par_tof(): + # Test that SetProfilePar assigns the ten TOF profile parameters + # Expected: Each refinable parameter has the value passed for it. + profile = ReflectionProfileDoubleExponentialPseudoVoigt() + profile.SetProfilePar( + instrumentAlpha0=0.01, + instrumentAlpha1=0.1, + instrumentBeta0=0.02, + instrumentBeta1=0.004, + gaussianSigma0=1.0, + gaussianSigma1=7.0, + gaussianSigma2=0.5, + lorentzianGamma0=0.1, + lorentzianGamma1=0.2, + lorentzianGamma2=0.4, + ) + actual_values = { + profile.GetPar(i).GetName(): profile.GetPar(i).GetValue() + for i in range(profile.GetNbPar()) + } + expected_values = { + "Alpha0": 0.01, + "Alpha1": 0.1, + "Beta0": 0.02, + "Beta1": 0.004, + "GaussianSigma0": 1.0, + "GaussianSigma1": 7.0, + "GaussianSigma2": 0.5, + "LorentzianGamma0": 0.1, + "LorentzianGamma1": 0.2, + "LorentzianGamma2": 0.4, + } + assert actual_values == pytest.approx(expected_values) + + +def test_set_profile_tof_without_unit_cell(loadcifdata): + # Test installing a TOF profile constructed without a unit cell + # Expected: SetProfile gives the profile the crystal's unit cell, so + # the strongest peak is the Si (220) reflection at + # TOF = DIFC * d + DIFA * d^2. + crystal = loadcifdata("Si.cif") + pattern = build_tof_pattern( + crystal, ReflectionProfileDoubleExponentialPseudoVoigt() + ) + calc = pattern.GetPowderPatternCalc() + x = pattern.GetPowderPatternX() + actual_peak_tof = x[np.argmax(calc)] + d_220 = crystal.a / np.sqrt(8) + expected_peak_tof = ( + pattern.GetPar("DIFC").GetValue() * d_220 + + pattern.GetPar("DIFA").GetValue() * d_220**2 + ) + tof_step = abs(x[1] - x[0]) + assert actual_peak_tof == pytest.approx(expected_peak_tof, abs=tof_step) + + +@pytest.mark.parametrize( + "parameter_name, new_value", + [ + # Test that changing a parameter of the installed TOF profile + # recalculates the pattern + # C1: The rising-edge exponential coefficient Alpha1 is changed. + # Expected: The pattern equals one calculated with Alpha1 set + # before the profile was installed. + ("Alpha1", 0.2), + # C2: The falling-edge exponential coefficient Beta0 is changed. + # Expected: The pattern equals one calculated with Beta0 set + # before the profile was installed. + ("Beta0", 0.05), + # C3: The Gaussian width coefficient GaussianSigma1 is changed. + # Expected: The pattern equals one calculated with GaussianSigma1 + # set before the profile was installed. + ("GaussianSigma1", 50.0), + # C4: The Lorentzian width coefficient LorentzianGamma2 is changed. + # Expected: The pattern equals one calculated with + # LorentzianGamma2 set before the profile was installed. + ("LorentzianGamma2", 2.0), + ], +) +def test_get_powder_pattern_calc_after_tof_profile_change( + loadcifdata, parameter_name, new_value +): + crystal = loadcifdata("Si.cif") + pattern = build_tof_pattern( + crystal, ReflectionProfileDoubleExponentialPseudoVoigt() + ) + pattern.GetPowderPatternCalc() + profile = pattern.GetPowderPatternComponent(0).GetProfile() + profile.GetPar(parameter_name).SetValue(new_value) + actual_calc = pattern.GetPowderPatternCalc() + expected_profile = ReflectionProfileDoubleExponentialPseudoVoigt(crystal) + expected_profile.GetPar(parameter_name).SetValue(new_value) + expected_calc = build_tof_pattern( + crystal, expected_profile + ).GetPowderPatternCalc() + assert np.allclose(actual_calc, expected_calc) + + +@pytest.mark.parametrize("copy_method", ["CreateCopy", "copy_constructor"]) +def test_tof_profile_copy_keeps_original_alive(loadcifdata, copy_method): + # Test that a copy of a TOF profile keeps its source and unit cell alive + # Expected: The original profile and crystal survive until the copy is + # deleted, since both profiles reference the same unit cell. + crystal = loadcifdata("Si.cif") + original = ReflectionProfileDoubleExponentialPseudoVoigt(crystal) + if copy_method == "CreateCopy": + copied = original.CreateCopy() + else: + copied = ReflectionProfileDoubleExponentialPseudoVoigt(original) + original_ref = weakref.ref(original) + crystal_ref = weakref.ref(crystal) + del original, crystal + gc.collect() + assert original_ref() is not None + assert crystal_ref() is not None + del copied + gc.collect() + assert original_ref() is None + assert crystal_ref() is None + + if __name__ == "__main__": unittest.main() From 92b4c06cb0b6890c7d19e4aa5aa82e7017fd75e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:03:33 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit hooks --- .../scitbx/array_family/small_reductions.h | 1 - .../scitbx/array_family/tiny_reductions.h | 1 - extern/newmat/Makefile.in | 1 - extern/newmat/_newmat.dox | 5 - extern/newmat/_rbd_com.dox | 5 - extern/newmat/bandmat.cpp | 8 +- extern/newmat/cholesky.cpp | 12 +- extern/newmat/controlw.h | 1 - extern/newmat/evalue.cpp | 7 +- extern/newmat/example.cpp | 8 +- extern/newmat/example.txt | 116 +- extern/newmat/garch.cpp | 2 +- extern/newmat/garch.dat | 1001 +- extern/newmat/garch.txt | 26 +- extern/newmat/hholder.cpp | 36 +- extern/newmat/include.h | 3 +- extern/newmat/myexcept.cpp | 3 +- extern/newmat/myexcept.h | 1 - extern/newmat/newfft.cpp | 1 - extern/newmat/newmat.h | 14 +- extern/newmat/newmat1.cpp | 8 +- extern/newmat/newmat4.cpp | 30 +- extern/newmat/newmat5.cpp | 18 +- extern/newmat/newmat6.cpp | 4 +- extern/newmat/newmat7.cpp | 3 +- extern/newmat/newmat8.cpp | 4 +- extern/newmat/newmatap.h | 16 +- extern/newmat/newmatex.cpp | 1 - extern/newmat/newmatnl.cpp | 4 +- extern/newmat/newmatnl.h | 3 +- extern/newmat/newmatrm.cpp | 2 +- extern/newmat/newmatrm.h | 4 +- extern/newmat/nl_ex.cpp | 7 +- extern/newmat/nl_ex.txt | 31 +- extern/newmat/nm11.htm | 11478 +++++++++------- extern/newmat/nm_b55.mak | 3 +- extern/newmat/nm_b56.mak | 3 +- extern/newmat/nm_cc.mak | 7 +- extern/newmat/nm_ex1.cpp | 11 +- extern/newmat/nm_ex1.txt | 25 +- extern/newmat/nm_ex2.cpp | 16 +- extern/newmat/nm_ex2.txt | 71 +- extern/newmat/nm_ex3.cpp | 23 +- extern/newmat/nm_ex3.txt | 19 +- extern/newmat/nm_gnu.mak | 3 +- extern/newmat/nm_i10.mak | 5 +- extern/newmat/nm_i8.mak | 3 +- extern/newmat/nm_il8.mak | 3 +- extern/newmat/nm_m6.mak | 3 +- extern/newmat/nm_m8.mak | 3 +- extern/newmat/nm_misc.cpp | 8 +- extern/newmat/nm_ow.mak | 3 +- extern/newmat/precisio.h | 4 +- extern/newmat/rbd.css | 98 +- extern/newmat/readme.txt | 2 - extern/newmat/sl_ex.cpp | 4 +- extern/newmat/solution.h | 1 - extern/newmat/submat.cpp | 7 +- extern/newmat/test_exc.txt | 3 +- extern/newmat/tmt.cpp | 17 +- extern/newmat/tmt.h | 10 +- extern/newmat/tmt.txt | 183 +- extern/newmat/tmt1.cpp | 30 +- extern/newmat/tmt2.cpp | 10 +- extern/newmat/tmt4.cpp | 36 +- extern/newmat/tmt6.cpp | 2 +- extern/newmat/tmt7.cpp | 46 +- extern/newmat/tmt8.cpp | 4 +- extern/newmat/tmt9.cpp | 20 +- extern/newmat/tmtc.cpp | 74 +- extern/newmat/tmtd.cpp | 66 +- extern/newmat/tmte.cpp | 2 +- extern/newmat/tmtf.cpp | 6 +- extern/newmat/tmth.cpp | 36 +- extern/newmat/tmti.cpp | 1 - extern/newmat/tmtj.cpp | 2 +- extern/newmat/tmtk.cpp | 4 +- extern/newmat/tmtm.cpp | 7 +- nanobind_migration_notes.md | 103 +- tests/test_lsq.py | 9 +- tests/test_powderpattern.py | 49 +- tests/test_refinableobj.py | 7 +- tests/test_reflectionprofile.py | 8 +- tests/test_scatterer.py | 36 +- tests/test_virtualbase_forwarding.py | 14 +- 85 files changed, 7975 insertions(+), 6000 deletions(-) diff --git a/extern/cctbx/include/scitbx/array_family/small_reductions.h b/extern/cctbx/include/scitbx/array_family/small_reductions.h index 740ce39..8cb297e 100644 --- a/extern/cctbx/include/scitbx/array_family/small_reductions.h +++ b/extern/cctbx/include/scitbx/array_family/small_reductions.h @@ -152,4 +152,3 @@ namespace scitbx { namespace af { #endif // DOXYGEN_SHOULD_SKIP_THIS #endif // SCITBX_ARRAY_FAMILY_SMALL_REDUCTIONS_H - diff --git a/extern/cctbx/include/scitbx/array_family/tiny_reductions.h b/extern/cctbx/include/scitbx/array_family/tiny_reductions.h index f221b13..87f372a 100644 --- a/extern/cctbx/include/scitbx/array_family/tiny_reductions.h +++ b/extern/cctbx/include/scitbx/array_family/tiny_reductions.h @@ -152,4 +152,3 @@ namespace scitbx { namespace af { #endif // DOXYGEN_SHOULD_SKIP_THIS #endif // SCITBX_ARRAY_FAMILY_TINY_REDUCTIONS_H - diff --git a/extern/newmat/Makefile.in b/extern/newmat/Makefile.in index 23f623c..746fa24 100644 --- a/extern/newmat/Makefile.in +++ b/extern/newmat/Makefile.in @@ -113,4 +113,3 @@ submat.o: $(newmatxx) $(srcdir)/newmatrc.h $(srcdir)/controlw.h $(srcdir)/su svd.o: $(newmatxx) $(srcdir)/newmatrm.h $(srcdir)/precisio.h $(srcdir)/svd.cpp $(CXX) $(CXXFLAGS) $(OPT++DEFINES) $(OPT++INCLUDES) $(srcdir)/svd.cpp - diff --git a/extern/newmat/_newmat.dox b/extern/newmat/_newmat.dox index 9318ab1..094eaa5 100644 --- a/extern/newmat/_newmat.dox +++ b/extern/newmat/_newmat.dox @@ -22,8 +22,3 @@ ///rather inefficient. ///@} - - - - - diff --git a/extern/newmat/_rbd_com.dox b/extern/newmat/_rbd_com.dox index 4ddf908..b904c7d 100644 --- a/extern/newmat/_rbd_com.dox +++ b/extern/newmat/_rbd_com.dox @@ -19,8 +19,3 @@ ///@} - - - - - diff --git a/extern/newmat/bandmat.cpp b/extern/newmat/bandmat.cpp index 8d91526..db325f8 100644 --- a/extern/newmat/bandmat.cpp +++ b/extern/newmat/bandmat.cpp @@ -284,8 +284,8 @@ GeneralMatrix* BandLUMatrix::Evaluate(MatrixType mt) // could we use SetParameters instead of this void BandLUMatrix::get_aux(BandLUMatrix& X) { - X.d = d; X.sing = sing; X.storage2 = storage2; X.m1 = m1; X.m2 = m2; - if (tag_val == 0 || tag_val == 1) // reuse the array + X.d = d; X.sing = sing; X.storage2 = storage2; X.m1 = m1; X.m2 = m2; + if (tag_val == 0 || tag_val == 1) // reuse the array { REPORT X.indx = indx; indx = 0; @@ -333,7 +333,7 @@ void BandLUMatrix::operator=(const BandLUMatrix& gm) ((BandLUMatrix&)gm).get_aux(*this); Eq(gm); } - + @@ -714,5 +714,3 @@ Real SymmetricBandMatrix::sum() const #endif ///@} - - diff --git a/extern/newmat/cholesky.cpp b/extern/newmat/cholesky.cpp index e0df0fa..d8c4eaf 100644 --- a/extern/newmat/cholesky.cpp +++ b/extern/newmat/cholesky.cpp @@ -104,7 +104,7 @@ void update_Cholesky(UpperTriangularMatrix &chol, RowVector x) int nc = chol.Nrows(); ColumnVector cGivens(nc); cGivens = 0.0; ColumnVector sGivens(nc); sGivens = 0.0; - + for(int j = 1; j <= nc; ++j) // process the jth column of chol { // apply the previous Givens rotations k = 1,...,j-1 to column j @@ -129,12 +129,12 @@ void update_Cholesky(UpperTriangularMatrix &chol, RowVector x) void downdate_Cholesky(UpperTriangularMatrix &chol, RowVector x) { int nRC = chol.Nrows(); - + // solve R^T a = x LowerTriangularMatrix L = chol.t(); ColumnVector a(nRC); a = 0.0; int i, j; - + for (i = 1; i <= nRC; ++i) { // accumulate subtr sum @@ -177,7 +177,7 @@ void right_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l) { int nRC = chol.Nrows(); int i, j; - + // I. compute shift of column l to the kth position Matrix cholCopy = chol; // a. grab column l @@ -202,7 +202,7 @@ void right_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l) } // the kth entry of columnL is the new diagonal element in column k of cholCopy cholCopy(k,k) = columnL(k); - + // III. apply these Given's rotations to subsequent columns // for columns k+1,...,l-1 we only need to apply the last nGivens-(j-k) rotations for(j = k+1; j <= nRC; ++j) @@ -276,7 +276,7 @@ void left_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l) } chol << cholCopy; - + } diff --git a/extern/newmat/controlw.h b/extern/newmat/controlw.h index 416bd65..899bc07 100644 --- a/extern/newmat/controlw.h +++ b/extern/newmat/controlw.h @@ -53,4 +53,3 @@ class ControlWord #endif ///@} - diff --git a/extern/newmat/evalue.cpp b/extern/newmat/evalue.cpp index f3c7e34..98904ce 100644 --- a/extern/newmat/evalue.cpp +++ b/extern/newmat/evalue.cpp @@ -66,7 +66,7 @@ static void tred2(const SymmetricMatrix& A, DiagonalMatrix& D, f = *zij++; g = *ej - hh * f; *ej++ = g; Real* zjk = z + j*n; Real* zik = z + i*n; Real* ek = E.Store(); k = j+1; - while (k--) *zjk++ -= ( f*(*ek++) + g*(*zik++) ); + while (k--) *zjk++ -= ( f*(*ek++) + g*(*zik++) ); } } D.element(i) = h; @@ -206,10 +206,10 @@ static void tred3(const SymmetricMatrix& X, DiagonalMatrix& D, Real* dk = D.Store(); Real* ak = A.Store()+(j*(j+1))/2; Real g = 0.0; k = j; while (k--) g += *ak++ * *dk++; - k = i-j; int l = j; + k = i-j; int l = j; if (k) for (;;) { g += *ak * *dk++; if (!(--k)) break; ak += ++l; } g /= h; *ej++ = g; f += g * *dj++; - } + } Real hh = f / (2 * h); Real* ak = A.Store(); dj = D.Store(); ej = E.Store(); for (j = 0; j < i; j++) @@ -300,4 +300,3 @@ void eigenvalues(const SymmetricMatrix& X, DiagonalMatrix& D, #endif ///@} - diff --git a/extern/newmat/example.cpp b/extern/newmat/example.cpp index e671d0a..3182a36 100644 --- a/extern/newmat/example.cpp +++ b/extern/newmat/example.cpp @@ -223,7 +223,7 @@ void test4(Real* y, Real* x1, Real* x2, int nobs, int npred) cout << "\n\nTest 4 - QR triangularisation\n"; // QR triangularisation method - + // load data - 1s into col 1 of matrix int npred1 = npred+1; Matrix X(nobs,npred1); ColumnVector Y(nobs); @@ -251,7 +251,7 @@ void test4(Real* y, Real* x1, Real* x2, int nobs, int npred) for (int i=1; i<=npred1; i++) SE(i) = sqrt(D(i)*ResVar); cout << setw(11) << setprecision(5) << (A | SE) << endl; cout << "\nObservations, fitted value, residual value, hat value\n"; - cout << setw(9) << setprecision(3) << + cout << setw(9) << setprecision(3) << (X.columns(2,3) | Y | Fitted | Y1 | Hat.as_column()); cout << "\n\n"; } @@ -261,7 +261,7 @@ void test5(Real* y, Real* x1, Real* x2, int nobs, int npred) cout << "\n\nTest 5 - singular value\n"; // Singular value decomposition method - + // load data - 1s into col 1 of matrix int npred1 = npred+1; Matrix X(nobs,npred1); ColumnVector Y(nobs); @@ -288,7 +288,7 @@ void test5(Real* y, Real* x1, Real* x2, int nobs, int npred) for (int i=1; i<=npred1; i++) SE(i) = sqrt(D(i)*ResVar); cout << setw(11) << setprecision(5) << (A | SE) << endl; cout << "\nObservations, fitted value, residual value, hat value\n"; - cout << setw(9) << setprecision(3) << + cout << setw(9) << setprecision(3) << (X.columns(2,3) | Y | Fitted | Residual | Hat.as_column()); cout << "\n\n"; } diff --git a/extern/newmat/example.txt b/extern/newmat/example.txt index e2b1fcb..afcb787 100644 --- a/extern/newmat/example.txt +++ b/extern/newmat/example.txt @@ -8,21 +8,21 @@ Test 1 - traditional, bad Estimates and their standard errors - 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.39166 0.53188 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -32,20 +32,20 @@ Test 2 - traditional, OK Estimates and their standard errors 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -55,20 +55,20 @@ Test 3 - Cholesky Estimates and their standard errors 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -77,21 +77,21 @@ Test 4 - QR triangularisation Estimates and their standard errors - 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.39166 0.53188 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -100,21 +100,21 @@ Test 5 - singular value Estimates and their standard errors - 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.39166 0.53188 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 diff --git a/extern/newmat/garch.cpp b/extern/newmat/garch.cpp index 4643e6f..6f97b22 100644 --- a/extern/newmat/garch.cpp +++ b/extern/newmat/garch.cpp @@ -189,7 +189,7 @@ int main() } CatchAll { - cout << "\nProgram fails - exception generated\n\n"; + cout << "\nProgram fails - exception generated\n\n"; } return 0; } diff --git a/extern/newmat/garch.dat b/extern/newmat/garch.dat index 81f55b0..5c39412 100644 --- a/extern/newmat/garch.dat +++ b/extern/newmat/garch.dat @@ -1,502 +1,501 @@ 500 - 3.44443 -0.49800 - 1.43549 -0.49600 - 3.70477 -0.49400 - -3.82558 -0.49200 - 1.20130 -0.49000 - -2.62383 -0.48800 - -1.34321 -0.48600 - -0.35801 -0.48400 - -2.18813 -0.48200 - -1.98628 -0.48000 - -1.53262 -0.47800 - -1.45007 -0.47600 - -1.18593 -0.47400 - -0.55274 -0.47200 - -1.55943 -0.47000 - -3.10084 -0.46800 - 0.44254 -0.46600 - -0.63936 -0.46400 - 2.44989 -0.46200 - -2.14392 -0.46000 - 0.47310 -0.45800 - -1.64464 -0.45600 - 0.56628 -0.45400 - -0.80925 -0.45200 - -0.78961 -0.45000 - -1.12984 -0.44800 - -0.50715 -0.44600 - -1.75134 -0.44400 - -1.04231 -0.44200 - 0.94435 -0.44000 - 1.16306 -0.43800 - -2.87888 -0.43600 - -3.31084 -0.43400 - -3.06191 -0.43200 - 1.06977 -0.43000 - 3.50462 -0.42800 - 3.94848 -0.42600 - 1.56565 -0.42400 - -5.21742 -0.42200 - 1.94652 -0.42000 - -3.01182 -0.41800 - -3.88963 -0.41600 - -0.31319 -0.41400 - -5.71752 -0.41200 - -6.72218 -0.41000 - 3.23482 -0.40800 - 2.12675 -0.40600 - -0.10975 -0.40400 - -1.73790 -0.40200 - -0.86870 -0.40000 - -1.46022 -0.39800 - -0.22960 -0.39600 - 0.01596 -0.39400 - 0.00568 -0.39200 - -3.41221 -0.39000 - -0.47401 -0.38800 - -1.76305 -0.38600 - -0.49640 -0.38400 - -2.36184 -0.38200 - -0.09625 -0.38000 - -2.81448 -0.37800 - 3.14301 -0.37600 - 1.88025 -0.37400 - -2.61618 -0.37200 - -1.56239 -0.37000 - 0.95722 -0.36800 - 1.29773 -0.36600 - -1.45155 -0.36400 - -0.63342 -0.36200 - -0.78925 -0.36000 - 0.42473 -0.35800 - 1.39599 -0.35600 - 1.03934 -0.35400 - -0.11042 -0.35200 - 0.89123 -0.35000 - 0.93411 -0.34800 - 2.78027 -0.34600 - 3.37402 -0.34400 - -0.07986 -0.34200 - 0.79142 -0.34000 - -4.17148 -0.33800 - -1.26717 -0.33600 - -4.36262 -0.33400 - 1.17431 -0.33200 - -1.75656 -0.33000 - 0.40495 -0.32800 - 0.17572 -0.32600 - -0.27991 -0.32400 - -0.85524 -0.32200 - -1.23380 -0.32000 - -1.01889 -0.31800 - 1.08393 -0.31600 - -0.55989 -0.31400 - -1.91643 -0.31200 - -1.23897 -0.31000 - -0.85407 -0.30800 - 0.35218 -0.30600 - -1.57057 -0.30400 - 0.20665 -0.30200 - 0.19680 -0.30000 - 0.03116 -0.29800 - 0.09100 -0.29600 - 1.03416 -0.29400 - -0.16048 -0.29200 - -0.27530 -0.29000 - -0.11056 -0.28800 - -2.11332 -0.28600 - -0.51348 -0.28400 - -0.16360 -0.28200 - 1.30712 -0.28000 - -0.94392 -0.27800 - -0.06838 -0.27600 - -0.04095 -0.27400 - -2.00364 -0.27200 - 0.63950 -0.27000 - -1.02895 -0.26800 - -0.17454 -0.26600 - -0.86659 -0.26400 - 0.81698 -0.26200 - 0.51579 -0.26000 - -0.74525 -0.25800 - 2.43378 -0.25600 - 0.89364 -0.25400 - 1.81727 -0.25200 - -0.29667 -0.25000 - -0.99628 -0.24800 - 0.09452 -0.24600 - 1.73730 -0.24400 - 0.36819 -0.24200 - -1.56521 -0.24000 - 0.74916 -0.23800 - 0.56802 -0.23600 - -1.34157 -0.23400 - -0.65638 -0.23200 - -2.12183 -0.23000 - -2.35486 -0.22800 - -2.09369 -0.22600 - -3.30745 -0.22400 - -4.14763 -0.22200 - -3.56306 -0.22000 - 0.78907 -0.21800 - -3.74014 -0.21600 - -2.73770 -0.21400 - -4.43153 -0.21200 - -0.80243 -0.21000 - -0.17474 -0.20800 - -0.38250 -0.20600 - -0.98962 -0.20400 - -1.41965 -0.20200 - 0.90585 -0.20000 - 0.66850 -0.19800 - -0.81629 -0.19600 - -3.04422 -0.19400 - -0.94514 -0.19200 - 0.05209 -0.19000 - 0.21315 -0.18800 - -0.86960 -0.18600 - -1.72978 -0.18400 - -2.85623 -0.18200 - -3.15650 -0.18000 - -0.09176 -0.17800 - -1.27376 -0.17600 - -1.06533 -0.17400 - 1.21766 -0.17200 - 0.41706 -0.17000 - -0.30885 -0.16800 - 0.78344 -0.16600 - -1.76348 -0.16400 - 2.46496 -0.16200 - -0.32712 -0.16000 - 1.38586 -0.15800 - 0.33513 -0.15600 - 0.66116 -0.15400 - 0.92420 -0.15200 - -0.67200 -0.15000 - -0.90707 -0.14800 - -0.41053 -0.14600 - 0.62288 -0.14400 - 0.78497 -0.14200 - 0.99670 -0.14000 - -2.19972 -0.13800 - 0.21922 -0.13600 - -0.15003 -0.13400 - -0.72706 -0.13200 - 0.13596 -0.13000 - -0.00235 -0.12800 - 0.50025 -0.12600 - 0.80875 -0.12400 - -0.71010 -0.12200 - -3.85477 -0.12000 - 2.45549 -0.11800 - -2.87772 -0.11600 - 1.03987 -0.11400 - -1.41914 -0.11200 - -1.87414 -0.11000 - 1.32656 -0.10800 - 2.15281 -0.10600 - 3.25624 -0.10400 - -3.72420 -0.10200 - -4.01675 -0.10000 - 1.19241 -0.09800 - 0.35189 -0.09600 - -0.40223 -0.09400 - 0.84146 -0.09200 - 1.08746 -0.09000 - 2.20874 -0.08800 - -0.18822 -0.08600 - -1.29757 -0.08400 - -1.36022 -0.08200 - 0.54575 -0.08000 - -0.23008 -0.07800 - 0.00750 -0.07600 - 1.81600 -0.07400 - -0.07319 -0.07200 - 0.70587 -0.07000 - -2.67033 -0.06800 - 0.67446 -0.06600 - -0.21002 -0.06400 - 2.11396 -0.06200 - -0.94189 -0.06000 - 0.27803 -0.05800 - -0.92172 -0.05600 - 1.37776 -0.05400 - 2.72565 -0.05200 - 0.47208 -0.05000 - -3.33845 -0.04800 - -0.20695 -0.04600 - -2.18905 -0.04400 - -4.33413 -0.04200 - 0.17860 -0.04000 - -5.57817 -0.03800 - -0.32771 -0.03600 - 1.47321 -0.03400 - 2.33767 -0.03200 - 1.22282 -0.03000 - -1.48593 -0.02800 - 0.79435 -0.02600 - 0.54491 -0.02400 - 1.31706 -0.02200 - -1.26472 -0.02000 - -1.72634 -0.01800 - -3.85299 -0.01600 - 0.43717 -0.01400 - -3.39362 -0.01200 - -3.60823 -0.01000 - 0.18868 -0.00800 - 1.23035 -0.00600 - 1.70454 -0.00400 - -1.44766 -0.00200 - 0.99808 0.00000 - 0.24554 0.00200 - 1.44446 0.00400 - 0.96697 0.00600 - -3.30396 0.00800 - -5.97223 0.01000 - 1.22379 0.01200 - 6.00662 0.01400 - 4.43380 0.01600 - 2.01081 0.01800 - -2.74552 0.02000 - 1.19452 0.02200 - 3.81020 0.02400 - 2.04597 0.02600 - 0.66764 0.02800 - 2.68350 0.03000 - -2.85514 0.03200 - 0.21727 0.03400 - 1.88780 0.03600 - 2.23549 0.03800 - 1.57589 0.04000 - 1.92344 0.04200 - -1.78414 0.04400 - -0.67367 0.04600 - 0.19357 0.04800 - 1.00246 0.05000 - 2.13782 0.05200 - 1.90734 0.05400 - 0.43943 0.05600 - -0.55699 0.05800 - 1.76985 0.06000 - -0.77310 0.06200 - -0.33812 0.06400 - -0.85572 0.06600 - -2.49390 0.06800 - -3.17954 0.07000 - 2.86688 0.07200 - 2.03589 0.07400 - -1.34393 0.07600 - 1.01839 0.07800 - -0.15220 0.08000 - 1.17978 0.08200 - 1.96847 0.08400 - 1.90596 0.08600 - 3.72675 0.08800 - -0.65513 0.09000 - -1.45672 0.09200 - -0.08779 0.09400 - -0.39105 0.09600 - 1.88645 0.09800 - 2.34710 0.10000 - -2.65900 0.10200 - -0.47996 0.10400 - -2.51512 0.10600 - -3.59097 0.10800 - -1.62117 0.11000 - -2.43947 0.11200 - 3.50339 0.11400 - 3.05144 0.11600 - -2.73565 0.11800 - -1.31556 0.12000 - 1.85250 0.12200 - -1.03864 0.12400 - 0.79097 0.12600 - -0.12426 0.12800 - 0.48964 0.13000 - 1.42419 0.13200 - 0.55098 0.13400 - -0.78121 0.13600 - -0.01716 0.13800 - -1.27952 0.14000 - 1.91981 0.14200 - 0.25822 0.14400 - 0.68516 0.14600 - 1.25616 0.14800 - -1.40178 0.15000 - -0.99551 0.15200 - 1.45728 0.15400 - -1.66513 0.15600 - -1.20284 0.15800 - 1.84775 0.16000 - -1.91535 0.16200 - 0.34142 0.16400 - 1.90641 0.16600 - 1.55524 0.16800 - 1.77263 0.17000 - 1.25731 0.17200 - -0.66331 0.17400 - 0.93506 0.17600 - 0.87120 0.17800 - 0.73840 0.18000 - -1.48181 0.18200 - -1.76043 0.18400 - 0.96176 0.18600 - 1.29128 0.18800 - 1.20889 0.19000 - 0.78386 0.19200 - 1.54668 0.19400 - -0.25996 0.19600 - 0.93201 0.19800 - 1.30374 0.20000 - 2.23175 0.20200 - -0.42525 0.20400 - 1.12784 0.20600 - -0.42014 0.20800 - -0.00577 0.21000 - -1.14837 0.21200 - 2.48454 0.21400 - -0.51466 0.21600 - -0.06257 0.21800 - -1.25993 0.22000 - 1.26623 0.22200 - 3.05099 0.22400 - -1.84077 0.22600 - -0.36058 0.22800 - 2.65788 0.23000 - -0.17717 0.23200 - 1.68915 0.23400 - -1.53406 0.23600 - 1.78097 0.23800 - -1.24217 0.24000 - -4.17466 0.24200 - 0.80433 0.24400 - 0.70856 0.24600 - -0.96881 0.24800 - 0.87322 0.25000 - -2.45936 0.25200 - 2.95677 0.25400 - 1.81628 0.25600 - -0.85793 0.25800 - 1.02089 0.26000 - -1.05425 0.26200 - -0.29861 0.26400 - 1.69682 0.26600 - 1.07389 0.26800 - 0.22183 0.27000 - 1.72766 0.27200 - -0.99746 0.27400 - -2.14178 0.27600 - -1.67924 0.27800 - 1.56520 0.28000 - -0.86864 0.28200 - 2.65155 0.28400 - -2.27166 0.28600 - 0.68310 0.28800 - 0.84102 0.29000 - 0.64604 0.29200 - 0.68712 0.29400 - 1.56297 0.29600 - -0.68136 0.29800 - 1.25519 0.30000 - -1.38612 0.30200 - 2.36320 0.30400 - 5.40128 0.30600 - -1.14776 0.30800 - -1.36081 0.31000 - 0.07679 0.31200 - -0.17231 0.31400 - 1.19094 0.31600 - 0.09285 0.31800 - -0.85191 0.32000 - -0.43739 0.32200 - -0.22950 0.32400 - 2.21298 0.32600 - 0.75045 0.32800 - 0.97489 0.33000 - -0.62158 0.33200 - 1.10503 0.33400 - 0.36977 0.33600 - -0.32894 0.33800 - 2.13729 0.34000 - 4.42019 0.34200 - -2.80916 0.34400 - 2.28181 0.34600 - 2.59053 0.34800 - -1.52891 0.35000 - -1.35202 0.35200 - 1.27639 0.35400 - 0.28782 0.35600 - 0.83540 0.35800 - -0.32867 0.36000 - 1.16891 0.36200 - 0.02511 0.36400 - -0.71878 0.36600 - 0.69811 0.36800 - 1.29399 0.37000 - 0.86300 0.37200 - -0.12139 0.37400 - -0.28069 0.37600 - 3.07623 0.37800 - -2.91737 0.38000 - 0.16709 0.38200 - -1.60815 0.38400 - 0.02795 0.38600 - 1.19657 0.38800 - 0.04390 0.39000 - 0.95983 0.39200 - -1.83683 0.39400 - -1.69167 0.39600 - 3.15836 0.39800 - 2.24002 0.40000 - 0.45225 0.40200 - 1.35014 0.40400 - -1.67177 0.40600 - -0.97317 0.40800 - 4.20922 0.41000 - -0.03983 0.41200 - -0.35933 0.41400 - -1.49772 0.41600 - 2.72900 0.41800 - -2.61061 0.42000 - -0.26581 0.42200 - -4.30162 0.42400 - -3.55225 0.42600 - -5.60739 0.42800 - 2.26730 0.43000 - -0.05568 0.43200 - -0.14348 0.43400 - -1.73015 0.43600 - -1.01649 0.43800 - -2.39568 0.44000 - 3.41626 0.44200 - 2.23817 0.44400 - -1.02668 0.44600 - 3.18086 0.44800 - 0.71908 0.45000 - -0.37826 0.45200 - -0.39837 0.45400 - 0.50378 0.45600 - 0.38287 0.45800 - 2.95404 0.46000 - -1.16143 0.46200 - 0.89913 0.46400 - -0.82190 0.46600 - 1.30638 0.46800 - 0.89138 0.47000 - 0.85038 0.47200 - -1.38925 0.47400 - 3.74026 0.47600 - 4.60999 0.47800 - 1.31364 0.48000 - 5.17183 0.48200 - 1.82162 0.48400 - 1.09830 0.48600 - 1.36666 0.48800 - -0.09676 0.49000 - 0.74155 0.49200 - 1.21910 0.49400 - 1.20746 0.49600 - 0.82236 0.49800 - 1.54856 0.50000 - + 3.44443 -0.49800 + 1.43549 -0.49600 + 3.70477 -0.49400 + -3.82558 -0.49200 + 1.20130 -0.49000 + -2.62383 -0.48800 + -1.34321 -0.48600 + -0.35801 -0.48400 + -2.18813 -0.48200 + -1.98628 -0.48000 + -1.53262 -0.47800 + -1.45007 -0.47600 + -1.18593 -0.47400 + -0.55274 -0.47200 + -1.55943 -0.47000 + -3.10084 -0.46800 + 0.44254 -0.46600 + -0.63936 -0.46400 + 2.44989 -0.46200 + -2.14392 -0.46000 + 0.47310 -0.45800 + -1.64464 -0.45600 + 0.56628 -0.45400 + -0.80925 -0.45200 + -0.78961 -0.45000 + -1.12984 -0.44800 + -0.50715 -0.44600 + -1.75134 -0.44400 + -1.04231 -0.44200 + 0.94435 -0.44000 + 1.16306 -0.43800 + -2.87888 -0.43600 + -3.31084 -0.43400 + -3.06191 -0.43200 + 1.06977 -0.43000 + 3.50462 -0.42800 + 3.94848 -0.42600 + 1.56565 -0.42400 + -5.21742 -0.42200 + 1.94652 -0.42000 + -3.01182 -0.41800 + -3.88963 -0.41600 + -0.31319 -0.41400 + -5.71752 -0.41200 + -6.72218 -0.41000 + 3.23482 -0.40800 + 2.12675 -0.40600 + -0.10975 -0.40400 + -1.73790 -0.40200 + -0.86870 -0.40000 + -1.46022 -0.39800 + -0.22960 -0.39600 + 0.01596 -0.39400 + 0.00568 -0.39200 + -3.41221 -0.39000 + -0.47401 -0.38800 + -1.76305 -0.38600 + -0.49640 -0.38400 + -2.36184 -0.38200 + -0.09625 -0.38000 + -2.81448 -0.37800 + 3.14301 -0.37600 + 1.88025 -0.37400 + -2.61618 -0.37200 + -1.56239 -0.37000 + 0.95722 -0.36800 + 1.29773 -0.36600 + -1.45155 -0.36400 + -0.63342 -0.36200 + -0.78925 -0.36000 + 0.42473 -0.35800 + 1.39599 -0.35600 + 1.03934 -0.35400 + -0.11042 -0.35200 + 0.89123 -0.35000 + 0.93411 -0.34800 + 2.78027 -0.34600 + 3.37402 -0.34400 + -0.07986 -0.34200 + 0.79142 -0.34000 + -4.17148 -0.33800 + -1.26717 -0.33600 + -4.36262 -0.33400 + 1.17431 -0.33200 + -1.75656 -0.33000 + 0.40495 -0.32800 + 0.17572 -0.32600 + -0.27991 -0.32400 + -0.85524 -0.32200 + -1.23380 -0.32000 + -1.01889 -0.31800 + 1.08393 -0.31600 + -0.55989 -0.31400 + -1.91643 -0.31200 + -1.23897 -0.31000 + -0.85407 -0.30800 + 0.35218 -0.30600 + -1.57057 -0.30400 + 0.20665 -0.30200 + 0.19680 -0.30000 + 0.03116 -0.29800 + 0.09100 -0.29600 + 1.03416 -0.29400 + -0.16048 -0.29200 + -0.27530 -0.29000 + -0.11056 -0.28800 + -2.11332 -0.28600 + -0.51348 -0.28400 + -0.16360 -0.28200 + 1.30712 -0.28000 + -0.94392 -0.27800 + -0.06838 -0.27600 + -0.04095 -0.27400 + -2.00364 -0.27200 + 0.63950 -0.27000 + -1.02895 -0.26800 + -0.17454 -0.26600 + -0.86659 -0.26400 + 0.81698 -0.26200 + 0.51579 -0.26000 + -0.74525 -0.25800 + 2.43378 -0.25600 + 0.89364 -0.25400 + 1.81727 -0.25200 + -0.29667 -0.25000 + -0.99628 -0.24800 + 0.09452 -0.24600 + 1.73730 -0.24400 + 0.36819 -0.24200 + -1.56521 -0.24000 + 0.74916 -0.23800 + 0.56802 -0.23600 + -1.34157 -0.23400 + -0.65638 -0.23200 + -2.12183 -0.23000 + -2.35486 -0.22800 + -2.09369 -0.22600 + -3.30745 -0.22400 + -4.14763 -0.22200 + -3.56306 -0.22000 + 0.78907 -0.21800 + -3.74014 -0.21600 + -2.73770 -0.21400 + -4.43153 -0.21200 + -0.80243 -0.21000 + -0.17474 -0.20800 + -0.38250 -0.20600 + -0.98962 -0.20400 + -1.41965 -0.20200 + 0.90585 -0.20000 + 0.66850 -0.19800 + -0.81629 -0.19600 + -3.04422 -0.19400 + -0.94514 -0.19200 + 0.05209 -0.19000 + 0.21315 -0.18800 + -0.86960 -0.18600 + -1.72978 -0.18400 + -2.85623 -0.18200 + -3.15650 -0.18000 + -0.09176 -0.17800 + -1.27376 -0.17600 + -1.06533 -0.17400 + 1.21766 -0.17200 + 0.41706 -0.17000 + -0.30885 -0.16800 + 0.78344 -0.16600 + -1.76348 -0.16400 + 2.46496 -0.16200 + -0.32712 -0.16000 + 1.38586 -0.15800 + 0.33513 -0.15600 + 0.66116 -0.15400 + 0.92420 -0.15200 + -0.67200 -0.15000 + -0.90707 -0.14800 + -0.41053 -0.14600 + 0.62288 -0.14400 + 0.78497 -0.14200 + 0.99670 -0.14000 + -2.19972 -0.13800 + 0.21922 -0.13600 + -0.15003 -0.13400 + -0.72706 -0.13200 + 0.13596 -0.13000 + -0.00235 -0.12800 + 0.50025 -0.12600 + 0.80875 -0.12400 + -0.71010 -0.12200 + -3.85477 -0.12000 + 2.45549 -0.11800 + -2.87772 -0.11600 + 1.03987 -0.11400 + -1.41914 -0.11200 + -1.87414 -0.11000 + 1.32656 -0.10800 + 2.15281 -0.10600 + 3.25624 -0.10400 + -3.72420 -0.10200 + -4.01675 -0.10000 + 1.19241 -0.09800 + 0.35189 -0.09600 + -0.40223 -0.09400 + 0.84146 -0.09200 + 1.08746 -0.09000 + 2.20874 -0.08800 + -0.18822 -0.08600 + -1.29757 -0.08400 + -1.36022 -0.08200 + 0.54575 -0.08000 + -0.23008 -0.07800 + 0.00750 -0.07600 + 1.81600 -0.07400 + -0.07319 -0.07200 + 0.70587 -0.07000 + -2.67033 -0.06800 + 0.67446 -0.06600 + -0.21002 -0.06400 + 2.11396 -0.06200 + -0.94189 -0.06000 + 0.27803 -0.05800 + -0.92172 -0.05600 + 1.37776 -0.05400 + 2.72565 -0.05200 + 0.47208 -0.05000 + -3.33845 -0.04800 + -0.20695 -0.04600 + -2.18905 -0.04400 + -4.33413 -0.04200 + 0.17860 -0.04000 + -5.57817 -0.03800 + -0.32771 -0.03600 + 1.47321 -0.03400 + 2.33767 -0.03200 + 1.22282 -0.03000 + -1.48593 -0.02800 + 0.79435 -0.02600 + 0.54491 -0.02400 + 1.31706 -0.02200 + -1.26472 -0.02000 + -1.72634 -0.01800 + -3.85299 -0.01600 + 0.43717 -0.01400 + -3.39362 -0.01200 + -3.60823 -0.01000 + 0.18868 -0.00800 + 1.23035 -0.00600 + 1.70454 -0.00400 + -1.44766 -0.00200 + 0.99808 0.00000 + 0.24554 0.00200 + 1.44446 0.00400 + 0.96697 0.00600 + -3.30396 0.00800 + -5.97223 0.01000 + 1.22379 0.01200 + 6.00662 0.01400 + 4.43380 0.01600 + 2.01081 0.01800 + -2.74552 0.02000 + 1.19452 0.02200 + 3.81020 0.02400 + 2.04597 0.02600 + 0.66764 0.02800 + 2.68350 0.03000 + -2.85514 0.03200 + 0.21727 0.03400 + 1.88780 0.03600 + 2.23549 0.03800 + 1.57589 0.04000 + 1.92344 0.04200 + -1.78414 0.04400 + -0.67367 0.04600 + 0.19357 0.04800 + 1.00246 0.05000 + 2.13782 0.05200 + 1.90734 0.05400 + 0.43943 0.05600 + -0.55699 0.05800 + 1.76985 0.06000 + -0.77310 0.06200 + -0.33812 0.06400 + -0.85572 0.06600 + -2.49390 0.06800 + -3.17954 0.07000 + 2.86688 0.07200 + 2.03589 0.07400 + -1.34393 0.07600 + 1.01839 0.07800 + -0.15220 0.08000 + 1.17978 0.08200 + 1.96847 0.08400 + 1.90596 0.08600 + 3.72675 0.08800 + -0.65513 0.09000 + -1.45672 0.09200 + -0.08779 0.09400 + -0.39105 0.09600 + 1.88645 0.09800 + 2.34710 0.10000 + -2.65900 0.10200 + -0.47996 0.10400 + -2.51512 0.10600 + -3.59097 0.10800 + -1.62117 0.11000 + -2.43947 0.11200 + 3.50339 0.11400 + 3.05144 0.11600 + -2.73565 0.11800 + -1.31556 0.12000 + 1.85250 0.12200 + -1.03864 0.12400 + 0.79097 0.12600 + -0.12426 0.12800 + 0.48964 0.13000 + 1.42419 0.13200 + 0.55098 0.13400 + -0.78121 0.13600 + -0.01716 0.13800 + -1.27952 0.14000 + 1.91981 0.14200 + 0.25822 0.14400 + 0.68516 0.14600 + 1.25616 0.14800 + -1.40178 0.15000 + -0.99551 0.15200 + 1.45728 0.15400 + -1.66513 0.15600 + -1.20284 0.15800 + 1.84775 0.16000 + -1.91535 0.16200 + 0.34142 0.16400 + 1.90641 0.16600 + 1.55524 0.16800 + 1.77263 0.17000 + 1.25731 0.17200 + -0.66331 0.17400 + 0.93506 0.17600 + 0.87120 0.17800 + 0.73840 0.18000 + -1.48181 0.18200 + -1.76043 0.18400 + 0.96176 0.18600 + 1.29128 0.18800 + 1.20889 0.19000 + 0.78386 0.19200 + 1.54668 0.19400 + -0.25996 0.19600 + 0.93201 0.19800 + 1.30374 0.20000 + 2.23175 0.20200 + -0.42525 0.20400 + 1.12784 0.20600 + -0.42014 0.20800 + -0.00577 0.21000 + -1.14837 0.21200 + 2.48454 0.21400 + -0.51466 0.21600 + -0.06257 0.21800 + -1.25993 0.22000 + 1.26623 0.22200 + 3.05099 0.22400 + -1.84077 0.22600 + -0.36058 0.22800 + 2.65788 0.23000 + -0.17717 0.23200 + 1.68915 0.23400 + -1.53406 0.23600 + 1.78097 0.23800 + -1.24217 0.24000 + -4.17466 0.24200 + 0.80433 0.24400 + 0.70856 0.24600 + -0.96881 0.24800 + 0.87322 0.25000 + -2.45936 0.25200 + 2.95677 0.25400 + 1.81628 0.25600 + -0.85793 0.25800 + 1.02089 0.26000 + -1.05425 0.26200 + -0.29861 0.26400 + 1.69682 0.26600 + 1.07389 0.26800 + 0.22183 0.27000 + 1.72766 0.27200 + -0.99746 0.27400 + -2.14178 0.27600 + -1.67924 0.27800 + 1.56520 0.28000 + -0.86864 0.28200 + 2.65155 0.28400 + -2.27166 0.28600 + 0.68310 0.28800 + 0.84102 0.29000 + 0.64604 0.29200 + 0.68712 0.29400 + 1.56297 0.29600 + -0.68136 0.29800 + 1.25519 0.30000 + -1.38612 0.30200 + 2.36320 0.30400 + 5.40128 0.30600 + -1.14776 0.30800 + -1.36081 0.31000 + 0.07679 0.31200 + -0.17231 0.31400 + 1.19094 0.31600 + 0.09285 0.31800 + -0.85191 0.32000 + -0.43739 0.32200 + -0.22950 0.32400 + 2.21298 0.32600 + 0.75045 0.32800 + 0.97489 0.33000 + -0.62158 0.33200 + 1.10503 0.33400 + 0.36977 0.33600 + -0.32894 0.33800 + 2.13729 0.34000 + 4.42019 0.34200 + -2.80916 0.34400 + 2.28181 0.34600 + 2.59053 0.34800 + -1.52891 0.35000 + -1.35202 0.35200 + 1.27639 0.35400 + 0.28782 0.35600 + 0.83540 0.35800 + -0.32867 0.36000 + 1.16891 0.36200 + 0.02511 0.36400 + -0.71878 0.36600 + 0.69811 0.36800 + 1.29399 0.37000 + 0.86300 0.37200 + -0.12139 0.37400 + -0.28069 0.37600 + 3.07623 0.37800 + -2.91737 0.38000 + 0.16709 0.38200 + -1.60815 0.38400 + 0.02795 0.38600 + 1.19657 0.38800 + 0.04390 0.39000 + 0.95983 0.39200 + -1.83683 0.39400 + -1.69167 0.39600 + 3.15836 0.39800 + 2.24002 0.40000 + 0.45225 0.40200 + 1.35014 0.40400 + -1.67177 0.40600 + -0.97317 0.40800 + 4.20922 0.41000 + -0.03983 0.41200 + -0.35933 0.41400 + -1.49772 0.41600 + 2.72900 0.41800 + -2.61061 0.42000 + -0.26581 0.42200 + -4.30162 0.42400 + -3.55225 0.42600 + -5.60739 0.42800 + 2.26730 0.43000 + -0.05568 0.43200 + -0.14348 0.43400 + -1.73015 0.43600 + -1.01649 0.43800 + -2.39568 0.44000 + 3.41626 0.44200 + 2.23817 0.44400 + -1.02668 0.44600 + 3.18086 0.44800 + 0.71908 0.45000 + -0.37826 0.45200 + -0.39837 0.45400 + 0.50378 0.45600 + 0.38287 0.45800 + 2.95404 0.46000 + -1.16143 0.46200 + 0.89913 0.46400 + -0.82190 0.46600 + 1.30638 0.46800 + 0.89138 0.47000 + 0.85038 0.47200 + -1.38925 0.47400 + 3.74026 0.47600 + 4.60999 0.47800 + 1.31364 0.48000 + 5.17183 0.48200 + 1.82162 0.48400 + 1.09830 0.48600 + 1.36666 0.48800 + -0.09676 0.49000 + 0.74155 0.49200 + 1.21910 0.49400 + 1.20746 0.49600 + 0.82236 0.49800 + 1.54856 0.50000 diff --git a/extern/newmat/garch.txt b/extern/newmat/garch.txt index 328cccc..f7ef7c1 100644 --- a/extern/newmat/garch.txt +++ b/extern/newmat/garch.txt @@ -23,23 +23,21 @@ Converged estimates and standard errors - 1.56690 0.22311 - 0.80046 0.20274 - 0.45307 0.08428 - 0.34655 0.09081 + 1.56690 0.22311 + 0.80046 0.20274 + 0.45307 0.08428 + 0.34655 0.09081 correlation matrix - 1.00 0.00 -0.02 0.01 - 0.00 1.00 0.21 -0.81 - -0.02 0.21 1.00 -0.63 - 0.01 -0.81 -0.63 1.00 + 1.00 0.00 -0.02 0.01 + 0.00 1.00 0.21 -0.81 + -0.02 0.21 1.00 -0.63 + 0.01 -0.81 -0.63 1.00 inverse of correlation matrix - 1.00 0.03 0.04 0.04 - 0.03 4.77 2.28 5.28 - 0.04 2.28 2.73 3.55 - 0.04 5.28 3.55 7.48 - - + 1.00 0.03 0.04 0.04 + 0.03 4.77 2.28 5.28 + 0.04 2.28 2.73 3.55 + 0.04 5.28 3.55 7.48 diff --git a/extern/newmat/hholder.cpp b/extern/newmat/hholder.cpp index a1e10b8..04fba3a 100644 --- a/extern/newmat/hholder.cpp +++ b/extern/newmat/hholder.cpp @@ -232,12 +232,12 @@ void updateQRZT(Matrix& X, LowerTriangularMatrix& L) Tracer et("updateQRZT"); int n = X.Ncols(); int s = X.Nrows(); if (s != L.Nrows()) - Throw(ProgramException("Incompatible dimensions",X,L)); + Throw(ProgramException("Incompatible dimensions",X,L)); if (n == 0 || s == 0) return; Real* xi = X.Store(); int k; for (int i=0; iProtect(); return gm; } diff --git a/extern/newmat/newmat4.cpp b/extern/newmat/newmat4.cpp index 5c5cc41..34f6aca 100644 --- a/extern/newmat/newmat4.cpp +++ b/extern/newmat/newmat4.cpp @@ -200,12 +200,12 @@ CroutMatrix::CroutMatrix(const BaseMatrix& m) void CroutMatrix::get_aux(CroutMatrix& X) { X.d = d; X.sing = sing; - if (tag_val == 0 || tag_val == 1) // reuse the array + if (tag_val == 0 || tag_val == 1) // reuse the array { REPORT X.indx = indx; indx = 0; d = true; sing = true; return; } else if (nrows_val == 0) { REPORT indx = 0; d = true; sing = true; return; } else // copy the array - { + { REPORT Tracer tr("CroutMatrix::get_aux"); int *ix = new int [nrows_val]; MatrixErrorNoSpace(ix); @@ -259,7 +259,7 @@ ReturnMatrix GeneralMatrix::for_return() const Matrix::Matrix(Real a, int m, int n) : GeneralMatrix(m * n) { REPORT nrows_val=m; ncols_val=n; operator=(a); } - + Matrix::Matrix(const Real* a, int m, int n) : GeneralMatrix(m * n) { REPORT nrows_val=m; ncols_val=n; *this << a; } @@ -433,7 +433,7 @@ void Matrix::resize_keep(int nr, int nc) { Tracer tr("Matrix::resize_keep"); if (nr == nrows_val && nc == ncols_val) { REPORT return; } - + if (nr <= nrows_val && nc <= ncols_val) { REPORT @@ -456,7 +456,7 @@ void Matrix::resize_keep(int nr, int nc) X.submatrix(1,nr,1,nc) = submatrix(1,nr,1,nc); swap(X); } -} +} void SquareMatrix::resize_keep(int nr) { @@ -483,7 +483,7 @@ void SquareMatrix::resize_keep(int nr, int nc) if (nr != nc) Throw(NotSquareException(*this)); resize_keep(nr); } - + void SymmetricMatrix::resize_keep(int nr) { @@ -501,7 +501,7 @@ void SymmetricMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void UpperTriangularMatrix::resize_keep(int nr) { @@ -519,7 +519,7 @@ void UpperTriangularMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void LowerTriangularMatrix::resize_keep(int nr) { @@ -537,7 +537,7 @@ void LowerTriangularMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void DiagonalMatrix::resize_keep(int nr) { @@ -555,7 +555,7 @@ void DiagonalMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void RowVector::resize_keep(int nc) { @@ -599,7 +599,7 @@ void ColumnVector::resize_keep(int nr) X.rows(1,nrows_val) = *this; swap(X); } -} +} void ColumnVector::resize_keep(int nr, int nc) { @@ -683,7 +683,7 @@ MatrixBandWidth BandMatrix::bandwidth() const MatrixBandWidth BandLUMatrix::bandwidth() const { REPORT return MatrixBandWidth(m1,m2); } - + MatrixBandWidth GenericMatrix::bandwidth()const { REPORT return gm->bandwidth(); } @@ -1271,7 +1271,7 @@ void GeneralMatrix::swap(GeneralMatrix& gm) t = storage; storage = gm.storage; gm.storage = t; Real* s = store; store = gm.store; gm.store = s; } - + void nricMatrix::swap(nricMatrix& gm) { REPORT @@ -1339,7 +1339,7 @@ RealStarStar::RealStarStar(Matrix& A) MatrixErrorNoSpace(a); Real* d = A.data(); for (int i = 0; i < m; ++i) a[i] = d + i * n; -} +} ConstRealStarStar::ConstRealStarStar(const Matrix& A) { @@ -1351,7 +1351,7 @@ ConstRealStarStar::ConstRealStarStar(const Matrix& A) MatrixErrorNoSpace(a); const Real* d = A.data(); for (int i = 0; i < m; ++i) a[i] = d + i * n; -} +} diff --git a/extern/newmat/newmat5.cpp b/extern/newmat/newmat5.cpp index 703fb00..83b495b 100644 --- a/extern/newmat/newmat5.cpp +++ b/extern/newmat/newmat5.cpp @@ -303,7 +303,7 @@ GeneralMatrix* GetSubMatrix::Evaluate(MatrixType mt) else Compare(gm->Type().sub(), mt); GeneralMatrix* gmx = mt.New(row_number, col_number, this); int i = row_number; - MatrixRow mr(gm, LoadOnEntry, row_skip); + MatrixRow mr(gm, LoadOnEntry, row_skip); MatrixRow mrx(gmx, StoreOnExit+DirectPart); MatrixRowCol sub; while (i--) @@ -330,7 +330,7 @@ void GeneralMatrix::Add(GeneralMatrix* gm1, Real f) { *s++ = *s1++ + f; *s++ = *s1++ + f; *s++ = *s1++ + f; *s++ = *s1++ + f; } i = storage & 3; while (i--) *s++ = *s1++ + f; } - + void GeneralMatrix::Add(Real f) { REPORT @@ -338,7 +338,7 @@ void GeneralMatrix::Add(Real f) while (i--) { *s++ += f; *s++ += f; *s++ += f; *s++ += f; } i = storage & 3; while (i--) *s++ += f; } - + void GeneralMatrix::NegAdd(GeneralMatrix* gm1, Real f) { REPORT @@ -347,7 +347,7 @@ void GeneralMatrix::NegAdd(GeneralMatrix* gm1, Real f) { *s++ = f - *s1++; *s++ = f - *s1++; *s++ = f - *s1++; *s++ = f - *s1++; } i = storage & 3; while (i--) *s++ = f - *s1++; } - + void GeneralMatrix::NegAdd(Real f) { REPORT @@ -359,7 +359,7 @@ void GeneralMatrix::NegAdd(Real f) } i = storage & 3; while (i--) { *s = f - *s; s++; } } - + void GeneralMatrix::Negate(GeneralMatrix* gm1) { // change sign of elements @@ -369,7 +369,7 @@ void GeneralMatrix::Negate(GeneralMatrix* gm1) { *s++ = -(*s1++); *s++ = -(*s1++); *s++ = -(*s1++); *s++ = -(*s1++); } i = storage & 3; while(i--) *s++ = -(*s1++); } - + void GeneralMatrix::Negate() { REPORT @@ -378,7 +378,7 @@ void GeneralMatrix::Negate() { *s = -(*s); s++; *s = -(*s); s++; *s = -(*s); s++; *s = -(*s); s++; } i = storage & 3; while(i--) { *s = -(*s); s++; } } - + void GeneralMatrix::Multiply(GeneralMatrix* gm1, Real f) { REPORT @@ -387,7 +387,7 @@ void GeneralMatrix::Multiply(GeneralMatrix* gm1, Real f) { *s++ = *s1++ * f; *s++ = *s1++ * f; *s++ = *s1++ * f; *s++ = *s1++ * f; } i = storage & 3; while (i--) *s++ = *s1++ * f; } - + void GeneralMatrix::Multiply(Real f) { REPORT @@ -395,7 +395,7 @@ void GeneralMatrix::Multiply(Real f) while (i--) { *s++ *= f; *s++ *= f; *s++ *= f; *s++ *= f; } i = storage & 3; while (i--) *s++ *= f; } - + /************************ MatrixInput routines ****************************/ diff --git a/extern/newmat/newmat6.cpp b/extern/newmat/newmat6.cpp index eda3909..575ff08 100644 --- a/extern/newmat/newmat6.cpp +++ b/extern/newmat/newmat6.cpp @@ -351,7 +351,7 @@ void Matrix::operator=(const BaseMatrix& X) REPORT //CheckConversion(X); // MatrixConversionCheck mcc; Eq(X,MatrixType::Rt); -} +} void SquareMatrix::operator=(const BaseMatrix& X) { @@ -432,7 +432,7 @@ void CroutMatrix::operator=(const CroutMatrix& gm) ((CroutMatrix&)gm).get_aux(*this); Eq(gm); } - + diff --git a/extern/newmat/newmat7.cpp b/extern/newmat/newmat7.cpp index 5befa5d..17bd778 100644 --- a/extern/newmat/newmat7.cpp +++ b/extern/newmat/newmat7.cpp @@ -1033,7 +1033,7 @@ ReturnMatrix crossproduct_columns(const Matrix& A, const Matrix& B) Real* bn = b+n; Real* bn2 = bn+n; Real* cn = c+n; Real* cn2 = cn+n; - int i = n; + int i = n; while (i--) { *c++ = *an * *bn2 - *an2 * *bn; @@ -1050,4 +1050,3 @@ ReturnMatrix crossproduct_columns(const Matrix& A, const Matrix& B) #endif ///@} - diff --git a/extern/newmat/newmat8.cpp b/extern/newmat/newmat8.cpp index f48edc6..d3796a0 100644 --- a/extern/newmat/newmat8.cpp +++ b/extern/newmat/newmat8.cpp @@ -750,7 +750,7 @@ ReturnMatrix BaseMatrix::sum_square_rows() const int s = mr.Storage(); Real* in = mr.Data(); while (s--) sum += square(*in++); - ssq(i) = sum; + ssq(i) = sum; mr.Next(); } } @@ -795,7 +795,7 @@ ReturnMatrix BaseMatrix::sum_rows() const int s = mr.Storage(); Real* in = mr.Data(); while (s--) sum += *in++; - sum_vec(i) = sum; + sum_vec(i) = sum; mr.Next(); } } diff --git a/extern/newmat/newmatap.h b/extern/newmat/newmatap.h index dc88ac1..e6884d8 100644 --- a/extern/newmat/newmatap.h +++ b/extern/newmat/newmatap.h @@ -25,13 +25,13 @@ void QRZT(const Matrix&, Matrix&, Matrix&); void QRZ(Matrix&, UpperTriangularMatrix&); -void QRZ(const Matrix&, Matrix&, Matrix&); +void QRZ(const Matrix&, Matrix&, Matrix&); inline void QRZT(Matrix& X, Matrix& Y, LowerTriangularMatrix& L, Matrix& M) - { QRZT(X, L); QRZT(X, Y, M); } + { QRZT(X, L); QRZT(X, Y, M); } inline void QRZ(Matrix& X, Matrix& Y, UpperTriangularMatrix& U, Matrix& M) - { QRZ(X, U); QRZ(X, Y, M); } + { QRZ(X, U); QRZ(X, Y, M); } inline void HHDecompose(Matrix& X, LowerTriangularMatrix& L) { QRZT(X,L); } @@ -60,7 +60,7 @@ inline void UpdateQRZ(UpperTriangularMatrix& X, UpperTriangularMatrix& U) inline void UpdateQRZ(const UpperTriangularMatrix& X, Matrix& MX, Matrix& MU) { updateQRZ(X, MX, MU); } - + inline void UpdateQRZ(const Matrix& X, Matrix& MX, Matrix& MU) { updateQRZ(X, MX, MU); } @@ -68,7 +68,7 @@ inline void UpdateQRZ(const Matrix& X, Matrix& MX, Matrix& MU) // Matrix A's first n columns are orthonormal // so A.Columns(1,n).t() * A.Columns(1,n) is the identity matrix. // Fill out the remaining columns of A to make them orthonormal -// so A.t() * A is the identity matrix +// so A.t() * A is the identity matrix void extend_orthonormal(Matrix& A, int n); @@ -99,9 +99,9 @@ inline void RightCircularUpdateCholesky(UpperTriangularMatrix &chol, // a LEFT circular shift of the rows and columns from // 1,...,k-1,k,k+1,...l,l+1,...,p to // 1,...,k-1,k+1,...l,k,l+1,...,p to -void left_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l); +void left_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l); inline void LeftCircularUpdateCholesky(UpperTriangularMatrix &chol, - int k, int l) { left_circular_update_Cholesky(chol, k, l); } + int k, int l) { left_circular_update_Cholesky(chol, k, l); } void SVD(const Matrix&, DiagonalMatrix&, Matrix&, Matrix&, @@ -268,5 +268,3 @@ ReturnMatrix Helmert_transpose(const Matrix& Y, bool full=false); ///@} - - diff --git a/extern/newmat/newmatex.cpp b/extern/newmat/newmatex.cpp index d00496e..0df2657 100644 --- a/extern/newmat/newmatex.cpp +++ b/extern/newmat/newmatex.cpp @@ -322,4 +322,3 @@ void BaseMatrix::IEQND() const #ifdef use_namespace } #endif - diff --git a/extern/newmat/newmatnl.cpp b/extern/newmat/newmatnl.cpp index 56c52ea..35c4b46 100644 --- a/extern/newmat/newmatnl.cpp +++ b/extern/newmat/newmatnl.cpp @@ -237,7 +237,7 @@ void MLE_D_FI::Fit(ColumnVector& Parameters) FindMaximum2::Fit(Parameters,Lim); cout << "\nConverged" << endl; } - + void MLE_D_FI::MakeCovariance() { if (Covariance.Nrows()==0) @@ -252,7 +252,7 @@ void MLE_D_FI::MakeCovariance() void MLE_D_FI::GetStandardErrors(ColumnVector& SEX) { MakeCovariance(); SEX = SE.AsColumn(); } - + void MLE_D_FI::GetCorrelations(SymmetricMatrix& Corr) { MakeCovariance(); Corr << SE.i() * Covariance * SE.i(); } diff --git a/extern/newmat/newmatnl.h b/extern/newmat/newmatnl.h index 0a41584..7477d01 100644 --- a/extern/newmat/newmatnl.h +++ b/extern/newmat/newmatnl.h @@ -249,7 +249,7 @@ class NonLinearLeastSquares : public FindMaximum2 // The next class is the prototype class for calculating the // log-likelihood. -// I assume first derivatives are available and something like the +// I assume first derivatives are available and something like the // Fisher Information or variance/covariance matrix of the first // derivatives or minus the matrix of second derivatives is // available. This matrix must be positive definite. @@ -324,4 +324,3 @@ class MLE_D_FI : public FindMaximum2 ///@} - diff --git a/extern/newmat/newmatrm.cpp b/extern/newmat/newmatrm.cpp index 726d10f..66e5e27 100644 --- a/extern/newmat/newmatrm.cpp +++ b/extern/newmat/newmatrm.cpp @@ -141,7 +141,7 @@ void ComplexScale(RectMatrixCol& U, RectMatrixCol& V, Real x, Real y) Tracer tr("newmatrm"); Throw(InternalException("Dimensions differ in ComplexScale")); } - Real* u = U.store; Real* v = V.store; + Real* u = U.store; Real* v = V.store; int su = U.spacing; int sv = V.spacing; //while (n--) //{ diff --git a/extern/newmat/newmatrm.h b/extern/newmat/newmatrm.h index d8494d7..ad64e18 100644 --- a/extern/newmat/newmatrm.h +++ b/extern/newmat/newmatrm.h @@ -130,7 +130,7 @@ inline void GivensRotation(Real cGivens, Real sGivens, Real& x, Real& y) Real tmp1 = -sGivens * x + cGivens * y; x = tmp0; y = tmp1; } - + inline void GivensRotationR(Real cGivens, Real sGivens, Real& x, Real& y) { // also change sign of y @@ -138,7 +138,7 @@ inline void GivensRotationR(Real cGivens, Real sGivens, Real& x, Real& y) Real tmp0 = cGivens * x + sGivens * y; Real tmp1 = sGivens * x - cGivens * y; x = tmp0; y = tmp1; -} +} diff --git a/extern/newmat/nl_ex.cpp b/extern/newmat/nl_ex.cpp index 25c9a01..66cf73b 100644 --- a/extern/newmat/nl_ex.cpp +++ b/extern/newmat/nl_ex.cpp @@ -95,7 +95,7 @@ int my_main() #ifdef DO_FREE_CHECK FreeCheck::Status(); #endif - + return 0; } @@ -113,13 +113,10 @@ int main() } CatchAll { - cout << "\nProgram fails - exception generated\n\n"; + cout << "\nProgram fails - exception generated\n\n"; } return 0; } ///@} - - - diff --git a/extern/newmat/nl_ex.txt b/extern/newmat/nl_ex.txt index 46dcbf4..5ca98e7 100644 --- a/extern/newmat/nl_ex.txt +++ b/extern/newmat/nl_ex.txt @@ -13,30 +13,29 @@ Converged Estimates and standard errors - 19.77 0.73 - -23.63 0.82 - 0.35 0.04 + 19.77 0.73 + -23.63 0.82 + 0.35 0.04 Residual s.d. = 0.42 CorrelationMatrix - 1.00 -0.05 -0.91 - -0.05 1.00 -0.31 - -0.91 -0.31 1.00 + 1.00 -0.05 -0.91 + -0.05 1.00 -0.31 + -0.91 -0.31 1.00 X, Y, Residual, Hat - 1.00 3.20 0.10 0.89 - 2.00 7.90 -0.11 0.33 - 3.00 11.10 -0.38 0.39 - 4.00 14.50 0.58 0.35 - 6.00 16.70 -0.16 0.32 - 8.00 18.30 -0.02 0.73 + 1.00 3.20 0.10 0.89 + 2.00 7.90 -0.11 0.33 + 3.00 11.10 -0.38 0.39 + 4.00 14.50 0.58 0.35 + 6.00 16.70 -0.16 0.32 + 8.00 18.30 -0.02 0.73 Var/cov - 0.5295 -0.0324 -0.0250 - -0.0324 0.6668 -0.0096 - -0.0250 -0.0096 0.0014 - + 0.5295 -0.0324 -0.0250 + -0.0324 0.6668 -0.0096 + -0.0250 -0.0096 0.0014 diff --git a/extern/newmat/nm11.htm b/extern/newmat/nm11.htm index f34829a..495eef3 100644 --- a/extern/newmat/nm11.htm +++ b/extern/newmat/nm11.htm @@ -1,743 +1,1046 @@ - - - - - - - - - -Newmat11 documentation - - - - - -

Documentation for newmat11, a matrix library in C++

-

next - skip - -up - start
-return to online documentation page

-

Copyright (C) 2008: R B Davies

-

20 November, 2008.

- - - - - -
1. -Introduction
-2. Getting started
-3. Reference manual
-4. -Error messages
-5. Design of the library
-6. Function summary
-7. Change History
-8. Problem report form
-

 

-

This is the how to use documentation for newmat plus some -background information on its design.

-

There is additional support material on my web site. -

-

Navigation:  This page is arranged in sections, -sub-sections and sub-sub-sections; four cross-references are given at the top -of these. Next takes you through the sections, sub-sections and -sub-sub-sections in order. Skip goes to the next section, sub-section or -sub-sub-section at the same level in the hierarchy as the section, sub-section -or sub-sub-section that you are currently reading. Up takes you up one -level in the hierarchy and start gets you back here.

-

Please read the sections on customising and -compilers before -attempting to compile newmat.

-

1. Introduction

-

next - skip - -up - start

- - - - - -
1.1 -Conditions of use
-1.2 Description
-1.3 Is this the library for you?
-1.4 Other matrix libraries
1.5 -Where to find this library
-1.6 How to contact the author
-1.7 References
-

1.1 Conditions of use

-

next - skip - -up - start

-
-

I place no restrictions on the use of newmat except that I take no liability for any problems that may arise from its use, -distribution or other dealings with it.

-

-You can use it in your commercial projects (as well as your non-commercial -projects).

-

-You can make and distribute modified or merged versions. You can -include parts of it in your own software.

-

-If you distribute modified or merged versions, please make it clear -which parts are mine and which parts are modified.

-

-For a substantially modified version, simply note that it is, in -part, derived from my software. A comment in the code will be -sufficient.

-

-The software is provided as is, without warranty of any kind.

-

-Please understand that there may still be bugs and errors. Use at -your own risk. I (Robert Davies) take no responsibility for any errors -or omissions in this package or for any misfortune that may befall you -or others as a result of your use, distribution or other dealings with it.


-

Please report bugs to me at robert at statsresearch.co.nz   -[replace at by you-know-what-character in the email address].

-

When reporting a bug please tell me which C++ compiler you are using, and -what version. Also give me details of your computer. And tell me which version -of newmat (e.g. newmat03 or newmat04) you are using and its date. Note any changes -you have made to my code. If at all possible give me a piece of code -illustrating the bug. See the problem report form.

-

Please do report bugs to me.

-

1.2 General description -

-

next - skip - -up - start

-

The package is intended for scientists and engineers who need to manipulate -a variety of types of matrices using standard matrix operations. Emphasis is on -the kind of operations needed in statistical calculations such as least -squares, linear equation solve and eigenvalues.

-

It supports matrix types

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Matrixrectangular matrix
SquareMatrixsquare matrix
nricMatrixfor use with Numerical Recipes in C programs
UpperTriangularMatrix 
LowerTriangularMatrix 
DiagonalMatrix 
SymmetricMatrix 
BandMatrix 
UpperBandMatrixupper triangular band matrix
LowerBandMatrixlower triangular band matrix
SymmetricBandMatrix 
RowVectorderived from Matrix
ColumnVectorderived from Matrix
IdentityMatrixdiagonal matrix, elements have same value
-
-

Only one element type (float or double) is supported.

-

The package includes the operations *, +, -, -Kronecker product, Schur product, concatenation, inverse, transpose, conversion between types, submatrix, -determinant, Cholesky decomposition, QR decomposition, singular value -decomposition, eigenvalues of a symmetric matrix, sorting, fast Fourier -transform, printing and an interface with Numerical Recipes in C.

-

It is intended for matrices in the range 10 x 10 to the maximum size your -machine will accommodate in a single array. The number of elements in an array -cannot exceed the maximum size of an int. The package will work for very -small matrices but becomes rather inefficient. Some of the factorisation -functions are not (yet) optimised for paged memory and so become inefficient -when used with very large matrices.

-

A lazy evaluation approach to evaluating matrix expressions is used -to improve efficiency and reduce the use of temporary storage.

-

I have tested versions of the package on variety of compilers and platforms -including Borland, Gnu, Microsoft and Sun. For more details -see the section on compilers.

-

1.3 Is this the library for -you?

-

next - skip - -up - start

-

Do you

-
    -
  • understand * to mean matrix multiply and not element by element -multiply
  • -
  • need matrix operators such as * and + defined as -operators so you can write things like X = A * (B + C);
  • -
  • need a variety of types of matrices (but not sparse)
  • -
  • need only one element type (float or double)
  • -
  • work with matrices in the range 10 x 10 up to what can be stored in memory -
  • -
  • tolerate a moderately large but not huge package
  • -
  • need high quality but not necessarily the latest numerical methods.
  • -
-

Then newmat may be the right matrix library for you.

-

1.4 Other matrix libraries -

-

next - skip - -up - start

-

For details of other C++ matrix libraries look at -http://www.robertnz.net/cpp_site.html. -Look at the section lists of libraries which gives the locations of -several very comprehensive lists of matrix and other C++ libraries and at the -section source code. Or just search on Google.

-

1.5 Where to find this -library

-

next - skip - -up - start

- -

1.6 How to contact the -author

-

next - skip - -up - start

-
   Robert Davies
+
+
+
+  
+    
+    
+    
+
+    Newmat11 documentation
+    
+    
+  
+
+  
+    

+ Documentation for newmat11, a matrix library in C++ +

+

+ next - skip - + up - start
+ return to online documentation page +

+

Copyright (C) 2008: R B Davies

+

20 November, 2008.

+ + + + + +
+ 1. Introduction
+ 2. Getting started
+ 3. Reference manual
+ 4. Error messages +
+ 5. Design of the library
+ 6. Function summary
+ 7. Change History
+ 8. Problem report form +
+

 

+

+ This is the how to use documentation for newmat plus some + background information on its design. +

+

+ There is additional support material on my web site. +

+

+ Navigation:  This page is arranged in sections, sub-sections and + sub-sub-sections; four cross-references are given at the top of these. + Next takes you through the sections, sub-sections and + sub-sub-sections in order. Skip goes to the next section, + sub-section or sub-sub-section at the same level in the hierarchy as the + section, sub-section or sub-sub-section that you are currently reading. + Up takes you up one level in the hierarchy and start gets + you back here. +

+

+ Please read the sections on customising and + compilers before attempting to compile + newmat. +

+

1. Introduction

+

+ next - skip - + up - start +

+ + + + + +
+ 1.1 Conditions of use
+ 1.2 Description
+ 1.3 Is this the library for you?
+ 1.4 Other matrix libraries +
+ 1.5 Where to find this library
+ 1.6 How to contact the author
+ 1.7 References +
+

1.1 Conditions of use

+

+ next - skip - + up - start +

+
+

+ I place no restrictions on the use of newmat except that I take no + liability for any problems that may arise from its use, distribution or + other dealings with it. +

+

+

+ You can use it in your commercial projects (as well as your non-commercial + projects). +

+ +

+

+ You can make and distribute modified or merged versions. You can include + parts of it in your own software. +

+ +

+

+ If you distribute modified or merged versions, please make it clear which + parts are mine and which parts are modified. +

+ +

+

+ For a substantially modified version, simply note that it is, in part, + derived from my software. A comment in the code will be sufficient. +

+ +

+

The software is provided as is, without warranty of any kind.

+

+

+ Please understand that there may still be bugs and errors. Use at your own + risk. I (Robert Davies) take no responsibility for any errors or omissions + in this package or for any misfortune that may befall you or others as a + result of your use, distribution or other dealings with it. +

+ +
+

+ Please report bugs to me at + robert at statsresearch.co.nz   [replace at by + you-know-what-character in the email address]. +

+

+ When reporting a bug please tell me which C++ compiler you are using, and + what version. Also give me details of your computer. And tell me which + version of newmat (e.g. newmat03 or newmat04) you are using and its + date. Note any changes you have made to my code. If at all possible give + me a piece of code illustrating the bug. See the + problem report form. +

+

Please do report bugs to me.

+

1.2 General description

+

+ next - skip - + up - start +

+

+ The package is intended for scientists and engineers who need to + manipulate a variety of types of matrices using standard matrix + operations. Emphasis is on the kind of operations needed in statistical + calculations such as least squares, linear equation solve and eigenvalues. +

+

It supports matrix types

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Matrixrectangular matrix
SquareMatrixsquare matrix
nricMatrixfor use with Numerical Recipes in C programs
UpperTriangularMatrix 
LowerTriangularMatrix 
DiagonalMatrix 
SymmetricMatrix 
BandMatrix 
UpperBandMatrixupper triangular band matrix
LowerBandMatrixlower triangular band matrix
SymmetricBandMatrix 
RowVectorderived from Matrix
ColumnVectorderived from Matrix
IdentityMatrixdiagonal matrix, elements have same value
+
+

Only one element type (float or double) is supported.

+

+ The package includes the operations *, +, -, + Kronecker product, Schur product, concatenation, inverse, transpose, + conversion between types, submatrix, determinant, Cholesky decomposition, + QR decomposition, singular value decomposition, eigenvalues of a symmetric + matrix, sorting, fast Fourier transform, printing and an interface with + Numerical Recipes in C. +

+

+ It is intended for matrices in the range 10 x 10 to the maximum size your + machine will accommodate in a single array. The number of elements in an + array cannot exceed the maximum size of an int. The package will + work for very small matrices but becomes rather inefficient. Some of the + factorisation functions are not (yet) optimised for paged memory and so + become inefficient when used with very large matrices. +

+

+ A lazy evaluation approach to evaluating matrix expressions is used + to improve efficiency and reduce the use of temporary storage. +

+

+ I have tested versions of the package on variety of compilers and + platforms including Borland, Gnu, Microsoft and Sun. For more details see + the section on compilers. +

+

1.3 Is this the library for you?

+

+ next - skip - + up - start +

+

Do you

+
    +
  • + understand * to mean matrix multiply and not element by element + multiply +
  • +
  • + need matrix operators such as * and + defined as + operators so you can write things like X = A * (B + C); +
  • +
  • need a variety of types of matrices (but not sparse)
  • +
  • need only one element type (float or double)
  • +
  • + work with matrices in the range 10 x 10 up to what can be stored in + memory +
  • +
  • tolerate a moderately large but not huge package
  • +
  • + need high quality but not necessarily the latest numerical methods. +
  • +
+

Then newmat may be the right matrix library for you.

+

1.4 Other matrix libraries

+

+ next - skip - + up - start +

+

+ For details of other C++ matrix libraries look at + http://www.robertnz.net/cpp_site.html. Look at the section lists of libraries which gives the locations + of several very comprehensive lists of matrix and other C++ libraries and + at the section source code. Or just search on + Google. +

+

1.5 Where to find this library

+

+ next - skip - + up - start +

+ +

1.6 How to contact the author

+

+ next - skip - + up - start +

+
+   Robert Davies
    16 Gloucester Street
    Wilton
    Wellington
    New Zealand
 
-   Internet: robert at statsresearch.co.nz
- -[replace at by you-know-what.] - - -

1.7 References

-

next - skip - -up - start

-
    -
  • The matrix LU decomposition is from Golub, G.H. & Van Loan, C.F. -(1996), Matrix Computations, published by Johns Hopkins University -Press.
  • -
  • Part of the matrix inverse/solve routine is adapted from Press, Flannery, -Teukolsky, Vetterling (1988), Numerical Recipes in C, published by the -Cambridge University Press.
  • -
  • Many of the advanced matrix routines are adapted from routines in Wilkinson -and Reinsch (1971), Handbook for Automatic Computation, Vol II, Linear -Algebra published by Springer Verlag.
  • -
  • The fast Fourier transform is adapted from Carl de Boor (1980), Siam J -Sci Stat Comput, pp173-8 and the fast trigonometric transforms from Charles -Van Loan (1992) in Computational frameworks for the fast Fourier -transform published by SIAM.
  • -
  • The sort function is derived from Sedgewick, Robert (1992), Algorithms -in C++ published by Addison Wesley.
  • -
-

For references about Newmat see

-
    -
  • Davies, R.B. (1994) Writing a matrix package in C++. In OON-SKI'94: The -second annual object-oriented numerics conference, pp 207-213. Rogue Wave -Software, Corvallis.
  • -
  • Eddelbuttel, Dirk (1996) Object-oriented econometrics: matrix programming -in C++ using GCC and Newmat. Journal of Applied Econometrics, Vol 11, No 2, pp -199-209.
  • -
-

2. Getting started

-

next - skip - -up - start

- - - - - -
2.1 Overview
-2.2 Make files
-2.3 Customising
-2.4 Compilers
-2.5 Updating from previous versions
-2.6 Catching exceptions
2.7 Examples
-2.8 Testing
-2.9 Bugs
-2.10 Problem areas
-2.11 Files in newmat11
- 
-

2.1 Overview

-

next - skip - -up - start

-

I use .h as the suffix of definition files and .cpp as the suffix of C++ -source files.

-

You will need to compile all the *.cpp files listed as program files in the -files section to get the complete package. Ideally you -should store the resulting object files as a library. The tmt*.cpp files are -used for testing, example.cpp is an example and sl_ex.cpp, nl_ex.cpp and garch.cpp are examples -of the non-linear solve and optimisation routines. A -demonstration and test of the exception mechanism is in test_exc.cpp. The files -nm_ex1.cpp, nm_ex2.cpp and nm_ex3.cpp contain more simple examples.

-

I include a number of make files for compiling the example and the -test package. See the section on make files for details. -Alternatively, with the PC compilers, its pretty quick just to load all the files in the -interactive environments by pointing and clicking.

-

Use the large or win32 console model when you are using a PC. Do not -outline inline functions. You may need to increase the stack size on -older operating systems or compilers.

-

Your source files that access the newmat will need to #include one or more -of the following files.

- - - - - - - - - - - - - - - - - - - - - -
include.hto access just the compiler options
newmat.hto access just the main matrix library (includes include.h)
newmatap.hto access the advanced matrix routines such as Cholesky decomposition, QR -triangularisation etc (includes newmat.h)
newmatio.hto access the output routines (includes newmat.h) You -can use this only with compilers that support the standard input/output -routines including manipulators (all recent compilers)
newmatnl.hto access the non-linear optimisation routines (includes newmat.h)
-

See the section on customising to see how to edit -include.h for your environment and the section on compilers for any special problems with the compiler you -are using.

-

2.2 Make files

-

next - skip - -up - start

-

I have included make files for compiling my test and example programs for -various versions of CC, Borland, Microsoft, Open Watcom, Intel and Gnu compilers. You -can generate make files for a number of other compilers with my -genmake utility. Make files provide -a way of compiling your programs without using the IDE that comes with -PC compilers. See the files section for details.

-

PC

-

I include make files for various versions of Borland, Microsoft and Intel -compilers. With the -Borland compiler you will need to edit it to show where -you have stored your Borland compiler. For make files for other compilers use my -genmake utility. To compile my test and example -programs use Borland 5.5 (Builder 5) use

-
   make -f nm_b55.mak
-

or with Borland 5.6 (Builder 6) use

-
   make -f nm_b56.mak
-

or with Microsoft VC++ 6 or 7 use

-
   nmake -f nm_m6.mak
-

There are some more notes in the -genmake documentation about using these make files.

-

Unix

-

The make file for the Unix CC compilers link a .cxx file to each .cpp -file since some of these compilers do not recognise .cpp as a legitimate -extension for a C++ file. I suggest you delete this part of the make -file and, if necessary, rename the .cpp files to something your compiler -recognises.

-

My make file for Gnu GCC on Unix systems is for use with -gmake rather than make. I assume your compiler recognises the -.cpp extension. Ordinary make works with it on the Sun but did not the -Silicon Graphics or HP machines when I had access to them, many years ago. On Linux use make.

-

My make file for the CC compilers works with the ordinary make.

-

To compile everything with the CC compiler use

-
   make -f nm_cc.mak
-
- -

or for the gnu compiler use

-
   make -f nm_gnu.mak
-
- -

There is a line in the make file for CC rm -f $*.cxx. Some systems -won't accept this line and you will need to delete it. In this case, if you -have a bad compile and you are using my scheme for linking .cxx files, you will -need to delete the .cxx file link generated by that compile before you can do -the next one.

-

2.3 Customising

-

next - skip - -up - start

-

The file include.h sets a variety of options including several -compiler dependent options. You may need to edit include.h to get the options -you require. If you are using a compiler different from one I have worked with -you may have to set up a new section in include.h appropriate for your -compiler.

-

Borland, Gnu, Microsoft and Watcom are recognised automatically. If -none of these are recognised a default set of options is used. These are fine -for AT&T, HPUX and Sun C++. If you using a compiler I don't know about you -may have to write a new set of options.

-

There is an option in include.h for selecting whether you use compiler -supported exceptions, simulated exceptions, or disable exceptions. I now set - compiler supported exceptions as the default. Use the option for -compiler supported exceptions if and only if you have set the option on -your compiler to recognise exceptions. Disabling exceptions sometimes helps -with compilers that are incompatible with my exception simulation scheme.

-

Activate the appropriate statement to make the element type float or -double. I suggest you leave it at double.

-

The option DO_FREE_CHECK is used for tracking memory -leaks and normally should not be activated.

-

Activate SETUP_C_SUBSCRIPTS if you want to use traditional C style -element access. Note that this does not change -the starting point for indices when you are using round brackets for accessing -elements or selecting submatrices. It does enable you to use C style square -brackets. This also activates additional constructors for Matrix, ColumnVector -and RowVector to simplify use with Numerical Recipes in C++.

-

Activate #define use_namespace if you want to use namespaces. Do this only if you are sure your compiler -supports namespaces. If you do turn this option on, be prepared to turn it off -again if the compiler reports inaccessible variables or the linker reports -missing links.

-

Activate #define _STANDARD_ to use the standard names for the -included files and to find the floating point precision data using the floating -point standard. This will work with most recent compilers and is done -automatically for Borland, Gnu, Intel and Microsoft compilers.

-

If you haven't defined _STANDARD_ and are using a compiler that -include.h does not recognise and you want to pick up the floating point -precision data from float.h then activate #define use_float_h. -Otherwise the floating point precision data will be accessed from -values.h. You may need to do this with computers from Digital, in -particular.

-

There is a line

-
   //#define set_unix_options
-

You can activate this if you are using a Linux or Unix system. It is not used -by Newmat but is used by some of my other programs.

-

2.4 Compilers

-

next - skip - -up - start

- - - - - -
-2.4.1 AT&T
-2.4.2 Borland
-2.4.3 Gnu G++
-2.4.4 HPUX
-2.4.5 Intel
-2.4.6 Microsoft
-2.4.7 Sun
-2.4.8 Watcom
-

I have tested this library on a number of compilers. Here are the levels of -success and any special considerations. In most cases I have chosen code that -works under all the compilers I have access to, but I have had to include some -specific work-arounds for some compilers. For the newest PC versions, I use a Pentium -4 computer running windows XP or Linux -(Red Hat workstation version). The Unix versions are on a Sun Sparc -station. Thanks to Victoria University for access to the Sparc.

-

I have set up a block of code for each of the compilers in include.h. Turbo, -Borland, Gnu, Microsoft and Watcom are recognised automatically. There is a -default option that works for AT&T, Sun C++ and HPUX. So you don't -have to make any changes for these compilers. Otherwise you may have to build -your own set of options in include.h.

-

2.4.1 AT&T

-

next - skip - -up - start

-

The AT&T compiler used to be available on a wide variety of Unix -workstations. I don't know if anyone still uses it. However the AT&T options are -the default if your compiler is not recognised.

-

AT&T C++ 2.1; 3.0.1 on a Sun: Previous versions worked on these -compilers, which I no longer have access to.

-

In AT&T 2.1 you may get an error when you use an expression for the -single argument when constructing a Vector or DiagonalMatrix or one of the -Triangular Matrices. You need to evaluate the expression separately.

-

2.4.2 Borland

-

next - skip - -up - start

-

Newer compilers

-

Borland Builder version 8. My tests here have been compiling from a -make file using nm_b58.mak and making a console program. This works fine -except that my values of LnMinimum and LnMaximum in precisio.h -are not correct.

-

Borland Builder version 6: My tests have been on the personal -version. See the notes for version 5. If you are -compiling with a make file you can use nm_b56.mak as a model. You can set -the newmat options to use namespace and the standard library. If you are -compiling a GUI program you may need to comment out the line defining -TypeDefException in include.h. I don't believe exceptions work -completely correctly in either version 5 or version 6. However, this does not -seem to be a problem with my use of them in newmat.

-

Borland Builder version 5: This works fine in console mode and no -special editing of the source codes is required. I haven't tested it in GUI -mode. You can set the newmat options to use namespace and the standard library. You -should turn off the Borland option to use pre-compiled headers. There -are notes on compiling with the IDE on my website. -Alternatively you can use the nm_b55.mak make file.

-

Borland Builder version 4: I have successfully used this on older -versions of newmat using the -console wizard (menu item file/new - select new tab). Use compiler -exceptions. Suppose you are compiling my test program tmt. Rename my -main() function in tmt.cpp to my_main(). Rename -tmt.cpp to tmt_main.cpp. Borland will generate a new file -tmt.cpp containing their main() function. Put the line int -my_main(); above this function and put return my_main(); into the -body of main().

-

Borland compiler version 5.5: this is the free C++ compiler available -from Borland's web site. I suggest you use -the compiler supported exceptions and turn on standard in include.h. You -can use the make file nm_b55.mak after editing to correct the file locations for -your system.

-

Older compilers

-

Borland C++ 5.02:

-

I am not longer checking compatibility with this compiler.

-

Use the large or 32 bit flat model. If you are not debugging, turn off the -options that collect debugging information. Use my simulated exceptions.

-

When running my test program under ms-dos you may run out of memory. Either -compile the test routine to run under easywin or use simulated exceptions -rather than the built in exceptions.

-

If you can, upgrade to windows 95 or window NT and use the 32 bit console -model.

-

If you are using the 16 bit large model, don't forget to keep all matrices -less than 64K bytes in length (90x90 for a rectangular matrix if you are using -double as your element type). Otherwise your program will crash -without warning or explanation. You will need to break the tmt set of test files into several parts to get the program -to fit into your computer and run without stack overflow.

-

You can generate make files for versions 5 with my -genmake utility.

-

Borland C++ 3 and 4.

-

The program used to compile in version 3.1 if you enable the simulated booleans -- comment out the line #define bool_LIB 0 in include.h -and use the simulated exceptions. I haven't checked the latest versions -of Newmat. The main test program is too large to run -unless you break it up into several parts. I haven't tried it under version 4.

-

2.4.3 Gnu G++

-

next - skip - -up - start

-

Gnu G++ 3, 4 (Linux), 3 (Sun): These work OK. If you are using a much earlier version -see if you can upgrade. It  used to work with 2.95 and 2.96 but I don't -have access to these now. You can't use standard with the 2.9X -versions. The namespace option worked with 2.96 on Linux but not with 2.95 on -the Sun. Standard is automatically turned on with the 3.X.

-

This version of Newmat is not compatible with versions 2.6 or earlier.

-

2.4.4 HP-UX

-

next - skip - -up - start

-

HP 9000 series HP-UX. I no longer have access to this compiler. Newmat09 -worked without problems with the simulated exceptions; haven't tried the -built-in exceptions.

-

With recent versions of the compiler you may get warning messages like -Unsafe cast between pointers/references to incomplete classes. At -present, I think these can be ignored.

- -

2.4.5 Intel

-

next - skip - -up - start

- -

Newmat works correctly with the Intel 10 C++ compiler for Windows and Linux. (Not tested for the other versions). Standard is -automatically turned on for both the Linux versions and Windows versions. If -this causes a problem for the version you are using you can find the lines in -include.h that control this and comment them out. Note that the Intel compiler for -Linux is free for non-commercial use. (One of the versions of 8.1 gave a -warning message every time I had something like -Real x; ... if (x==0.0) ..., which was often. This is now seems to be fixed.)

- -

2.4.6 Microsoft

-

next - skip - -up - start

-

Newer versions

-

See my web site for instructions how to work -Microsoft's IDE.

-

Microsoft Visual C++ 7, 7.1, 8: These work OK. All my tests have -been in console mode. You can turn on my namespace option. Standard is turned on -by default for these versions.

-

Microsoft Visual C++ 6: Get the latest service pack. I have tried this -in console mode and it seems to work satisfactorily. Use the compiler supported exceptions. You may be able to -use the namespace and standard options. If you want to work under MFC -you may need to #include "stdafx.h" at the beginning of each .cpp file -(or turn off precompiled headers).

-

Microsoft Visual C++ 5: I have tried this in console mode on previous -versions of Newmat. It -seems to work satisfactorily. There may be a problem with namespace (fixed by Service Pack 3?). Turn optimisation -off. Use the compiler supported exceptions. If -you want to work under MFC  -you may need to #include "stdafx.h" at the -beginning of each .cpp file (or turn off precompiled headers).

-

Older versions

-

I doubt whether these will work.

-

2.4.7 Sun

-

next - skip - -up - start

-

Sun C++ (version = ?): This seems to work fine with -compiler supported exceptions. Sun C++ (version -5): There was a problem with exceptions. If you use my simulated -exceptions the non-linear optimisation programs hang. If you use the compiler -supported exceptions my tmt and test_exc programs crash. You should -disable exceptions.

-

2.4.8 Watcom

-

next - skip - -up - start

-

Open Watcom (version 1.7a): this works. You can set the standard -option in include.h. The scientific and fixed -manipulators don't work.

-

Watcom C++ (version 10a): this used to work, I don't know if it works -now.

-

2.5 Updating from previous -versions

-

next - skip - -up - start

-

Newmat11 - if you are upgrading from earlier versions note the -following:

-
    -
  • The class Exception in myexcept.h has been replaced by - BaseException and a typedef statement included so programs that use - the Exception class will still work. If the Exception class was - causing a problem comment out the line defining TypeDefException in - include.h.
  • -
  • Newmat11 does not support the TEMP_DESTROYED_QUICKLY options so won't work - with very old versions of Gnu G++
  • -
  • Old AT&T work-arounds are removed
  • -
  • The simulated Booleans class is now stored at the end of include.h. In - general, I am not testing with compilers that don't support bool.
  • -
  • QRZ and QRZT no longer throw an exception if they generate a singular - triangular matrix
  • -
  • Converting functions to lower case. Both the old and new names will work. See the list of - functions for new and old names
  • -
  • nm_i5.mak, nm_il5.mak replaced by nm_i8.mak, - nm_il8.mak
  • -
  • extra file nm_misc.cpp to be included in compilation
  • -
  • scientific and fixed manipulators now recognised in output - statements. If you want fixed output and have been using - scientific in a previous output statement, you may need to include the - fixed manipulator. (Doesn't work in Visual C++, version 6 and open - Watcom).
  • -
-

Newmat10 includes new maxima, minima, -determinant, dot product and Frobenius norm functions, a -faster FFT, revised make files for GCC -and CC compilers, several corrections, new ReSize function, IdentityMatrix -and Kronecker Product. Singular values from -SVD are sorted. The program files include a new file, newfft.cpp, so you -will need to include this in the list of files in your IDE and make files. There -is also a new test file tmtm.cpp. -Pointer arithmetic now mostly meets requirements of -standard. You can use << to load data into rows -of a matrix. The default options in include.h have been -changed. If you are updating from a beta version of newmat09 look through the -next section as there were some late changes to newmat09.

-

If you are upgrading from newmat08 note the following: -

-
    -
  • Boolean, TRUE, FALSE are now bool, true, false. See -customising if your compiler supports the bool class. -
  • -
  • ReDimension is now ReSize. -
  • -
  • The simulated exception package has -been updated.
  • -
  • Operators ==, !=, +=, --=, *=, |=, &= are now supported as -binary matrix operators.
  • -
  • A+=f, A-=f, A*=f, A/=f, -f+A, f-A, f*A are supported for A -matrix, f scalar.
  • -
  • Fast trigonometric transforms. -
  • -
  • Reverse function for reversing order of -elements in a vector or matrix.
  • -
  • IsSingular function.
  • -
  • An option is included for defining namespaces.
  • -
  • Dummy inequality operators are defined for compatibility -with the STL.
  • -
  • The row/column classes in newmat3.cpp have been modified to -improve efficiency and correct an invalid use of pointer arithmetic. Most users -won't be using these classes explicitly; if you are, please contact me for -details of the changes.
  • -
  • Matrix LU decomposition rewritten (faster for large arrays). -
  • -
  • The sort function rewritten (faster).
  • -
  • The documentation files newmata.txt and newmatb.txt have -been amalgamated and both are included in the hypertext version.
  • -
  • Some of the make files reorganised -again.
  • -
-

If you are upgrading from newmat07 note the following: -

-
    -
  • .cxx files are now .cpp files. Some versions of won't accept -.cpp. The make files for Gnu and AT&T link the .cpp files to .cxx -files before compilation and delete the links after compilation.
  • -
  • An option in include.h allows you to -use compiler supported exceptions, simulated exceptions or disable exceptions. -Edit the file include.h to select one of these three options. Don't simulate -exceptions if you have set your compiler's option to implement exceptions. -
  • -
  • New QR decomposition functions. -
  • -
  • A non-linear least squares class. -
  • -
  • No need to explicitly set the AT&T option in include.h. -
  • -
  • Concatenation and elementwise -multiplication.
  • -
  • A new GenericMatrix class. -
  • -
  • Sum function.
  • -
  • Some of the make files reorganised. -
  • -
-

If you are upgrading from newmat06 note the following: -

-
    -
  • If you are using << to load a Real into a submatrix -change this to =.
  • -
-

If you are upgrading from newmat03 or newmat04 -note the following

-
    -
  • .hxx files are now .h files
  • -
  • real changed to Real
  • -
  • BOOL changed to Boolean
  • -
  • CopyToMatrix changed to AsMatrix, etc
  • -
  • real(A) changed to A.AsScalar()
  • -
-

The current version is quite a bit longer that newmat04, so -if you are almost out of space with newmat04, don't throw newmat04 away until -you have checked your program will work under this version.

-

See the change history for other changes.

-

2.6 Catching exceptions

-

next - skip - -up - start

-

This section applies particularly to people using compiler supported -exceptions rather than my simulated exceptions.

-
-

If newmat detects an error it will throw an exception. It is important that -you catch this exception and print the error message. Otherwise you will get an -unhelpful message like abnormal termination.

-
-

I suggest you set up your -main program like 

-
#define WANT_STREAM             // or #include <iostream>
+   Internet: robert at statsresearch.co.nz
+ + [replace at by you-know-what.] + +

1.7 References

+

+ next - skip - + up - start +

+
    +
  • + The matrix LU decomposition is from Golub, G.H. & Van Loan, C.F. + (1996), Matrix Computations, published by Johns Hopkins + University Press. +
  • +
  • + Part of the matrix inverse/solve routine is adapted from Press, + Flannery, Teukolsky, Vetterling (1988), Numerical Recipes in C, + published by the Cambridge University Press. +
  • +
  • + Many of the advanced matrix routines are adapted from routines in + Wilkinson and Reinsch (1971), + Handbook for Automatic Computation, Vol II, Linear Algebra + published by Springer Verlag. +
  • +
  • + The fast Fourier transform is adapted from Carl de Boor (1980), + Siam J Sci Stat Comput, pp173-8 and the fast trigonometric + transforms from Charles Van Loan (1992) in + Computational frameworks for the fast Fourier transform published + by SIAM. +
  • +
  • + The sort function is derived from Sedgewick, Robert (1992), + Algorithms in C++ published by Addison Wesley. +
  • +
+

For references about Newmat see

+
    +
  • + Davies, R.B. (1994) Writing a matrix package in C++. In OON-SKI'94: The + second annual object-oriented numerics conference, pp 207-213. Rogue + Wave Software, Corvallis. +
  • +
  • + Eddelbuttel, Dirk (1996) Object-oriented econometrics: matrix + programming in C++ using GCC and Newmat. Journal of Applied + Econometrics, Vol 11, No 2, pp 199-209. +
  • +
+

2. Getting started

+

+ next - skip - + up - start +

+ + + + + +
+ 2.1 Overview
+ 2.2 Make files
+ 2.3 Customising
+ 2.4 Compilers
+ 2.5 Updating from previous versions
+ 2.6 Catching exceptions +
+ 2.7 Examples
+ 2.8 Testing
+ 2.9 Bugs
+ 2.10 Problem areas
+ 2.11 Files in newmat11
+   +
+

2.1 Overview

+

+ next - skip - + up - start +

+

+ I use .h as the suffix of definition files and .cpp as the suffix of C++ + source files. +

+

+ You will need to compile all the *.cpp files listed as program files in + the files section to get the complete package. + Ideally you should store the resulting object files as a library. The + tmt*.cpp files are used for testing, example.cpp is + an example and sl_ex.cpp, nl_ex.cpp and garch.cpp + are examples of the non-linear solve and + optimisation routines. A demonstration and test of the exception mechanism + is in test_exc.cpp. The files nm_ex1.cpp, nm_ex2.cpp and nm_ex3.cpp + contain more simple examples. +

+

+ I include a number of make files for compiling the example and the + test package. See the section on make files for + details. Alternatively, with the PC compilers, its pretty quick just to + load all the files in the interactive environments by pointing and + clicking. +

+

+ Use the large or win32 console model when you are using a PC. Do not + outline inline functions. You may need to increase the stack size + on older operating systems or compilers. +

+

+ Your source files that access the newmat will need to #include one or more + of the following files. +

+ + + + + + + + + + + + + + + + + + + + + +
include.hto access just the compiler options
newmat.hto access just the main matrix library (includes include.h)
newmatap.h + to access the advanced matrix routines such as Cholesky decomposition, + QR triangularisation etc (includes newmat.h) +
newmatio.h + to access the output routines (includes + newmat.h) You can use this only with compilers that support the + standard input/output routines including manipulators (all recent + compilers) +
newmatnl.h + to access the non-linear optimisation routines (includes newmat.h) +
+

+ See the section on customising to see how to edit + include.h for your environment and the section on + compilers for any special problems with the + compiler you are using. +

+

2.2 Make files

+

+ next - skip - + up - start +

+

+ I have included make files for compiling my test and example + programs for various versions of CC, Borland, Microsoft, Open Watcom, + Intel and Gnu compilers. You can generate make files for a number of other + compilers with my genmake utility. + Make files provide a way of compiling your programs without using + the IDE that comes with PC compilers. See the + files section for details. +

+

PC

+

+ I include make files for various versions of Borland, Microsoft and Intel + compilers. With the Borland compiler you will need to edit it to show + where you have stored your Borland compiler. For make files for other + compilers use my genmake utility. To compile my + test and example programs use Borland 5.5 (Builder 5) use +

+
   make -f nm_b55.mak
+

or with Borland 5.6 (Builder 6) use

+
   make -f nm_b56.mak
+

or with Microsoft VC++ 6 or 7 use

+
   nmake -f nm_m6.mak
+

+ There are some more notes in the + genmake documentation about using these make + files. +

+

Unix

+

+ The make file for the Unix CC compilers link a .cxx file to each + .cpp file since some of these compilers do not recognise .cpp as a + legitimate extension for a C++ file. I suggest you delete this part of the + make file and, if necessary, rename the .cpp files to something + your compiler recognises. +

+

+ My make file for Gnu GCC on Unix systems is for use with + gmake rather than make. I assume your compiler + recognises the .cpp extension. Ordinary make works with it on the + Sun but did not the Silicon Graphics or HP machines when I had access to + them, many years ago. On Linux use make. +

+

My make file for the CC compilers works with the ordinary make.

+

To compile everything with the CC compiler use

+
+   make -f nm_cc.mak
+
+ +

or for the gnu compiler use

+
+   make -f nm_gnu.mak
+
+ +

+ There is a line in the make file for CC rm -f $*.cxx. Some + systems won't accept this line and you will need to delete it. In this + case, if you have a bad compile and you are using my scheme for linking + .cxx files, you will need to delete the .cxx file link generated by that + compile before you can do the next one. +

+

2.3 Customising

+

+ next - skip - + up - start +

+

+ The file include.h sets a variety of options including several + compiler dependent options. You may need to edit include.h to get the + options you require. If you are using a compiler different from one I have + worked with you may have to set up a new section in include.h appropriate + for your compiler. +

+

+ Borland, Gnu, Microsoft and Watcom are recognised automatically. If none + of these are recognised a default set of options is used. These are fine + for AT&T, HPUX and Sun C++. If you using a compiler I don't know about + you may have to write a new set of options. +

+

+ There is an option in include.h for selecting whether you use compiler + supported exceptions, simulated exceptions, or disable exceptions. I now + set compiler supported exceptions as the default. Use the option + for compiler supported exceptions if and only if you have set the + option on your compiler to recognise exceptions. Disabling exceptions + sometimes helps with compilers that are incompatible with my exception + simulation scheme. +

+

+ Activate the appropriate statement to make the element type + float or double. I suggest you leave it at double. +

+

+ The option DO_FREE_CHECK is used for tracking + memory leaks and normally should not be activated. +

+

+ Activate SETUP_C_SUBSCRIPTS if you want to use traditional C style + element access. Note that this does + not change the starting point for indices when you are using round + brackets for accessing elements or selecting submatrices. It does enable + you to use C style square brackets. This also activates additional + constructors for Matrix, ColumnVector and RowVector to simplify use with + Numerical Recipes in C++. +

+

+ Activate #define use_namespace if you want to use + namespaces. Do this only if you are sure your + compiler supports namespaces. If you do turn this option on, be prepared + to turn it off again if the compiler reports inaccessible variables or the + linker reports missing links. +

+

+ Activate #define _STANDARD_ to use the standard names for the + included files and to find the floating point precision data using the + floating point standard. This will work with most recent compilers and is + done automatically for Borland, Gnu, Intel and Microsoft compilers. +

+

+ If you haven't defined _STANDARD_ and are using a compiler that + include.h does not recognise and you want to pick up the floating + point precision data from float.h then activate + #define use_float_h. Otherwise the floating point precision data + will be accessed from values.h. You may need to do this with + computers from Digital, in particular. +

+

There is a line

+
   //#define set_unix_options
+

+ You can activate this if you are using a Linux or Unix system. It is not + used by Newmat but is used by some of my other programs. +

+

2.4 Compilers

+

+ next - skip - + up - start +

+ + + + + +
+ 2.4.1 AT&T
+ 2.4.2 Borland
+ 2.4.3 Gnu G++
+ 2.4.4 HPUX +
+ 2.4.5 Intel
+ 2.4.6 Microsoft
+ 2.4.7 Sun
+ 2.4.8 Watcom +
+

+ I have tested this library on a number of compilers. Here are the levels + of success and any special considerations. In most cases I have chosen + code that works under all the compilers I have access to, but I have had + to include some specific work-arounds for some compilers. For the newest + PC versions, I use a Pentium 4 computer running windows XP or Linux (Red + Hat workstation version). The Unix versions are on a Sun Sparc station. + Thanks to Victoria University for access to the Sparc. +

+

+ I have set up a block of code for each of the compilers in include.h. + Turbo, Borland, Gnu, Microsoft and Watcom are recognised automatically. + There is a default option that works for AT&T, Sun C++ and HPUX. So + you don't have to make any changes for these compilers. Otherwise you may + have to build your own set of options in include.h. +

+

2.4.1 AT&T

+

+ next - skip - + up - start +

+

+ The AT&T compiler used to be available on a wide variety of Unix + workstations. I don't know if anyone still uses it. However the AT&T + options are the default if your compiler is not recognised. +

+

+ AT&T C++ 2.1; 3.0.1 on a Sun: Previous versions worked on these + compilers, which I no longer have access to. +

+

+ In AT&T 2.1 you may get an error when you use an expression for the + single argument when constructing a Vector or DiagonalMatrix or one of the + Triangular Matrices. You need to evaluate the expression separately. +

+

2.4.2 Borland

+

+ next - skip - + up - start +

+

Newer compilers

+

+ Borland Builder version 8. My tests here have been compiling from a + make file using nm_b58.mak and making a console program. This + works fine except that my values of LnMinimum and + LnMaximum in precisio.h are not correct. +

+

+ Borland Builder version 6: My tests have been on the + personal version. See the notes for version 5. If you are compiling + with a make file you can use nm_b56.mak as a model. You can set the + newmat options to use namespace and the standard library. If you + are compiling a GUI program you may need to comment out the line defining + TypeDefException in include.h. I don't believe exceptions + work completely correctly in either version 5 or version 6. However, this + does not seem to be a problem with my use of them in newmat. +

+

+ Borland Builder version 5: This works fine in console mode and no + special editing of the source codes is required. I haven't tested it in + GUI mode. You can set the newmat options to use namespace and the + standard library. + + You should turn off the Borland option to use pre-compiled + headers. + There are notes on compiling with the IDE on my + website. Alternatively you can use the + nm_b55.mak make file. +

+

+ Borland Builder version 4: I have successfully used this on older + versions of newmat using the console wizard (menu item file/new - select + new tab). Use compiler exceptions. Suppose you are compiling my test + program tmt. Rename my main() function in tmt.cpp to + my_main(). Rename tmt.cpp to tmt_main.cpp. Borland + will generate a new file tmt.cpp containing their + main() function. Put the line int my_main(); above this + function and put return my_main(); into the body of + main(). +

+

+ Borland compiler version 5.5: this is the free C++ compiler + available from Borland's web site. I suggest you use the compiler + supported exceptions and turn on standard in include.h. You can use + the make file nm_b55.mak after editing to correct the file + locations for your system. +

+

Older compilers

+

Borland C++ 5.02:

+

I am not longer checking compatibility with this compiler.

+

+ Use the large or 32 bit flat model. If you are not debugging, turn off the + options that collect debugging information. Use my simulated exceptions. +

+

+ When running my test program under ms-dos you may run out of memory. + Either compile the test routine to run under easywin or use + simulated exceptions rather than the built in exceptions. +

+

+ If you can, upgrade to windows 95 or window NT and use the 32 bit console + model. +

+

+ If you are using the 16 bit large model, don't forget to keep all matrices + less than 64K bytes in length (90x90 for a rectangular matrix if you are + using double as your element type). Otherwise your program will + crash without warning or explanation. You will need to break the + tmt set of test files into several parts to get the + program to fit into your computer and run without stack overflow. +

+

+ You can generate make files for versions 5 with my + genmake utility. +

+

Borland C++ 3 and 4.

+

+ The program used to compile in version 3.1 if you enable the + simulated booleans - comment out the line + #define bool_LIB 0 in include.h and use the + simulated exceptions. I haven't checked the latest versions of + Newmat. The main test program is too large to run unless you break it up + into several parts. I haven't tried it under version 4. +

+

2.4.3 Gnu G++

+

+ next - skip - + up - start +

+

+ Gnu G++ 3, 4 (Linux), 3 (Sun): These work OK. If you are using a + much earlier version see if you can upgrade. It  used to work with + 2.95 and 2.96 but I don't have access to these now. You can't use + standard with the 2.9X versions. The namespace option worked with + 2.96 on Linux but not with 2.95 on the Sun. Standard is automatically + turned on with the 3.X. +

+

+ This version of Newmat is not compatible with versions 2.6 or earlier. +

+

2.4.4 HP-UX

+

+ next - skip - + up - start +

+

+ HP 9000 series HP-UX. I no longer have access to this compiler. Newmat09 + worked without problems with the simulated exceptions; haven't tried the + built-in exceptions. +

+

+ With recent versions of the compiler you may get warning messages like + Unsafe cast between pointers/references to incomplete classes. At + present, I think these can be ignored. +

+ +

2.4.5 Intel

+

+ next - skip - + up - start +

+ +

+ Newmat works correctly with the Intel 10 C++ compiler for Windows and + Linux. (Not tested for the other versions). Standard is automatically + turned on for both the Linux versions and Windows versions. If this causes + a problem for the version you are using you can find the lines in + include.h that control this and comment them out. Note that the + Intel compiler for Linux is free for non-commercial use. (One of + the versions of 8.1 gave a warning message every time I had something like + Real x; ... if (x==0.0) ..., which was often. This is now seems + to be fixed.) +

+ +

2.4.6 Microsoft

+

+ next - skip - + up - start +

+

Newer versions

+

+ See my web site for instructions how to work + Microsoft's IDE. +

+

+ Microsoft Visual C++ 7, 7.1, 8: These work OK. All my tests have + been in console mode. You can turn on my namespace option. Standard is + turned on by default for these versions. +

+

+ Microsoft Visual C++ 6: Get the latest service pack. I have + tried this in console mode and it seems to work satisfactorily. Use the + compiler supported exceptions. You may be able to use the namespace and + standard options. If you want to work under MFC you may need to + #include "stdafx.h" at the beginning of each .cpp file + (or turn off precompiled headers). +

+

+ Microsoft Visual C++ 5: I have tried this in console mode on + previous versions of Newmat. It seems to work satisfactorily. There may be + a problem with namespace (fixed by Service Pack 3?). + Turn optimisation off. Use the compiler supported exceptions. If + you want to work under MFC  you may need to + #include "stdafx.h" at the beginning of each .cpp file + (or turn off precompiled headers). +

+

Older versions

+

I doubt whether these will work.

+

2.4.7 Sun

+

+ next - skip - + up - start +

+

+ Sun C++ (version = ?): This seems to work fine with compiler + supported exceptions. Sun C++ (version 5): There was a problem with + exceptions. If you use my simulated exceptions the non-linear optimisation + programs hang. If you use the compiler supported exceptions my tmt and + test_exc programs crash. You should disable exceptions. +

+

2.4.8 Watcom

+

+ next - skip - + up - start +

+

+ Open Watcom (version 1.7a): this works. You can set the standard + option in include.h. The scientific and + fixed manipulators don't work. +

+

+ Watcom C++ (version 10a): this used to work, I don't know if it + works now. +

+

2.5 Updating from previous versions

+

+ next - skip - + up - start +

+

+ Newmat11 - if you are upgrading from earlier versions note the + following: +

+
    +
  • + The class Exception in myexcept.h has been replaced by + BaseException and a typedef statement included so + programs that use the Exception class will still work. If the + Exception class was causing a problem comment out the line + defining TypeDefException in include.h. +
  • +
  • + Newmat11 does not support the TEMP_DESTROYED_QUICKLY options so won't + work with very old versions of Gnu G++ +
  • +
  • Old AT&T work-arounds are removed
  • +
  • + The simulated Booleans class is now stored at the end of include.h. In + general, I am not testing with compilers that don't support bool. +
  • +
  • + QRZ and QRZT no longer throw an exception if they generate a singular + triangular matrix +
  • +
  • + Converting functions to lower case. Both the old and new names will + work. See the list of functions for new and old + names +
  • +
  • + nm_i5.mak, nm_il5.mak replaced by nm_i8.mak, + nm_il8.mak +
  • +
  • extra file nm_misc.cpp to be included in compilation
  • +
  • + scientific and fixed manipulators now recognised in output + statements. If you want fixed output and have been using + scientific in a previous output statement, you may need to + include the fixed manipulator. (Doesn't work in Visual C++, + version 6 and open Watcom). +
  • +
+

+ Newmat10 includes new maxima, minima, + determinant, dot product and Frobenius norm + functions, a faster FFT, revised + make files for GCC and CC compilers, several + corrections, new ReSize function, + IdentityMatrix and + Kronecker Product. Singular values from + SVD are sorted. The program files include a new file, + newfft.cpp, so you will need to include this in the list of files + in your IDE and make files. There is also a new test file tmtm.cpp. + Pointer arithmetic now mostly meets requirements of + standard. You can use << to load data into + rows of a matrix. The default options in include.h + have been changed. If you are updating from a beta version of newmat09 + look through the next section as there were some late changes to newmat09. +

+

If you are upgrading from newmat08 note the following:

+
    +
  • + Boolean, TRUE, FALSE are now bool, true, false. See + customising if your compiler supports the bool + class. +
  • +
  • ReDimension is now ReSize.
  • +
  • + The simulated exception package has been updated. +
  • +
  • + Operators ==, !=, +=, -=, + *=, |=, &= are now supported as + binary matrix operators. +
  • +
  • + A+=f, A-=f, A*=f, A/=f, + f+A, f-A, f*A are supported for + A matrix, f scalar. +
  • +
  • Fast trigonometric transforms.
  • +
  • + Reverse function for reversing order of elements in + a vector or matrix. +
  • +
  • IsSingular function.
  • +
  • + An option is included for defining namespaces. +
  • +
  • + Dummy inequality operators are defined for compatibility with the STL. +
  • +
  • + The row/column classes in newmat3.cpp have been modified to improve + efficiency and correct an invalid use of pointer arithmetic. Most users + won't be using these classes explicitly; if you are, please contact me + for details of the changes. +
  • +
  • Matrix LU decomposition rewritten (faster for large arrays).
  • +
  • The sort function rewritten (faster).
  • +
  • + The documentation files newmata.txt and newmatb.txt have been + amalgamated and both are included in the hypertext version. +
  • +
  • Some of the make files reorganised again.
  • +
+

If you are upgrading from newmat07 note the following:

+
    +
  • + .cxx files are now .cpp files. Some versions of won't accept .cpp. The + make files for Gnu and AT&T link the .cpp files to .cxx files + before compilation and delete the links after compilation. +
  • +
  • + An option in include.h allows you to use compiler + supported exceptions, simulated exceptions or disable exceptions. Edit + the file include.h to select one of these three options. Don't simulate + exceptions if you have set your compiler's option to implement + exceptions. +
  • +
  • New QR decomposition functions.
  • +
  • A non-linear least squares class.
  • +
  • No need to explicitly set the AT&T option in include.h.
  • +
  • + Concatenation and elementwise multiplication. +
  • +
  • A new GenericMatrix class.
  • +
  • Sum function.
  • +
  • Some of the make files reorganised.
  • +
+

If you are upgrading from newmat06 note the following:

+
    +
  • + If you are using << to load a Real into a submatrix change this to + =. +
  • +
+

+ If you are upgrading from newmat03 or newmat04 note the + following +

+
    +
  • .hxx files are now .h files
  • +
  • real changed to Real
  • +
  • BOOL changed to Boolean
  • +
  • CopyToMatrix changed to AsMatrix, etc
  • +
  • real(A) changed to A.AsScalar()
  • +
+

+ The current version is quite a bit longer that newmat04, so if you are + almost out of space with newmat04, don't throw newmat04 away until you + have checked your program will work under this version. +

+

See the change history for other changes.

+

2.6 Catching exceptions

+

+ next - skip - + up - start +

+

+ This section applies particularly to people using + compiler supported exceptions rather than my + simulated exceptions. +

+
+

+ If newmat detects an error it will throw an exception. It is important + that you catch this exception and print the error message. + Otherwise you will get an unhelpful message like + abnormal termination. +

+
+

I suggest you set up your main program like 

+
+#define WANT_STREAM             // or #include <iostream>
 #include "newmat.h"             // or #include "newmatap.h"
 #include "newmatio.h"           // if you are using my matrix output functions
 
@@ -753,889 +1056,1103 @@ 

2.6 Catching exceptions

catch(...) { cout << "exception caught in main program" << endl; } return 0; }
-

Or see my file nm_ex1.cpp for an easy way of organising this.

-

If you are using a GUI version rather a console version of the program you -will need to catch the exception and display the error message in a pop-up -window.

-

If you are using my simulated exceptions or have set the disable exceptions -option in include.h then uncaught exceptions automatically print the -error message generated by the exception so you can ignore this section. -Alternatively use Try, Catch and CatchAll in place of try, catch -and catch(...) in the preceding code.

-

See the section on exceptions for more information on -the exception structure.

-

2.7 Examples

-

next - skip - -up - start

-

I include a number of example files. See the sections on make -files and on compilers for information about compiling -them.

-

Invert matrix: nm_ex1.cpp. Load values into a 4x4 matrix; invert it -and check the result. The output is in nm_ex1.txt.

-

Eigenvalues and eigenvectors of Hilbert matrix: nm_ex2.cpp. Calculate the -eigenvalues and eigenvectors of a 7x7 Hilbert matrix. The output is in -nm_ex2.txt.

-

Values in precisio.h: nm_ex3.cpp.

-

Linear regression example: example.cpp. This gives a linear -regression example using five different algorithms. The correct output is given -in example.txt. The program carries out a rough check that no memory -is left allocated on the heap when it terminates. See the section on -testing for a comment on the reliability of this check -and the use of the DO_FREE_CHECK option.

-

Other example files are nl_ex.cpp and garch.cpp for -demonstrating the non-linear fitting routines, sl_ex for demonstrating -the solve function and test_exc for demonstrating and testing exception -handling.

-

2.8 Testing

-

next - skip - -up - start

-

The library package contains a comprehensive test program in the form of a -series of files with names of the form tmt?.cxx. The files consist of a large -number of matrix formulae all of which evaluate to zero (except the first one -which is used to check that we are detecting non-zero matrices). The printout -should state that it has found just one non-zero matrix.

-

The test program should be run with Real typedefed to double -rather than float in include.h.

-

Make sure the C subscripts are enabled if you want -to test these.

-

If you are carrying out some form of bounds checking, for example, with -Borland's CodeGuard, then disable the testing of the Numerical Recipes in C interface. Activate the statement -#define DONT_DO_NRIC in tmt.h.

-

Various versions of the make file (extension .mak) are included with the -package. See the section on make files.

-

The program also allocates and deletes a large block and small block of -memory before it starts the main testing and then at the end of the test. It -then checks that the blocks of memory were allocated in the same place. If not, -then one suspects that there has been a memory leak. i.e. a piece of memory has -been allocated and not deleted.

-

This is not foolproof. For example, programs may allocate extra print buffers -while the program is running. I have tried to overcome this by doing a print -before I allocate the first memory block. Programs may allocate memory for -different sized items in different places, or might not allocate items -consecutively. Or they might mix the items with memory blocks from other -programs. Nevertheless, I seem to get consistent answers from some of the -compilers I work with, so I think this is a worthwhile test. The compilers that -the test seems to work for include the Borland compilers, Microsoft VC++ 6 , -Watcom, and Gnu 2.96 for Linux.

-

If the DO_FREE_CHECK option in include.h is activated, -the program checks that each new is balanced with exactly one -delete. This provides a more definitive test of no memory leaks. There -are additional statements in myexcept.cpp which can be activated to print out -details of the memory being allocated and released.

-

I have included a facility for checking that each piece of code in the -library is really exercised by the test routines. Each block of code in the -main part of the library contains a word REPORT. newmat.h has -a line defining REPORT that can be activated (deactivate the dummy -version). This gives a printout of the number of times each of the -REPORT statements in the .cpp files is accessed. Use a grep -with line numbers to locate the lines on which REPORT occurs and -compare these with the lines that the printout shows were actually accessed. -One can then see which lines of code were not accessed.

-

2.9 Bugs

-

next - skip - -up - start

-
    -
  • Small memory leaks may occur when an exception is thrown and caught.
  • -
  • My exception scheme may not be not properly linked in with the standard -library exceptions. In particular, my scheme may fail to catch out-of-memory -exceptions.
  • -
-

2.10 Problem areas

-

next - skip - -up - start

-

This section lists parts of Newmat which users (including me) have found -difficult or unnatural. Also see the newmat FAQ list on -my website.

-

Invert, element access, matrix multiply etc causes the program to crash

-
-

Newmat throws an exception when it detects an error. This can cause a program -crash unless the exception is caught with a catch statement. See -catching exceptions.

-
-

1x1 matrix not automatically converted to a Real

-
-

Use the as_scalar() member function or the -dotproduct() function to take the dot -product of two vectors.

-
-

Constructors do not initialise elements

-
-

For example, Matrix A(4,5); does not initialise the elements of A. Use the -statement A=0.0 to set the values to zero.

-
-

resize does not initialise elements

-
-

For example, A.resize(5,6); does not set the elements of A. -If you want to keep values use resize_keep. See resize.

-
-

Setting Matrix to a scalar sets all the values

-
-

A(1,3) = 0.0; sets one element of a Matrix to zero. A = 0.0; sets all the -elements to zero. This is very convenient but also a source of error that is - -hard to see if you wanted A(1,3) = 0.0; but left out the element details.

-
-

Symmetry not detected automatically

-
-

For example, SymmetricMatrix SM = A.t() * A; will fail. Use SymmetricMatrix -SM; SM << A.t() * A;

-
-

<< does not work with constructors

-
-

For example, SymmetricMatrix SM << A.t() * A; does not work.

-
-

Multiple multiplication may be inefficient

-
-

For example, A * B * X where A and B are matrices and X is a column vector is -likely to be much slower than A * (B * X).

-
-

 

-

2.11 List of files

-

next - skip - -up - start

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Documentationreadme.txtreadme file
 nm11.htmdocumentation file
 add_time.pgnimage used by nm11.htm
 rbd.cssstyle sheet for nm11.htm
 _newmat.doxdescription file for Doxygen
 _rbd_com.doxdescription file for Doxygen
Header filescontrolw.hcontrol word definition file
 include.hdetails of include files and options
 myexcept.hgeneral exception handler definitions
 newmat.hmain matrix class definition file
 newmatap.happlications definition file
 newmatio.hinput/output definition file
 newmatnl.hnon-linear optimisation definition file
 newmatrc.hrow/column functions definition files
 newmatrm.hrectangular matrix access definition files
 precisio.hnumerical precision constants
 solution.hone dimensional solve definition file
Program filesbandmat.cppband matrix routines
 cholesky.cppCholesky decomposition
 evalue.cppeigenvalues and eigenvector calculation
 fft.cppfast Fourier, trig. transforms
 hholder.cppQR routines
 jacobi.cppeigenvalues by the Jacobi method
 myexcept.cppgeneral error and exception handler
 newfft.cppnew fast Fourier transform
 newmat1.cpptype manipulation routines
 newmat2.cpprow and column manipulation functions
 newmat3.cpprow and column access functions
 newmat4.cppconstructors, resize, utilities
 newmat5.cpptranspose, evaluate, matrix functions
 newmat6.cppoperators, element access
 newmat7.cppinvert, solve, binary operations
 newmat8.cppLU decomposition, scalar functions
 newmat9.cppoutput routines
 newmatex.cppmatrix exception handler
 newmatnl.cppnon-linear optimisation
 newmatrm.cpprectangular matrix access functions
 nm_misc.cppmiscellaneous classes, functions
 sort.cppsorting functions
 solution.cppone dimensional solve
 submat.cppsubmatrix functions
 svd.cppsingular value decomposition
Example filesnm_ex1.cppsimple example - invert matrix
 nm_ex1.txtoutput from nm_ex1.cpp
 nm_ex2.cppsimple example - eigenvalues of Hilbert matrix
 nm_ex2.txtoutput from nm_ex2.cpp
 nm_ex3.cppscientific format and constants from precisio.h
 nm_ex3.txtoutput from nm_ex3.cpp
 example.cppexample of use of package
 example.txtoutput from example
 sl_ex.cppexample of OneDimSolve routine
 sl_ex.txtoutput from example
 nl_ex.cppexample of non-linear least squares
 nl_ex.txtoutput from example
 garch.cppexample of maximum-likelihood fit
 garch.datdata file for garch.cpp
 garch.txtoutput from example
 test_exc.cppdemonstration exceptions
 test_exc.txtoutput from test_exc.cpp
Test filestmt.hheader file for test files
 tmt*.cpptest files (see the section on testing)
 tmt.txtoutput from test files
Make filesnm_gnu.makmake file for Gnu G++
 nm_cc.makmake file for AT&T, Sun and HPUX
 nm_b55.makmake file for Borland C++ 5.5
 nm_b56.makmake file for Borland Builder C++ 6
 nm_b58.makmake file for Borland Builder C++ 8
 nm_m6.makmake file for VC++ 6&7
 nm_m8.makmake file for VC++ 8
 nm_i8.makmake file for Intel C++ 8,9 under Windows
 nm_i10.makmake file for Intel C++ 10 under Windows
 nm_il8.makmake file for Intel C++ 8,9,10 under Linux
 nm_ow.makmake file for Open Watcom
 newmat.lfllibrary file list for use with genmake
 nm_targ.txttarget file list for use with genmake
 Makefile.inused for compiling with Opt++
- -

 

-

These are the .cpp files you need to include in your make file or project:

-

Basic newmat

- - - - - - - -
    -
  • bandmat.cpp
  • -
  • myexcept.cpp
  • -
  • newmat1.cpp
  • -
  • newmat2.cpp
  • -
-
    -
  • newmat3.cpp
  • -
  • newmat4.cpp
  • -
  • newmat5.cpp
  • -
  • newmat6.cpp
  • -
-
    -
  • newmat7.cpp
  • -
  • newmat8.cpp
  • -
  • newmat9.cpp
  • -
  • newmatex.cpp
  • -
-
    -
  • newmatrm.cpp
  • -
  • submat.cpp
  • -
-
-

Factorisations etc

- - - - - - - -
    -
  • cholesky.cpp
  • -
  • evalue.cpp
  • -
  • fft.cpp
  • -
-
-
    -
  • hholder.cpp
  • -
  • jacobi.cpp
  • -
-
-
    -
  • sort.cpp
  • -
  • svd.cpp
  • -
-

 

    -
  • newfft.cpp
  • -
  • nm_misc.cpp
  • -
-
-

Nonlinear routines

- - - - - - - -
    -
  • newmatnl.cpp
  • -
-
    -
  • solution.cpp
  • -
-
-

 

- -

3. Reference manual

-

next - skip - -up - start

- - - - - -
3.1 -Constructors
-3.2 Accessing elements
-3.3 Assignment and copying
-3.4 Entering values
-3.5 Unary operations
-3.6 Binary operations
-3.7 Matrix and scalar ops
-3.8 Scalar functions - size & shape
-3.9 Scalar functions - maximum & minimum
-3.10 Scalar functions - numerical
-3.11 Submatrices
-3.12 Change dimension
-3.13 Change type
-3.14 Multiple matrix solve
-3.15 Memory management
-3.16 Efficiency
-3.17 Output
-3.18 Accessing unspecified type
-3.19 Cholesky decomposition
-3.20 QR decomposition
-3.21 Singular value decomposition
-3.22 Eigenvalue decomposition
-3.23 Sorting
-3.24 Fast Fourier transform
-3.25 Fast trigonometric transforms
-3.26 Numerical recipes in C
-3.27 Exceptions
-3.28 Cleanup following exception
-3.29 Non-linear applications
-3.30 Standard template library
-3.31 Namespace
-3.32 Updating the Cholesky matrix
-3.33 Accessing C functions
-3.34 Simple integer array class
-3.35 Extend orthonormal set of columns
-3.36 Miscellaneous functions
-

See also function summary.

- -

3.1 Constructors

-

next - skip - -up - start

-

To construct an m x n matrix, A, (m and -n are integers) use

-
    Matrix A(m,n);
-
- -

The SquareMatrix, UpperTriangularMatrix, LowerTriangularMatrix, SymmetricMatrix and -DiagonalMatrix types are square. To construct an n x n matrix -use, for example

-
    SquareMatrix SQ(n);
+    

Or see my file nm_ex1.cpp for an easy way of organising this.

+

+ If you are using a GUI version rather a console version of the program you + will need to catch the exception and display the error message in a pop-up + window. +

+

+ If you are using my simulated exceptions or have set the disable + exceptions option in include.h then uncaught exceptions + automatically print the error message generated by the exception so you + can ignore this section. Alternatively use Try, Catch and + CatchAll in place of try, catch and + catch(...) in the preceding code. +

+

+ See the section on exceptions for more information + on the exception structure. +

+

2.7 Examples

+

+ next - skip - + up - start +

+

+ I include a number of example files. See the sections on + make files and on + compilers for information about compiling them. +

+

+ Invert matrix: nm_ex1.cpp. Load values into a 4x4 matrix; + invert it and check the result. The output is in nm_ex1.txt. +

+

+ Eigenvalues and eigenvectors of Hilbert matrix: + nm_ex2.cpp. Calculate the eigenvalues and eigenvectors of a 7x7 + Hilbert matrix. The output is in nm_ex2.txt. +

+

Values in precisio.h: nm_ex3.cpp.

+

+ Linear regression example: example.cpp. This gives a + linear regression example using five different algorithms. The correct + output is given in example.txt. The program carries out a rough + check that no memory is left allocated on the heap when it terminates. See + the section on testing for a comment on the + reliability of this check and the use of the DO_FREE_CHECK option. +

+

+ Other example files are nl_ex.cpp and garch.cpp for + demonstrating the non-linear fitting routines, sl_ex for + demonstrating the solve function and test_exc for demonstrating + and testing exception handling. +

+

2.8 Testing

+

+ next - skip - + up - start +

+

+ The library package contains a comprehensive test program in the form of a + series of files with names of the form tmt?.cxx. The files consist of a + large number of matrix formulae all of which evaluate to zero (except the + first one which is used to check that we are detecting non-zero matrices). + The printout should state that it has found just one non-zero matrix. +

+

+ The test program should be run with Real typedefed to + double rather than float in include.h. +

+

+ Make sure the C subscripts are enabled if you want + to test these. +

+

+ If you are carrying out some form of bounds checking, for example, with + Borland's CodeGuard, then disable the testing of the + Numerical Recipes in C interface. Activate the + statement #define DONT_DO_NRIC in tmt.h. +

+

+ Various versions of the make file (extension .mak) are included with the + package. See the section on make files. +

+

+ The program also allocates and deletes a large block and small block of + memory before it starts the main testing and then at the end of the test. + It then checks that the blocks of memory were allocated in the same place. + If not, then one suspects that there has been a memory leak. i.e. a piece + of memory has been allocated and not deleted. +

+

+ This is not foolproof. For example, programs may allocate extra print + buffers while the program is running. I have tried to overcome this by + doing a print before I allocate the first memory block. Programs may + allocate memory for different sized items in different places, or might + not allocate items consecutively. Or they might mix the items with memory + blocks from other programs. Nevertheless, I seem to get consistent answers + from some of the compilers I work with, so I think this is a + worthwhile test. The compilers that the test seems to work for include the + Borland compilers, Microsoft VC++ 6 , Watcom, and Gnu 2.96 for Linux. +

+

+ If the DO_FREE_CHECK option in include.h is + activated, the program checks that each new is balanced with + exactly one delete. This provides a more definitive test of no + memory leaks. There are additional statements in myexcept.cpp which can be + activated to print out details of the memory being allocated and released. +

+

+ I have included a facility for checking that each piece of code in the + library is really exercised by the test routines. Each block of code in + the main part of the library contains a word REPORT. + newmat.h has a line defining REPORT that can be + activated (deactivate the dummy version). This gives a printout of the + number of times each of the REPORT statements in the + .cpp files is accessed. Use a grep with line numbers to locate + the lines on which REPORT occurs and compare these with the lines + that the printout shows were actually accessed. One can then see which + lines of code were not accessed. +

+

2.9 Bugs

+

+ next - skip - + up - start +

+
    +
  • + Small memory leaks may occur when an exception is thrown and caught. +
  • +
  • + My exception scheme may not be not properly linked in with the standard + library exceptions. In particular, my scheme may fail to catch + out-of-memory exceptions. +
  • +
+

2.10 Problem areas

+

+ next - skip - + up - start +

+

+ This section lists parts of Newmat which users (including me) have + found difficult or unnatural. Also see the + newmat FAQ list on my + website. +

+

+ Invert, element access, matrix multiply etc causes the program to + crash +

+
+

+ Newmat throws an exception when it detects an error. This can cause a + program crash unless the exception is caught with a + catch statement. See catching exceptions. +

+
+

+ 1x1 matrix not automatically converted to a Real +

+
+

+ Use the as_scalar() member function or the + dotproduct() function to take the dot product of + two vectors. +

+
+

Constructors do not initialise elements

+
+

+ For example, Matrix A(4,5); does not initialise the elements of + A. Use the statement A=0.0 to set the values to zero. +

+
+

+ resize does not initialise elements +

+
+

+ For example, A.resize(5,6); does not set the elements of + A. If you want to keep values use resize_keep. See + resize. +

+
+

Setting Matrix to a scalar sets all the values

+
+

+ A(1,3) = 0.0; sets one element of a Matrix to zero. + A = 0.0; sets all the elements to zero. This is very convenient + but also a source of error that is hard to see if you wanted + A(1,3) = 0.0; but left out the element details. +

+
+

Symmetry not detected automatically

+
+

+ For example, SymmetricMatrix SM = A.t() * A; will fail. Use + SymmetricMatrix SM; SM << A.t() * A; +

+
+

+ << does not work with constructors +

+
+

+ For example, SymmetricMatrix SM << A.t() * A; does not + work. +

+
+

Multiple multiplication may be inefficient

+
+

+ For example, A * B * X where A and B are + matrices and X is a column vector is likely to be much slower + than A * (B * X). +

+
+

 

+

2.11 List of files

+

+ next - skip - + up - start +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Documentationreadme.txtreadme file
 nm11.htmdocumentation file
 add_time.pgnimage used by nm11.htm
 rbd.cssstyle sheet for nm11.htm
 _newmat.doxdescription file for Doxygen
 _rbd_com.doxdescription file for Doxygen
Header filescontrolw.hcontrol word definition file
 include.hdetails of include files and options
 myexcept.hgeneral exception handler definitions
 newmat.hmain matrix class definition file
 newmatap.happlications definition file
 newmatio.hinput/output definition file
 newmatnl.hnon-linear optimisation definition file
 newmatrc.hrow/column functions definition files
 newmatrm.hrectangular matrix access definition files
 precisio.hnumerical precision constants
 solution.hone dimensional solve definition file
Program filesbandmat.cppband matrix routines
 cholesky.cppCholesky decomposition
 evalue.cppeigenvalues and eigenvector calculation
 fft.cppfast Fourier, trig. transforms
 hholder.cppQR routines
 jacobi.cppeigenvalues by the Jacobi method
 myexcept.cppgeneral error and exception handler
 newfft.cppnew fast Fourier transform
 newmat1.cpptype manipulation routines
 newmat2.cpprow and column manipulation functions
 newmat3.cpprow and column access functions
 newmat4.cppconstructors, resize, utilities
 newmat5.cpptranspose, evaluate, matrix functions
 newmat6.cppoperators, element access
 newmat7.cppinvert, solve, binary operations
 newmat8.cppLU decomposition, scalar functions
 newmat9.cppoutput routines
 newmatex.cppmatrix exception handler
 newmatnl.cppnon-linear optimisation
 newmatrm.cpprectangular matrix access functions
 nm_misc.cppmiscellaneous classes, functions
 sort.cppsorting functions
 solution.cppone dimensional solve
 submat.cppsubmatrix functions
 svd.cppsingular value decomposition
Example filesnm_ex1.cppsimple example - invert matrix
 nm_ex1.txtoutput from nm_ex1.cpp
 nm_ex2.cppsimple example - eigenvalues of Hilbert matrix
 nm_ex2.txtoutput from nm_ex2.cpp
 nm_ex3.cppscientific format and constants from precisio.h
 nm_ex3.txtoutput from nm_ex3.cpp
 example.cppexample of use of package
 example.txtoutput from example
 sl_ex.cppexample of OneDimSolve routine
 sl_ex.txtoutput from example
 nl_ex.cppexample of non-linear least squares
 nl_ex.txtoutput from example
 garch.cppexample of maximum-likelihood fit
 garch.datdata file for garch.cpp
 garch.txtoutput from example
 test_exc.cppdemonstration exceptions
 test_exc.txtoutput from test_exc.cpp
Test filestmt.hheader file for test files
 tmt*.cpp + test files (see the section on testing) +
 tmt.txtoutput from test files
Make filesnm_gnu.makmake file for Gnu G++
 nm_cc.makmake file for AT&T, Sun and HPUX
 nm_b55.makmake file for Borland C++ 5.5
 nm_b56.makmake file for Borland Builder C++ 6
 nm_b58.makmake file for Borland Builder C++ 8
 nm_m6.makmake file for VC++ 6&7
 nm_m8.makmake file for VC++ 8
 nm_i8.makmake file for Intel C++ 8,9 under Windows
 nm_i10.makmake file for Intel C++ 10 under Windows
 nm_il8.makmake file for Intel C++ 8,9,10 under Linux
 nm_ow.makmake file for Open Watcom
 newmat.lfl + library file list for use with genmake +
 nm_targ.txt + target file list for use with genmake +
 Makefile.inused for compiling with Opt++
+ +

 

+

+ These are the .cpp files you need to include in your make file or project: +

+

Basic newmat

+ + + + + + + +
+
    +
  • bandmat.cpp
  • +
  • myexcept.cpp
  • +
  • newmat1.cpp
  • +
  • newmat2.cpp
  • +
+
+
    +
  • newmat3.cpp
  • +
  • newmat4.cpp
  • +
  • newmat5.cpp
  • +
  • newmat6.cpp
  • +
+
+
    +
  • newmat7.cpp
  • +
  • newmat8.cpp
  • +
  • newmat9.cpp
  • +
  • newmatex.cpp
  • +
+
+
    +
  • newmatrm.cpp
  • +
  • submat.cpp
  • +
+
+

Factorisations etc

+ + + + + + + +
+
    +
  • cholesky.cpp
  • +
  • evalue.cpp
  • +
  • fft.cpp
  • +
+
+
    +
  • hholder.cpp
  • +
  • jacobi.cpp
  • +
+
+
    +
  • sort.cpp
  • +
  • svd.cpp
  • +
+

 

+
+
    +
  • newfft.cpp
  • +
  • nm_misc.cpp
  • +
+
+

Nonlinear routines

+ + + + + + + +
+
    +
  • newmatnl.cpp
  • +
+
+
    +
  • solution.cpp
  • +
+
+

 

+ +

3. Reference manual

+

+ next - skip - + up - start +

+ + + + + +
+ 3.1 Constructors
+ 3.2 Accessing elements
+ 3.3 Assignment and copying
+ 3.4 Entering values
+ 3.5 Unary operations
+ 3.6 Binary operations
+ 3.7 Matrix and scalar ops
+ 3.8 Scalar functions - size & shape
+ 3.9 Scalar functions - maximum & minimum
+ 3.10 Scalar functions - numerical
+ 3.11 Submatrices
+ 3.12 Change dimension
+ 3.13 Change type
+ 3.14 Multiple matrix solve
+ 3.15 Memory management
+ 3.16 Efficiency
+ 3.17 Output
+ 3.18 Accessing unspecified type +
+ 3.19 Cholesky decomposition
+ 3.20 QR decomposition
+ 3.21 Singular value decomposition
+ 3.22 Eigenvalue decomposition
+ 3.23 Sorting
+ 3.24 Fast Fourier transform
+ 3.25 Fast trigonometric transforms
+ 3.26 Numerical recipes in C
+ 3.27 Exceptions
+ 3.28 Cleanup following exception
+ 3.29 Non-linear applications
+ 3.30 Standard template library
+ 3.31 Namespace
+ 3.32 Updating the Cholesky matrix
+ 3.33 Accessing C functions
+ 3.34 Simple integer array class
+ 3.35 Extend orthonormal set of columns
+ 3.36 Miscellaneous functions +
+

See also function summary.

+ +

3.1 Constructors

+

+ next - skip - + up - start +

+

+ To construct an m x n matrix, A, (m and + n are integers) use +

+
+    Matrix A(m,n);
+
+ +

+ The SquareMatrix, UpperTriangularMatrix, LowerTriangularMatrix, + SymmetricMatrix and DiagonalMatrix types are square. To construct an + n x n matrix use, for example +

+
+    SquareMatrix SQ(n);
     UpperTriangularMatrix UT(n);
     LowerTriangularMatrix LT(n);
     SymmetricMatrix S(n);
     DiagonalMatrix D(n);
-
+
-

Band matrices need to include bandwidth information in their constructors. -

-
    BandMatrix BM(n, lower, upper);
+    

+ Band matrices need to include bandwidth information in their constructors. +

+
+    BandMatrix BM(n, lower, upper);
     UpperBandMatrix UB(n, upper);
     LowerBandMatrix LB(n, lower);
     SymmetricBandMatrix SB(n, lower);
-
- -

The integers upper and lower are the number of non-zero -diagonals above and below the diagonal (excluding the diagonal) -respectively.  The UpperBandMatrix and LowerBandMatrix are upper and lower -triangular band matrices. So an UpperBandMatrix is essentially a BandMatrix with -lower = 0 and a LowerBandMatrix is a BandMatrix with upper = 0.

-

The RowVector and ColumnVector types take just one argument in their -constructors:

-
    RowVector RV(n);
+
+ +

+ The integers upper and lower are the number of non-zero + diagonals above and below the diagonal (excluding the diagonal) + respectively.  The UpperBandMatrix and LowerBandMatrix are upper and + lower triangular band matrices. So an UpperBandMatrix is essentially a + BandMatrix with lower = 0 and a LowerBandMatrix is a BandMatrix + with upper = 0. +

+

+ The RowVector and ColumnVector types take just one argument in their + constructors: +

+
+    RowVector RV(n);
     ColumnVector CV(n);
-
- -

These constructors do not initialise the elements of the matrices. - -To set all the elements to zero use, for example,

-
    Matrix A(m, n); A = 0.0;
-
- -

The IdentityMatrix takes one argument in its constructor specifying its -dimension.

-
    IdentityMatrix I(n);
-

The value of the diagonal elements is set to 1 by default, but you can -change this value as with other matrix types.

- -

You can also construct vectors and matrices without specifying the -dimension. For example

-
    Matrix A;
-
- -

In this case the dimension must be set by an assignment -statement or a resize statement.

-

You can also use a constructor to set a matrix equal to another matrix or -matrix expression.

-
    Matrix A = UT;
+
+ +

+ These constructors do not initialise the elements of the + matrices. + + To set all the elements to zero use, for example, +

+
+    Matrix A(m, n); A = 0.0;
+
+ +

+ The IdentityMatrix takes one argument in its constructor specifying its + dimension. +

+
    IdentityMatrix I(n);
+

+ The value of the diagonal elements is set to 1 by default, but you + can change this value as with other matrix types. +

+ +

+ You can also construct vectors and matrices without specifying the + dimension. For example +

+
+    Matrix A;
+
+ +

+ In this case the dimension must be set by an + assignment statement or a + resize statement. +

+

+ You can also use a constructor to set a matrix equal to another matrix or + matrix expression. +

+
+    Matrix A = UT;
     Matrix A = UT * LT;
-
- -

Only conversions that don't lose information are supported - eg you cannot -convert an upper triangular matrix into a diagonal matrix using =.

-

3.2 Accessing elements -

-

next - skip - -up - start

-

Elements are accessed by expressions of the form A(i,j) where -i and j run from 1 to the appropriate dimension. Access elements -of vectors with just one argument. Diagonal matrices can accept one or two -subscripts.

-

This is different from the earliest version of the package in which the -subscripts ran from 0 to one less than the appropriate dimension. Use -A.element(i,j) if you want this earlier convention.

-

A(i,j) and A.element(i,j) can appear on either side of an -= sign.

-

If you activate the #define SETUP_C_SUBSCRIPTS in -include.h you can also access elements using the traditional C style -notation. That is A[i][j] for matrices (except diagonal) and -V[i] for vectors and diagonal matrices. The subscripts start at zero -(i.e. like element) and there is no range checking. Because of the -possibility of confusing V(i) and V[i], I suggest you do -not activate this option unless you really want to use it.

-

Symmetric matrices are stored as lower triangular matrices. It is important -to remember this if you are using the A[i][j] method of accessing -elements. Make sure the first subscript is greater than or equal to the second -subscript. However, if you are using the A(i,j) method the program -will swap i and j if necessary; so it doesn't matter if you -think of the storage as being in the upper triangle (but it does matter -in some other situations such as when entering data).

-

The IdentityMatrix type does not support element access.

-

For interfacing with traditional C functions that involve one and two -dimensional arrays see accessing C functions.

-

3.3 Assignment and copying

-

next - skip - -up - start

-

The operator = is used for copying matrices, converting matrices, -or evaluating expressions. For example

-
    A = B;  A = L;  A = L * U;
-
- -

Only conversions that don't lose information are supported. The dimensions -of the matrix on the left hand side are adjusted to those of the matrix or -expression on the right hand side. Elements on the right hand side which are -not present on the left hand side are set to zero.

-

The operator << can be used in place of = where it -is permissible for information to be lost.

-

For example

-
    SymmetricMatrix S; Matrix A;
+
+ +

+ Only conversions that don't lose information are supported - eg you cannot + convert an upper triangular matrix into a diagonal matrix using =. +

+

3.2 Accessing elements

+

+ next - skip - + up - start +

+

+ Elements are accessed by expressions of the form A(i,j) where + i and j run from 1 to the appropriate dimension. Access + elements of vectors with just one argument. Diagonal matrices can accept + one or two subscripts. +

+

+ This is different from the earliest version of the package in which the + subscripts ran from 0 to one less than the appropriate dimension. Use + A.element(i,j) if you want this earlier convention. +

+

+ A(i,j) and A.element(i,j) can appear on either side of + an = sign. +

+

+ If you activate the #define SETUP_C_SUBSCRIPTS in + include.h you can also access elements using the traditional C + style notation. That is A[i][j] for matrices (except diagonal) + and V[i] for vectors and diagonal matrices. The subscripts start + at zero (i.e. like element) and there is no range checking. Because + of the possibility of confusing V(i) and V[i], I suggest + you do not activate this option unless you really want to use it. +

+

+ Symmetric matrices are stored as lower triangular matrices. It is + important to remember this if you are using the A[i][j] method of + accessing elements. Make sure the first subscript is greater than or equal + to the second subscript. However, if you are using the + A(i,j) method the program will swap i and j if + necessary; so it doesn't matter if you think of the storage as being in + the upper triangle (but it does matter in some other situations + such as when entering data). +

+

The IdentityMatrix type does not support element access.

+

+ For interfacing with traditional C functions that involve one and two + dimensional arrays see accessing C functions. +

+

3.3 Assignment and copying

+

+ next - skip - + up - start +

+

+ The operator = is used for copying matrices, converting matrices, + or evaluating expressions. For example +

+
+    A = B;  A = L;  A = L * U;
+
+ +

+ Only conversions that don't lose information are supported. The dimensions + of the matrix on the left hand side are adjusted to those of the matrix or + expression on the right hand side. Elements on the right hand side which + are not present on the left hand side are set to zero. +

+

+ The operator << can be used in place of = where it + is permissible for information to be lost. +

+

For example

+
+    SymmetricMatrix S; Matrix A;
     ......
     S << A.t() * A;
-
- -

is acceptable whereas

-
    S = A.t() * A;                            // error
-
- -

will cause a runtime error since the package does not (yet?) recognise -A.t()*A as symmetric.

-

Note that you can not use << with constructors. For -example

-
    SymmetricMatrix S << A.t() * A;           // error
-
- -

does not work.

-

Also note that << cannot be used to load values from a full -matrix into a band matrix, since it will be unable to determine the bandwidth -of the band matrix.

-

A third copy routine is used in a similar role to =. Use

-
    A.inject(D);
-
- -

to copy the elements of D to the corresponding elements of -A but leave the elements of A unchanged if there is no -corresponding element of D (the = operator would set them to -0). This is useful, for example, for setting the diagonal elements of a matrix -without disturbing the rest of the matrix. Unlike = and -<<, inject does not reset the dimensions of A, which -must match those of D. Inject does not test for no loss of -information. The name Inject can be used instead on inject.

-

You cannot replace D by a matrix expression. The effect of inject(D) depends on the type of D. If D is an -expression it might not be obvious to the user what type it would have. So I -thought it best to disallow expressions.

-

Inject can be used for loading values from a regular matrix into a band -matrix. (Don't forget to zero any elements of the left hand side that will not -be set by the loading operation).

-

Both << and inject can be used with submatrix expressions on -the left hand side. See the section on submatrices.

-

To set the elements of a matrix to a scalar use operator =

-
    Real r; int m,n;
+
+ +

is acceptable whereas

+
+    S = A.t() * A;                            // error
+
+ +

+ will cause a runtime error since the package does not (yet?) recognise + A.t()*A as symmetric. +

+

+ Note that you can not use << with constructors. For + example +

+
+    SymmetricMatrix S << A.t() * A;           // error
+
+ +

does not work.

+

+ Also note that << cannot be used to load values from a full + matrix into a band matrix, since it will be unable to determine the + bandwidth of the band matrix. +

+

A third copy routine is used in a similar role to =. Use

+
+    A.inject(D);
+
+ +

+ to copy the elements of D to the corresponding elements of + A but leave the elements of A unchanged if there is no + corresponding element of D (the = operator would set + them to 0). This is useful, for example, for setting the diagonal elements + of a matrix without disturbing the rest of the matrix. Unlike + = and <<, inject does not reset the dimensions of + A, which must match those of D. Inject does + not test for no loss of information. The name Inject can be + used instead on inject. +

+

+ You cannot replace D by a matrix expression. The effect of + inject(D) depends on the type of D. If D is an + expression it might not be obvious to the user what type it would have. So + I thought it best to disallow expressions. +

+

+ Inject can be used for loading values from a regular matrix into a band + matrix. (Don't forget to zero any elements of the left hand side that will + not be set by the loading operation). +

+

+ Both << and inject can be used with submatrix expressions + on the left hand side. See the section on + submatrices. +

+

To set the elements of a matrix to a scalar use operator =

+
+    Real r; int m,n;
     ......
-    Matrix A(m,n); A = r;
- - -To swap the values in two matrices A and B use one of the -following expressions
   A.swap(B);
-
   swap(A,B);
-The matrices A and B must be of the same type. This can be any -of the matrix types listed in the section on constructors, -CroutMatrix, BandLUMatrix or -GenericMatrix. Swap works by switching pointers and does not do any actual copying -of the main data arrays.

Notes:

- -
    -
  • When you do a matrix assignment to another matrix or matrix expression with -either = or << the original data array associated with the matrix - being assigned to is destroyed -even if there is no change in length. See the section on storage. -This means, in particular, that pointers to matrix elements - e.g. -Real* a; a = &(A(1,1)); become invalid. If you want avoid this you - can use -Inject rather than =. But remember that you may need to zero - the matrix first.
    -
  • -
- -

3.4 Entering values

-

next - skip - -up - start

-

You can load the elements of a matrix from an array:

-
    Matrix A(3,2);
+    Matrix A(m,n); A = r;
+ + To swap the values in two matrices A and B use one of the + following expressions +
   A.swap(B);
+
   swap(A,B);
+ The matrices A and B must be of the same type. This can be + any of the matrix types listed in the + section on constructors, + CroutMatrix, BandLUMatrix or + GenericMatrix. Swap works by switching pointers and + does not do any actual copying of the main data arrays. +

Notes:

+ +
    +
  • + When you do a matrix assignment to another matrix or matrix expression + with either = or << the original data array + associated with the matrix being assigned to is destroyed even if there + is no change in length. See the section on storage. + This means, in particular, that pointers to matrix elements - e.g. + Real* a; a = &(A(1,1)); become invalid. If you want avoid + this you can use Inject rather than =. But remember + that you may need to zero the matrix first.
    +
  • +
+ +

3.4 Entering values

+

+ next - skip - + up - start +

+

You can load the elements of a matrix from an array:

+
+    Matrix A(3,2);
     Real a[] = { 11,12,21,22,31,33 };
-    A << a;
-

or

-
    Matrix A(3,2);
+    A << a;
+

or

+
+    Matrix A(3,2);
     int a[] = { 11,12,21,22,31,33 };
     A << a;
-

This construction does not check that the numbers of elements match -correctly. This version of << can be used with submatrices on -the left hand side. It is not defined for band matrices.

-

Note that you enter only the values stored in a matrix. For example

-
    SymmetricMatrix A(2);
+    

+ This construction does not check that the numbers of elements match + correctly. This version of << can be used with submatrices + on the left hand side. It is not defined for band matrices. +

+

Note that you enter only the values stored in a matrix. For example

+
+    SymmetricMatrix A(2);
     Real a[] = { 11,12,22 };
     A << a;
-

Alternatively you can enter short lists using a sequence of numbers -separated by << .

-
    Matrix A(3,2);
+    

+ Alternatively you can enter short lists using a sequence of numbers + separated by << . +

+
+    Matrix A(3,2);
     A << 11 << 12
       << 21 << 22
       << 31 << 32;
-
- -

This does check for the correct total number of entries, although the -message for there being insufficient numbers in the list may be delayed until -the end of the block or the next use of this construction. This does not -work for band matrices or for long lists. It does work for submatrices if the -submatrix is a single complete row. For example

-
    Matrix A(3,2);
+
+ +

+ This does check for the correct total number of entries, although the + message for there being insufficient numbers in the list may be delayed + until the end of the block or the next use of this construction. This does + not work for band matrices or for long lists. It does work for + submatrices if the submatrix is a single complete row. For example +

+
+    Matrix A(3,2);
     A.row(1) << 11 << 12;
     A.row(2) << 21 << 22;
     A.row(3) << 31 << 32;
-
+
-

Load only values that are actually stored in the matrix. For example

-
    SymmetricMatrix S(2);
+    

Load only values that are actually stored in the matrix. For example

+
+    SymmetricMatrix S(2);
     S.row(1) << 11;
     S.row(2) << 21 << 22;
-
- -

Try to restrict this way of loading data to numbers. You can include -expressions, but these must not call a function which includes the same -construction.

- -

Remember that matrices are stored by rows and that symmetric matrices are -stored as lower triangular matrices when using these methods to enter -data.

-

3.5 Unary operators

-

next - skip - -up - start

-

The package supports unary operations

-
    X = -A;           // change sign of elements
+
+ +

+ Try to restrict this way of loading data to numbers. You can include + expressions, but these must not call a function which includes the same + construction. +

+ +

+ Remember that matrices are stored by rows and that symmetric matrices are + stored as lower triangular matrices when using these methods to + enter data. +

+

3.5 Unary operators

+

+ next - skip - + up - start +

+

The package supports unary operations

+
+    X = -A;           // change sign of elements
     X = A.t();        // transpose
     X = A.i();        // inverse (of square matrix A)
     X = A.reverse();  // reverse order of elements of vector
@@ -1647,17 +2164,21 @@ 

3.5 Unary operators

ColumnVector X = A.sum_square_rows(); // sum of squares of // elements of each row RowVector X = A.sum_square_columns(); // sum of squares of - // elements of each column
- -

See the function summary list for the older -depreciated function name.

- - -

3.6 Binary operators

-

next - skip - -up - start

-

The package supports binary operations

-
    X = A + B;       // matrix addition
+                                           // elements of each column
+ +

+ See the function summary list for the older + depreciated function name. +

+ +

3.6 Binary operators

+

+ next - skip - + up - start +

+

The package supports binary operations

+
+    X = A + B;       // matrix addition
     X = A - B;       // matrix subtraction
     X = A * B;       // matrix multiplication
     X = A.i() * B;   // equation solve (square matrix A)
@@ -1677,103 +2198,165 @@ 

3.6 Binary operators

A &= B; // A = A & B; A.SP_eq(B); // A = SP(A, B); <, >, <=, >= // included for compatibility with STL - see notes -
- -

Notes:

-
    -
  • If you are doing repeated multiplication. For example A*B*C, use -brackets to force the order of evaluation to minimise the number of operations. -If C is a column vector and A is not a vector, then it will -usually reduce the number of operations to use A*(B*C).
  • -
  • In the equation solve example case the inverse is not explicitly -calculated. An LU decomposition of A is performed and this is applied -to B. This is more efficient than calculating the inverse and then -multiplying. See also multiple matrix solving.
  • -
  • The package does not (yet?) recognise B*A.i() as an equation solve -and the inverse of A would be calculated. It is probably better to use -(A.t().i()*B.t()).t().
  • -
  • Horizontal or vertical concatenation returns a result of type Matrix, -RowVector or ColumnVector.
  • -
  • If A is m x p, B is m x q, -then A | B is m x (p+q) with the k-th row -being the elements of the k-th row of A followed by the -elements of the k-th row of B.
  • -
  • If A is p x n, B is q x n, -then A & B is (p+q) x n with the k-th -column being the elements of the k-th column of A followed by -the elements of the k-th column of B.
  • -
  • For complicated concatenations of matrices, consider instead using -submatrices.
  • -
  • See the section on submatrices on using a submatrix -on the RHS of an expression.
  • -
  • crossproduct - assumes A and B are both RowVectors of length 3 or both -ColumnVectors of length 3. Result is a Matrix of same dimension as A or B (will -automatically convert to RowVector if A and B are RowVectors and ColumnVector if -they are ColumnVectors).
  • -
  • crossproduct_rows - assumes A and B are of type Matrix with the same number -of rows and 3 columns. Does a cross product on corresponding pairs of rows.
  • -
  • crossproduct_columns - assumes A and B are of type Matrix with  the same -number of columns and 3 rows. Does a cross product on corresponding pairs of -columns.
  • -
  • Two matrices are equal if their difference is zero. They may be of -different types. For the CroutMatrix or BandLUMatrix they must be of the same -type and have all their elements equal. This is not a very useful operator and -is included for compatibility with some container templates.
  • -
  • The inequality operators are included for compatibility with some versions -of the -standard template library. If actually called, they will -throw an exception. So don't try to sort a list of matrices.
  • -
  • A row vector multiplied by a column vector yields a 1x1 matrix, not -a Real. To get a Real result use either as_scalar or -dotproduct.
  • -
  • The result from Kronecker product, KP(A, B), possesses an attribute such as -upper triangular, lower triangular, band, symmetric, diagonal if both of the -matrices A and B have the attribute. If A is band and B is a square type -(eg SquareMatrix, Diagonal, LowerTriangularMatrix etc) then -the result is band.
  • -
  • Elementwise product is also known as the Schur product or the Hadamard -product.
  • -
  • See the function summary list for the older -depreciated function names.
  • -
-

Remember that the product of symmetric matrices is not -necessarily symmetric so the following code will not run:

-
   SymmetricMatrix A, B;
+
+ +

Notes:

+
    +
  • + If you are doing repeated multiplication. For example A*B*C, + use brackets to force the order of evaluation to minimise the number of + operations. If C is a column vector and A is not a + vector, then it will usually reduce the number of operations to use + A*(B*C). +
  • +
  • + In the equation solve example case the inverse is not explicitly + calculated. An LU decomposition of A is performed and this is + applied to B. This is more efficient than calculating the + inverse and then multiplying. See also + multiple matrix solving. +
  • +
  • + The package does not (yet?) recognise B*A.i() as an equation + solve and the inverse of A would be calculated. It is probably + better to use (A.t().i()*B.t()).t(). +
  • +
  • + Horizontal or vertical concatenation returns a result of type Matrix, + RowVector or ColumnVector. +
  • +
  • + If A is m x p, B is m x + q, then A | B is m x (p+q) with + the k-th row being the elements of the k-th row of + A followed by the elements of the k-th row of + B. +
  • +
  • + If A is p x n, B is q x + n, then A & B is (p+q) x + n with the k-th column being the elements of the + k-th column of A followed by the elements of the + k-th column of B. +
  • +
  • + For complicated concatenations of matrices, consider instead using + submatrices. +
  • +
  • + See the section on submatrices on using a + submatrix on the RHS of an expression. +
  • +
  • + crossproduct - assumes A and B are both RowVectors of length 3 or both + ColumnVectors of length 3. Result is a Matrix of same dimension as A or + B (will automatically convert to RowVector if A and B are RowVectors and + ColumnVector if they are ColumnVectors). +
  • +
  • + crossproduct_rows - assumes A and B are of type Matrix with the same + number of rows and 3 columns. Does a cross product on corresponding + pairs of rows. +
  • +
  • + crossproduct_columns - assumes A and B are of type Matrix with  the + same number of columns and 3 rows. Does a cross product on corresponding + pairs of columns. +
  • +
  • + Two matrices are equal if their difference is zero. They may be of + different types. For the CroutMatrix or BandLUMatrix they must be of the + same type and have all their elements equal. This is not a very useful + operator and is included for compatibility with some container + templates. +
  • +
  • + The inequality operators are included for compatibility with some + versions of the standard template library. If + actually called, they will throw an exception. So don't try to sort a + list of matrices. +
  • +
  • + A row vector multiplied by a column vector yields a 1x1 matrix, + not a Real. To get a Real result use either + as_scalar or dotproduct. +
  • +
  • + The result from Kronecker product, KP(A, B), possesses an + attribute such as upper triangular, lower triangular, band, symmetric, + diagonal if both of the matrices A and B have the + attribute. If A is band and B is a square type (eg + SquareMatrix, Diagonal, LowerTriangularMatrix etc) then the result is + band. +
  • +
  • + Elementwise product is also known as the Schur product or the Hadamard + product. +
  • +
  • + See the function summary list for the older + depreciated function names. +
  • +
+

+ Remember that the product of symmetric matrices is not necessarily + symmetric so the following code will not run: +

+
+   SymmetricMatrix A, B;
    .... put values in A, B ....
-   SymmetricMatrix C = A * B;   // run time error
- -

Use instead

-
   Matrix C = A * B;
- -

or, if you know the product will be symmetric, -use

-
   SymmetricMatrix C; C << A * B;
-
- -

3.7 Matrix and scalar

-

next - skip - -up - start

-

The following expressions multiply the elements of a matrix A by a -scalar f: A * f or f * A . Likewise one can divide -the elements of a matrix A by a scalar f: A / f . -

-

The expressions A + f and A - f add or subtract a -rectangular matrix of the same dimension as A with elements equal to -f to or from the matrix A .

-

The expression f + A is an alternative to A + f. The -expression f - A subtracts matrix A from a rectangular matrix -of the same dimension as A and with elements equal to f . -

-

The expression A += f replaces A by A + f. -Operators -=, *=, /= are similarly defined.

-

3.8 Scalar functions of a -matrix - size & shape

-

next - skip - -up - start

-

This page describes functions returning the values associated with the size -and shape of matrices. The following pages describe other scalar matrix -functions.

-
    int m = A.nrows();                     // number of rows
+   SymmetricMatrix C = A * B;   // run time error
+ +

Use instead

+
   Matrix C = A * B;
+ +

+ or, if you know the product will be symmetric, use +

+
+   SymmetricMatrix C; C << A * B;
+
+ +

3.7 Matrix and scalar

+

+ next - skip - + up - start +

+

+ The following expressions multiply the elements of a matrix A by + a scalar f: A * f or f * A . Likewise one can + divide the elements of a matrix A by a scalar f: + A / f . +

+

+ The expressions A + f and A - f add or subtract a + rectangular matrix of the same dimension as A with elements equal + to f to or from the matrix A . +

+

+ The expression f + A is an alternative to A + f. The + expression f - A subtracts matrix A from a rectangular + matrix of the same dimension as A and with elements equal to + f . +

+

+ The expression A += f replaces A by A + f. + Operators -=, *=, /= are similarly defined. +

+

+ 3.8 Scalar functions of a matrix - size & shape +

+

+ next - skip - + up - start +

+

+ This page describes functions returning the values associated with the + size and shape of matrices. The following pages describe other scalar + matrix functions. +

+
+    int m = A.nrows();                     // number of rows
     int n = A.ncols();                     // number of columns
     MatrixType mt = A.type();              // type of matrix
     Real* s = A.data();                    // pointer to array of elements
@@ -1782,24 +2365,37 @@ 

3.8 Scalar functions of a const Real* s = A.const_data(); // pointer to array of elements int l = A.size(); // length of array of elements MatrixBandWidth mbw = A.bandwidth(); // upper and lower bandwidths -

- -

MatrixType mt = A.type() returns the type of a matrix. Use -mt.value() to get a string (UT, LT, Rect, Sym, Diag, Band, UB, LB, -Crout, BndLU) showing the type (Vector types are returned as Rect).

-

MatrixBandWidth has member functions upper() and -lower() for finding the upper and lower bandwidths (number of diagonals -above and below the diagonal, both zero for a diagonal matrix). For non-band -matrices -1 is returned for both these values.

-

See the function summary list for the older -depreciated function names.

-

3.9 Scalar functions of a -matrix - maximum & minimum

-

next - skip - -up - start

-

This page describes functions for finding the maximum and minimum elements -of a matrix.

-
    int i, j;
+
+ +

+ MatrixType mt = A.type() returns the type of a matrix. Use + mt.value() to get a string (UT, LT, Rect, Sym, Diag, Band, UB, + LB, Crout, BndLU) showing the type (Vector types are returned as Rect). +

+

+ MatrixBandWidth has member functions upper() and + lower() for finding the upper and lower bandwidths (number of + diagonals above and below the diagonal, both zero for a diagonal matrix). + For non-band matrices -1 is returned for both these values. +

+

+ See the function summary list for the older + depreciated function names. +

+

+ 3.9 Scalar functions of a matrix - maximum & + minimum +

+

+ next - skip - + up - start +

+

+ This page describes functions for finding the maximum and minimum elements + of a matrix. +

+
+    int i, j;
     Real mv = A.maximum_absolute_value();    // maximum of absolute values
     Real mv = A.minimum_absolute_value();    // minimum of absolute values
     Real mv = A.maximum();                   // maximum value
@@ -1812,23 +2408,31 @@ 

3.9 Scalar functions of a Real mv = A.minimum_absolute_value2(i,j);// minimum of absolute values Real mv = A.maximum2(i,j); // maximum value Real mv = A.minimum2(i,j); // minimum value -

- -

All these functions throw an exception if A has no rows or no -columns.

-

The versions A.maximum_absolute_value1(i), etc return the location of -the extreme element in a RowVector, ColumnVector or DiagonalMatrix. The -versions A.maximum_absolute_value2(i,j), etc return the row and column -numbers of the extreme element. If the extreme value occurs more than once the -location of the last one is given.

-

The versions maximum_absolute_value(A), minimum_absolute_value(A), maximum(A), -minimum(A) can be used in place of A.maximum_absolute_value(), -A.minimum_absolute_value(), A.maximum(), A.minimum().

-

3.10 Scalar functions of a -matrix - numerical

-

next - skip - -up - start

-
    Real r = A.as_scalar();                // value of 1x1 matrix
+
+ +

+ All these functions throw an exception if A has no rows or no + columns. +

+

+ The versions A.maximum_absolute_value1(i), etc return the + location of the extreme element in a RowVector, ColumnVector or + DiagonalMatrix. The versions A.maximum_absolute_value2(i,j), etc + return the row and column numbers of the extreme element. If the extreme + value occurs more than once the location of the last one is given. +

+

+ The versions maximum_absolute_value(A), minimum_absolute_value(A), + maximum(A), minimum(A) can be used in place of A.maximum_absolute_value(), + A.minimum_absolute_value(), A.maximum(), A.minimum(). +

+

3.10 Scalar functions of a matrix - numerical

+

+ next - skip - + up - start +

+
+    Real r = A.as_scalar();                // value of 1x1 matrix
     Real ssq = A.sum_square();             // sum of squares of elements
     Real sav = A.sum_absolute_value();     // sum of absolute values
     Real s = A.sum();                      // sum of values
@@ -1846,74 +2450,111 @@ 

3.10 Scalar functions of a BandLUMatrix Real s = dotproduct(A, B); // dot product of A and B // interpreted as vectors -

- -

See the function summary list for the older -depreciated function names.

+
-

A.log_determinant() returns a value of type LogAndSign. If ld is of -type LogAndSign use

-
    ld.value()     to get the value of the determinant
+    

+ See the function summary list for the older + depreciated function names. +

+ +

+ A.log_determinant() returns a value of type LogAndSign. If + ld is of type LogAndSign use +

+
+    ld.value()     to get the value of the determinant
     ld.sign()      to get the sign of the determinant (values 1, 0, -1)
     ld.log_value() to get the log of the absolute value.
-
- -

Note that the direct use of the function determinant() will often -cause a floating point overflow exception.

-

A.is_zero() returns Boolean value true if the matrix -A has all elements equal to 0.0.

-

is_singular() is defined only for CroutMatrix and BandLUMatrix. It -returns true if one of the diagonal elements of the LU decomposition -is exactly zero.

-

dotproduct(const Matrix& A, const Matrix& B) converts both -of the arguments to rectangular matrices, checks that they have the same number -of elements and then calculates the first element of A * first element -of B + second element of A * second element of B + -... ignoring the row/column structure of A and B. It is -primarily intended for the situation where A and B are row or -column vectors.

-

The versions sum(A), sum_square(A), sum_absolute_value(A), trace(A), -log_determinant(A), determinant(A), norm1(A), norm_infinity(A), norm_Frobenius(A) -can be used in place of A.sum(), A.sum_square(), A.sum_absolute_value(), -A.trace(), A.log_determinant(), A.determinant(A), A.norm1(), A.norm_infinity(), A.norm_Frobenius(). -

-

3.11 Submatrices

-

next - skip - -up - start

-
    A.submatrix(fr,lr,fc,lc)
-
- -

This selects a submatrix from A. The arguments -fr,lr,fc,lc are the first row, last row, -first column, last column of the submatrix with the numbering beginning at 1. -

-

I allow lr = fr-1 or lc = fc-1 or to indicate that a -matrix of zero rows or columns is to be returned.

-

A submatrix command may be used in any matrix expression or on the left hand -side of =, << or inject. inject does not check -no information loss. You can also use the construction

-
    Real c; .... A.submatrix(fr,lr,fc,lc) = c;
-
- -

to set a submatrix equal to a constant.

-

The following are variants of submatrix:

-
    A.sym_submatrix(f,l)            //   assumes fr=fc and lr=lc
+
+ +

+ Note that the direct use of the function determinant() will often + cause a floating point overflow exception. +

+

+ A.is_zero() returns Boolean value true if the matrix + A has all elements equal to 0.0. +

+

+ is_singular() is defined only for CroutMatrix and BandLUMatrix. + It returns true if one of the diagonal elements of the LU + decomposition is exactly zero. +

+

+ dotproduct(const Matrix& A, const Matrix& B) converts + both of the arguments to rectangular matrices, checks that they have the + same number of elements and then calculates the first element of + A * first element of B + second element of + A * second element of B + ... ignoring the row/column + structure of A and B. It is primarily intended for the + situation where A and B are row or column vectors. +

+

+ The versions sum(A), sum_square(A), sum_absolute_value(A), trace(A), + log_determinant(A), determinant(A), norm1(A), norm_infinity(A), + norm_Frobenius(A) can be used in place of A.sum(), A.sum_square(), + A.sum_absolute_value(), A.trace(), A.log_determinant(), A.determinant(A), + A.norm1(), A.norm_infinity(), A.norm_Frobenius(). +

+

3.11 Submatrices

+

+ next - skip - + up - start +

+
+    A.submatrix(fr,lr,fc,lc)
+
+ +

+ This selects a submatrix from A. The arguments + fr,lr,fc,lc are the first row, last + row, first column, last column of the submatrix with the numbering + beginning at 1. +

+

+ I allow lr = fr-1 or lc = fc-1 or to indicate that a + matrix of zero rows or columns is to be returned. +

+

+ A submatrix command may be used in any matrix expression or on the left + hand side of =, << or inject. + inject does not check no information loss. You can also use + the construction +

+
+    Real c; .... A.submatrix(fr,lr,fc,lc) = c;
+
+ +

to set a submatrix equal to a constant.

+

The following are variants of submatrix:

+
+    A.sym_submatrix(f,l)            //   assumes fr=fc and lr=lc
     A.rows(f,l)                     //   select rows
     A.row(f)                        //   select single row
     A.columns(f,l)                  //   select columns
     A.column(f)                     //   select single column
-
- -

See the function summary list for the older -depreciated function names.

- -

In each case f and l mean the first and last row or column -to be selected (starting at 1).

-

I allow l = f-1 to indicate that a matrix of zero rows or columns -is to be returned.

-

If submatrix or its variant occurs on the right hand side of an = -or << or within an expression think of its type as follows

-
    A.submatrix(fr,lr,fc,lc)           If A is RowVector or
+
+ +

+ See the function summary list for the older + depreciated function names. +

+ +

+ In each case f and l mean the first and last row or + column to be selected (starting at 1). +

+

+ I allow l = f-1 to indicate that a matrix of zero rows or columns + is to be returned. +

+

+ If submatrix or its variant occurs on the right hand side of an + = or << or within an expression think of its type + as follows +

+
+    A.submatrix(fr,lr,fc,lc)           If A is RowVector or
                                        ColumnVector then same type
                                        otherwise type Matrix
     A.sym_submatrix(f,l)               Same type as A
@@ -1921,44 +2562,64 @@ 

3.11 Submatrices

A.row(f) Type RowVector A.columns(f,l) Type Matrix A.column(f) Type ColumnVector -
- -

If submatrix or its variant appears on the left hand side of = or -<< , think of its type being Matrix. Thus L.row(1) -where L is LowerTriangularMatrix expects L.ncols() elements -even though it will use only one of them. If you are using = the -program will check for no loss of data.

- -

A submatrix can appear on the left-hand side of += or -= -with a matrix expression on the right-hand side. It can also appear on the -left-hand side of +=, -=, *= or /= with a -Real on the right-hand side. In each case there must be no loss of information. -The SP_eq function is also defined for a submatrix. -

-

The row version can appear on the left hand side of -<< for loading literal data into a row. -Load only the number of elements that are actually going to be stored in -memory.

-

Do not use the += and -= operations with a submatrix of a -SymmetricMatrix or BandSymmetricMatrix on the LHS.

-

You can't pass a submatrix (or any of its variants) as a reference -non-constant matrix in a function argument. For example, the following will not -work:

-
   void YourFunction(Matrix& A);
+
+ +

+ If submatrix or its variant appears on the left hand side of = or + << , think of its type being Matrix. Thus + L.row(1) where L is LowerTriangularMatrix expects + L.ncols() elements even though it will use only one of them. If + you are using = the program will check for no loss of data. +

+ +

+ A submatrix can appear on the left-hand side of += or + -= with a matrix expression on the right-hand side. It can also + appear on the left-hand side of +=, -=, *= or + /= with a Real on the right-hand side. In each case there must be + no loss of information. The SP_eq function is also + defined for a submatrix. +

+

+ The row version can appear on the left hand side of + << for loading literal data into a + row. Load only the number of elements that are actually going to be stored + in memory. +

+

+ Do not use the += and -= operations with a submatrix + of a SymmetricMatrix or BandSymmetricMatrix on the LHS. +

+

+ You can't pass a submatrix (or any of its variants) as a reference + non-constant matrix in a function argument. For example, the following + will not work: +

+
+   void YourFunction(Matrix& A);
    ...
    Matrix B(10,10);
    YourFunction(B.submatrix(1,5,1,5))    // won't compile
-

If you are are using the submatrix facility to build a matrix from a small -number of components, consider instead using the concatenation operators.

-

3.12 Change dimensions

-

next - skip - -up - start

-

The following operations change the dimensions of a matrix. The values of the -elements are lost, for resize. resize_keep keeps element -values and zeros the elements in the matrix with the new size that are not in -the matrix with the old size.

-
    A.resize(nrows,ncols);        // for type Matrix or nricMatrix
+    

+ If you are are using the submatrix facility to build a matrix from a small + number of components, consider instead using the + concatenation operators. +

+

3.12 Change dimensions

+

+ next - skip - + up - start +

+

+ The following operations change the dimensions of a matrix. The values of + the elements are lost, for resize. resize_keep keeps + element values and zeros the elements in the matrix with the new size that + are not in the matrix with the old size. +

+
+    A.resize(nrows,ncols);        // for type Matrix or nricMatrix
     A.resize(n);                  // for other types, except Band
     A.resize(n,lower,upper);      // for BandMatrix
     A.resize(n,lower);            // for LowerBandMatrix
@@ -1968,450 +2629,654 @@ 

3.12 Change dimensions

A.cleanup(); // resize to zero dimensions A.resize_keep(nrows,ncols); // for type Matrix or nricMatrix, keep values A.resize_keep(n); // for other types, except Band, keep values -
- -

Use A.cleanup() to set the dimensions of A to zero and -release all the heap memory.

-

A.resize(B) sets the dimensions of A to those of a matrix -B. This includes the band-width in the case of a band matrix. It is an -error for A to be a band matrix and B not a band matrix (or -diagonal matrix).

-

Remember that resize destroys values. If you want to resize, but -keep the values in the bit that is left use resize_keep.

-

See the function summary list for the older -depreciated function names.

- -

3.13 Change type

-

next - skip - -up - start

-

The following functions interpret the elements of a matrix (stored row by -row) to be a vector or matrix of a different type. Actual copying is usually -avoided where these occur as part of a more complicated expression.

-
    A.as_row()
+
+ +

+ Use A.cleanup() to set the dimensions of A to zero and + release all the heap memory. +

+

+ A.resize(B) sets the dimensions of A to those of a + matrix B. This includes the band-width in the case of a band + matrix. It is an error for A to be a band matrix and + B not a band matrix (or diagonal matrix). +

+

+ Remember that resize destroys values. If you want to resize, but + keep the values in the bit that is left use resize_keep. +

+

+ See the function summary list for the older + depreciated function names. +

+ +

3.13 Change type

+

+ next - skip - + up - start +

+

+ The following functions interpret the elements of a matrix (stored row by + row) to be a vector or matrix of a different type. Actual copying is + usually avoided where these occur as part of a more complicated + expression. +

+
+    A.as_row()
     A.as_column()
     A.as_diagonal()
     A.as_matrix(nrows,ncols)
     A.as_scalar()
-
- -

The expression A.as_scalar() is used to convert a 1 x 1 matrix to a -scalar.

-

See the function summary list for the older -depreciated function names.

-

3.14 Multiple matrix solve

-

next - skip - -up - start

-

To solve the matrix equation Ay = b where A is a square -matrix of equation coefficients, y is a column vector of values to be -solved for, and b is a column vector, use the code

-
    int n = something
+
+ +

+ The expression A.as_scalar() is used to convert a 1 x 1 matrix to + a scalar. +

+

+ See the function summary list for the older + depreciated function names. +

+

3.14 Multiple matrix solve

+

+ next - skip - + up - start +

+

+ To solve the matrix equation Ay = b where A is a square + matrix of equation coefficients, y is a column vector of values + to be solved for, and b is a column vector, use the code +

+
+    int n = something
     Matrix A(n,n); ColumnVector b(n);
     ... put values in A and b
     ColumnVector y = A.i() * b;       // solves matrix equation
-
- -

The following notes are for the case where you want to solve more than one -matrix equation with different values of b but the same A. Or -where you want to solve a matrix equation and also find the determinant of -A. In these cases you probably want to avoid repeating the LU -decomposition of A for each solve or determinant calculation.

-

If A is a square or symmetric matrix use

-
    ColumnVector p, q;    
+
+ +

+ The following notes are for the case where you want to solve more than one + matrix equation with different values of b but the same + A. Or where you want to solve a matrix equation and also find the + determinant of A. In these cases you probably want to avoid + repeating the LU decomposition of A for each solve or determinant + calculation. +

+

If A is a square or symmetric matrix use

+
+    ColumnVector p, q;
     ...
     CroutMatrix X = A;                // carries out LU decomposition
     ColumnVector Ap = X.i()*p; ColumnVector Aq = X.i()*q;
     LogAndSign ld = X.log_determinant();
-
+
-

rather than

-
    ColumnVector p, q;    
+    

rather than

+
+    ColumnVector p, q;
     ...
     ColumnVector Ap = A.i()*p; ColumnVector Aq = A.i()*q;
     LogAndSign ld = A.log_determinant();
-
- -

since each operation will repeat the LU decomposition.

-

If A is a BandMatrix or a SymmetricBandMatrix begin with

-
    BandLUMatrix X = A;               // carries out LU decomposition
-
- -

A CroutMatrix or BandLUMatrix can be copied and you can have a constructor -with no parameters (use = to give it values). They work with -release(), release_and_delete and -GenericMatrix and ReturnMatrix. You -can't do any other manipulation apart from taking the inverse or solving with -i(), or finding the determinant or log determinant. See the function summary list -for accessing the internals of a CroutMatrix or BandLUMatrix.

-

You can alternatively use

-
    LinearEquationSolver X = A;
-
- -

This will choose the most appropriate decomposition of A. That is, -the band form if A is banded; the Crout decomposition if A is -square or symmetric and no decomposition if A is triangular or -diagonal. It doesn't know about positive definite matrices so won't use -Cholesky.

-

3.15 Memory management

-

next - skip - -up - start

-

The package does not support delayed copy. Several strategies are required -to prevent unnecessary matrix copies.

-

Where a matrix is called as a function argument use a constant reference. -For example

-
    YourFunction(const Matrix& A)
-
- -

rather than

-
    YourFunction(Matrix A)
-
- -

Skip the rest of this section on your first reading.

-

A second place where it is desirable to avoid unnecessary copies is when a -function is returning a matrix. Matrices can be returned from a function with -the return command as you would expect. However these may incur one and -possibly two copyings of the matrix. To avoid this use the following -instructions.

-

Make your function of type ReturnMatrix . Then precede the return statement -with a release statement (or a release_and_delete statement if the matrix was -created with new). For example

-
    ReturnMatrix MakeAMatrix()
+
+ +

since each operation will repeat the LU decomposition.

+

If A is a BandMatrix or a SymmetricBandMatrix begin with

+
+    BandLUMatrix X = A;               // carries out LU decomposition
+
+ +

+ A CroutMatrix or BandLUMatrix can be copied and you can have a constructor + with no parameters (use = to give it values). They work with + release(), release_and_delete and + GenericMatrix and + ReturnMatrix. You can't do any other manipulation + apart from taking the inverse or solving with i(), or finding the + determinant or log determinant. See the + function summary list for accessing the internals + of a CroutMatrix or BandLUMatrix. +

+

You can alternatively use

+
+    LinearEquationSolver X = A;
+
+ +

+ This will choose the most appropriate decomposition of A. That + is, the band form if A is banded; the Crout decomposition if + A is square or symmetric and no decomposition if A is + triangular or diagonal. It doesn't know about positive definite matrices + so won't use Cholesky. +

+

3.15 Memory management

+

+ next - skip - + up - start +

+

+ The package does not support delayed copy. Several strategies are required + to prevent unnecessary matrix copies. +

+

+ Where a matrix is called as a function argument use a constant reference. + For example +

+
+    YourFunction(const Matrix& A)
+
+ +

rather than

+
+    YourFunction(Matrix A)
+
+ +

Skip the rest of this section on your first reading.

+

+ A second place where it is desirable to avoid unnecessary copies is when a + function is returning a matrix. Matrices can be returned from a function + with the return command as you would expect. However these may incur one + and possibly two copyings of the matrix. To avoid this use the following + instructions. +

+

+ Make your function of type ReturnMatrix . Then precede the return + statement with a release statement (or a + release_and_delete statement if the matrix was created with new). + For example +

+
+    ReturnMatrix MakeAMatrix()
     {
        Matrix A;                // or any other matrix type
        ......
        A.release(); return A;
     }
-
+
-

or

-
    ReturnMatrix MakeAMatrix()
+    

or

+
+    ReturnMatrix MakeAMatrix()
     {
        Matrix* m = new Matrix;
        ......
        m->release_and_delete(); return *m;
     }
-
+
-

If your compiler objects to this code, replace the return statements with -

-
    return A.for_return();
-
+

+ If your compiler objects to this code, replace the return statements with +

+
+    return A.for_return();
+
-

or

-
    return m->for_return();
+

or

+
    return m->for_return();
-
-

Do not forget to make the function of type ReturnMatrix.

-
-

In particular, don't do

-
    Matrix MakeAMatrix()
+    
+

+ Do not forget to make the function of type ReturnMatrix. +

+
+

In particular, don't do

+
    Matrix MakeAMatrix()
     {
        Matrix A;                // or any other matrix type
        ......
        A.release(); return A;   // will compile but could give wrong answers.
     }
-

since with some compilers A might retain its released status -after being returned.

-

You can also use .release() or ->release_and_delete() to -allow a matrix expression to recycle space. Suppose you call

-
    A.release();
-
- -

just before A is used just once in an expression. Then the memory -used by A is either returned to the system or reused in the -expression. In either case, A's memory is destroyed. This procedure -can be used to improve efficiency and reduce the use of memory.

-

Use ->release_and_delete for matrices created by new if you want -to completely delete the matrix after it is accessed.

-

See the function summary list for the older -depreciated function names.

-

3.16 Efficiency

-

next - skip - -up - start

-

The package tends to be not very efficient for dealing with matrices with -short rows. This is because some administration is required for accessing rows -for a variety of types of matrices. To reduce the administration a special -multiply routine is used for rectangular matrices in place of the generic one. -Where operations can be done without reference to the individual rows (such as -adding matrices of the same type) appropriate routines are used.

-

When you are using small matrices (say smaller than 10 x 10) you may find it -faster to use rectangular matrices rather than the triangular or symmetric -ones.

-

3.17 Output

-

next - skip - -up - start

-

To print a matrix use an expression like

-
   Matrix A, B C;
+    

+ since with some compilers A might retain its + released status after being returned. +

+

+ You can also use .release() or + ->release_and_delete() to allow a matrix expression to recycle + space. Suppose you call +

+
+    A.release();
+
+ +

+ just before A is used just once in an expression. Then the memory + used by A is either returned to the system or reused in the + expression. In either case, A's memory is destroyed. This + procedure can be used to improve efficiency and reduce the use of memory. +

+

+ Use ->release_and_delete for matrices created by new if you + want to completely delete the matrix after it is accessed. +

+

+ See the function summary list for the older + depreciated function names. +

+

3.16 Efficiency

+

+ next - skip - + up - start +

+

+ The package tends to be not very efficient for dealing with matrices with + short rows. This is because some administration is required for accessing + rows for a variety of types of matrices. To reduce the administration a + special multiply routine is used for rectangular matrices in place of the + generic one. Where operations can be done without reference to the + individual rows (such as adding matrices of the same type) appropriate + routines are used. +

+

+ When you are using small matrices (say smaller than 10 x 10) you may find + it faster to use rectangular matrices rather than the triangular or + symmetric ones. +

+

3.17 Output

+

+ next - skip - + up - start +

+

To print a matrix use an expression like

+
+   Matrix A, B C;
    ......
    cout << setw(10) << setprecision(5) << A << endl;
    cout << setw(10) << setprecision(5) << scientific << B << endl;
    cout << setw(10) << setprecision(5) << fixed << C << endl;
-
- -

This will work only with systems that support the standard input/output -routines including manipulators. The scientific and fixed manipulators won't -work with Visual C++, version 6.

-

You need to #include the files iostream.h, -iomanip.h, newmatio.h in your C++ source files that use this facility. The -files iostream.h, iomanip.h will be included automatically if you include the -statement #define WANT_STREAM at the beginning of your source file. So -you can begin your file with either

-
   #define WANT_STREAM
+
+ +

+ This will work only with systems that support the standard input/output + routines including manipulators. The scientific and fixed manipulators + won't work with Visual C++, version 6. +

+

+ You need to #include the files iostream.h, iomanip.h, newmatio.h in your + C++ source files that use this facility. The files iostream.h, iomanip.h + will be included automatically if you include the statement + #define WANT_STREAM at the beginning of your source file. So you + can begin your file with either +

+
+   #define WANT_STREAM
    #include "newmatio.h"
-
+
-

or

-
   #include <iostream>
+    

or

+
+   #include <iostream>
    #include <iomanip>
    #include "newmatio.h"
-
+
-

The present version of this routine is useful only for matrices small enough -to fit within a page or screen width.

-

To print several vectors or matrices in columns use a concatenation operator:

-
   ColumnVector A, B;
+    

+ The present version of this routine is useful only for matrices small + enough to fit within a page or screen width. +

+

+ To print several vectors or matrices in columns use a + concatenation operator: +

+
+   ColumnVector A, B;
    .....
    cout << setw(10) << setprecision(5) << (A | B) << endl;
-
- -

3.18 Unspecified type

-

next - skip - -up - start

-

Skip this section on your first reading.

-

If you want to work with a matrix of unknown type, say in a function. You -can construct a matrix of type GenericMatrix. Eg

-
   Matrix A;
+
+ +

3.18 Unspecified type

+

+ next - skip - + up - start +

+

Skip this section on your first reading.

+

+ If you want to work with a matrix of unknown type, say in a function. You + can construct a matrix of type GenericMatrix. Eg +

+
+   Matrix A;
    .....                                  // put some values in A
    GenericMatrix GM = A;
-
- -

A GenericMatrix matrix can be used anywhere where a matrix expression can be -used and also on the left hand side of an =. You can pass any type of -matrix to a const -GenericMatrix& argument in a function. However most scalar functions -including nrows(), ncols(), type() and element access do not work with it. Nor -does the ReturnMatrix construct. swap does work with objects of type -GenericMatrix. See also the paragraph on LinearEquationSolver.

-

An alternative and less flexible approach is to use BaseMatrix or -GeneralMatrix.

-

Suppose you wish to write a function which accesses a matrix of unknown type -including expressions (eg A*B). Then use a layout similar to the -following:

-
   void YourFunction(BaseMatrix& X)
+
+ +

+ A GenericMatrix matrix can be used anywhere where a matrix expression can + be used and also on the left hand side of an =. You can pass any + type of matrix to a const GenericMatrix& argument in a + function. However most scalar functions including nrows(), ncols(), type() + and element access do not work with it. Nor does the ReturnMatrix + construct. swap does work with objects of + type GenericMatrix. See also the paragraph on + LinearEquationSolver. +

+

+ An alternative and less flexible approach is to use BaseMatrix or + GeneralMatrix. +

+

+ Suppose you wish to write a function which accesses a matrix of unknown + type including expressions (eg A*B). Then use a layout similar to + the following: +

+
+   void YourFunction(BaseMatrix& X)
    {
       GeneralMatrix* gm = X.Evaluate();   // evaluate an expression
                                           // if necessary
       ........                            // operations on *gm
       gm->tDelete();                      // delete *gm if a temporary
    }
-
- -

See, as an example, the definitions of operator<< in -newmat9.cpp.

-

Under certain circumstances; particularly where X is to be used -just once in an expression you can leave out the Evaluate() statement -and the corresponding tDelete(). Just use X in the -expression.

-

If you know YourFunction will never have to handle a formula as its argument -you could also use

-
   void YourFunction(const GeneralMatrix& X)
+
+ +

+ See, as an example, the definitions of operator<< in + newmat9.cpp. +

+

+ Under certain circumstances; particularly where X is to be used + just once in an expression you can leave out the + Evaluate() statement and the corresponding tDelete(). + Just use X in the expression. +

+

+ If you know YourFunction will never have to handle a formula as its + argument you could also use +

+
+   void YourFunction(const GeneralMatrix& X)
    {
       ........                            // operations on X
    }
-
- -

Do not try to construct a GeneralMatrix or BaseMatrix.

-

3.19 Cholesky -decomposition

-

next - skip - -up - start

-

Suppose S is symmetric and positive definite. Then there exists a -unique lower triangular matrix L such that L * L.t() = S. To -calculate this use

-
    SymmetricMatrix S;
+
+ +

Do not try to construct a GeneralMatrix or BaseMatrix.

+

3.19 Cholesky decomposition

+

+ next - skip - + up - start +

+

+ Suppose S is symmetric and positive definite. Then there exists a + unique lower triangular matrix L such that + L * L.t() = S. To calculate this use +

+
+    SymmetricMatrix S;
     ......
     LowerTriangularMatrix L = Cholesky(S);
-
+
-

If S is a symmetric band matrix then L is a band matrix -and an alternative procedure is provided for carrying out the decomposition: -

-
    SymmetricBandMatrix S;
+    

+ If S is a symmetric band matrix then L is a band matrix + and an alternative procedure is provided for carrying out the + decomposition: +

+
+    SymmetricBandMatrix S;
     ......
-    LowerBandMatrix L = Cholesky(S);
- -

See section 3.32 on updating a Cholesky -decomposition.
-

- -

3.20 QR decomposition

-

next - skip - -up - start

-

This is a variant on the usual QR transformation.

-

Start with matrix (dimensions shown to left and below the matrix)

-
       / 0    0 \      s
+    LowerBandMatrix L = Cholesky(S);
+ +

+ See section 3.32 on updating a Cholesky + decomposition.
+

+ +

3.20 QR decomposition

+

+ next - skip - + up - start +

+

This is a variant on the usual QR transformation.

+

Start with matrix (dimensions shown to left and below the matrix)

+
+       / 0    0 \      s
        \ X    Y /      n
 
          s    t
-
+
-

Our version of the QR decomposition multiplies this matrix by an orthogonal -matrix Q to get

-
       / U    M \      s
+    

+ Our version of the QR decomposition multiplies this matrix by an + orthogonal matrix Q to get +

+
+       / U    M \      s
        \ 0    Z /      n
 
          s    t
-
- -

where U is upper triangular (the R of the QR transform). That is -

-
      Q  / 0   0 \  =  / U   M \
-         \ X   Y /     \ 0   Z / 
- -

This is good for solving least squares problems: choose b (matrix or column -vector) to minimise the sum of the squares of the elements of

-
         Y - X*b
-
- -

Then choose b = U.i()*M; The residuals Y - X*b are in -Z.

-

This is the usual QR transformation applied to the matrix X with -the square zero matrix concatenated on top of it. It gives the same triangular -matrix as the QR transform applied directly to X and generally seems -to work in the same way as the usual QR transform. However it fits into the -matrix package better and also gives us the residuals directly. It turns out to -be essentially a modified Gram-Schmidt decomposition.

-

Two routines are provided in newmat:

-
    QRZ(X, U);
-
- -

replaces X by orthogonal columns and forms U.

-
    QRZ(X, Y, M);
-
- -

uses X from the first routine, replaces Y by Z -and forms M. There is also a routine

-
    QRZ(X, Y, U, M);
-

which does both of these.

-

To extend U to a square orthogonal matrix see the function for -extending an orthonormal set of columns.

-

The are also routines QRZT(X, L), QRZT(X, Y, M) -and QRZT(X, Y, L, M) -which do the same decomposition on the transposes of all these matrices. QRZT -replaces the routines HHDecompose in earlier versions of newmat. -HHDecompose is -still defined but just calls QRZT.

-

For an example of the use of this decomposition see the file -example.cpp.

-

See the section on updating a Cholesky decomposition -for updating U.

-

Alternatively to update U or L with a new block of data, X, one can use

-
    updateQRZ(X, U);
 
-

or

-
    updateQRZT(X, L);
-

You can update the M matrix with

-
    updateQRZ(X, Y, M);
-

At present, there is no corresponding function for updateQRZT. Also -note, at present, updateQRZ(X, Y, M) is not optimised for accessing -contiguous locations.

-

If you have carried out QRZ transforms on two blocks of data, X1, X2, -(same number of columns in each) with the data to be fitted in Y1, -Y2, you can combine them as follows

-
    // QRZ transforms of two blocks of data
+
+    

+ where U is upper triangular (the R of the QR transform). That is +

+
+      Q  / 0   0 \  =  / U   M \
+         \ X   Y /     \ 0   Z / 
+ +

+ This is good for solving least squares problems: choose b (matrix or + column vector) to minimise the sum of the squares of the elements of +

+
+         Y - X*b
+
+ +

+ Then choose b = U.i()*M; The residuals Y - X*b are in + Z. +

+

+ This is the usual QR transformation applied to the matrix X with + the square zero matrix concatenated on top of it. It gives the same + triangular matrix as the QR transform applied directly to X and + generally seems to work in the same way as the usual QR transform. However + it fits into the matrix package better and also gives us the residuals + directly. It turns out to be essentially a modified Gram-Schmidt + decomposition. +

+

Two routines are provided in newmat:

+
+    QRZ(X, U);
+
+ +

replaces X by orthogonal columns and forms U.

+
+    QRZ(X, Y, M);
+
+ +

+ uses X from the first routine, replaces Y by + Z and forms M. There is also a routine +

+
    QRZ(X, Y, U, M);
+

which does both of these.

+

+ To extend U to a square orthogonal matrix see the function for + extending an orthonormal set of columns. +

+

+ The are also routines QRZT(X, L), QRZT(X, Y, M) and + QRZT(X, Y, L, M) which do the same decomposition on the + transposes of all these matrices. QRZT replaces the routines + HHDecompose in earlier versions of newmat. + HHDecompose is still defined but just calls QRZT. +

+

+ For an example of the use of this decomposition see the file + example.cpp. +

+

+ See the section on + updating a Cholesky decomposition for updating + U. +

+

+ Alternatively to update U or L with a new block of data, + X, one can use +

+
+    updateQRZ(X, U);
+
+

or

+
    updateQRZT(X, L);
+

You can update the M matrix with

+
    updateQRZ(X, Y, M);
+

+ At present, there is no corresponding function for updateQRZT. + Also note, at present, updateQRZ(X, Y, M) is not optimised for + accessing contiguous locations. +

+

+ If you have carried out QRZ transforms on two blocks of data, X1, + X2, (same number of columns in each) with the data to be fitted + in Y1, Y2, you can combine them as follows +

+
+    // QRZ transforms of two blocks of data
     UpperTriangularMatrix U1, U2; Matrix M1, M2;
     QRZ(X1, U1); QRZ(X2, U2); QRZ(X1, Y1, M1); QRZ(X2, Y2, M2);
 
     // Now combine the results
     updateQRZ(U1, U2); updateQRZ(U1, M1, M2);
-

Results are in U2 and M2. The values in U1 and -M1 are modified so use copies if you still need the original values.

-

The functions updateQRZ(U1, U2) and updateQRZ(U1, M1, M2) -are not optimised for accessing contiguous locations. -This is probably not an issue, since usually all the data will fit into cache -memory. 

-

Notes on updateQRZ and updateQRZT:

-
    -
  • Use these routines if your data is arriving in blocks or there is too much to -fit into memory.
  • -
  • Use QRZ or QRZT on the first block of data or you can use - updateQRZ or -updateQRZT if U or L is correctly dimensioned and set to zero.
  • -
  • The block of data, X, will be modified by these routines but the -modified data is probably not useful for further analysis.
  • -
  • The signs of some of the rows of U or columns of L maybe the reverse of what you would -expect (i.e. you get the negative of what you get from QRZ or QRZT applied to - the whole dataset). Usually this will not be a problem.
  • -
  • The second version of updateQRZ is sometimes a more useful way of - combining blocks, especially if you want to use the reduce function - in Intel's Threaded Building Blocks to parallelise QRZ. (Contact me - for what you need to do to make Newmat compatible with Threaded Building - Blocks).
  • -
  • See the function summary list for the older -depreciated function names.
  • -
-

 

-

3.21 Singular value -decomposition

-

next - skip - -up - start

-

The singular value decomposition of an m x n Matrix -A (where m >= n) is a decomposition

-
    A  = U * D * V.t()
-
- -

where U is m x n with U.t() * U equalling -the identity, D is an n x n DiagonalMatrix and -V is an n x n orthogonal matrix (type Matrix in -Newmat).

-

Singular value decompositions are useful for understanding the structure of -ill-conditioned matrices, solving least squares problems, and for finding the -eigenvalues of A.t() * A.

-

To calculate the singular value decomposition of A (with m ->= n) use one of

-
    SVD(A, D, U, V);                  // U = A is OK
+    

+ Results are in U2 and M2. The values in U1 and + M1 are modified so use copies if you still need the original + values. +

+

+ The functions updateQRZ(U1, U2) and + updateQRZ(U1, M1, M2) are not optimised for accessing + contiguous locations. This is probably not an + issue, since usually all the data will fit into cache memory.  +

+

Notes on updateQRZ and updateQRZT:

+
    +
  • + Use these routines if your data is arriving in blocks or there is too + much to fit into memory. +
  • +
  • + Use QRZ or QRZT on the first block of data or you can + use updateQRZ or updateQRZT if U or + L is correctly dimensioned and set to zero. +
  • +
  • + The block of data, X, will be modified by these routines but + the modified data is probably not useful for further analysis. +
  • +
  • + The signs of some of the rows of U or columns of + L maybe the reverse of what you would expect (i.e. you get the + negative of what you get from QRZ or QRZT applied to the whole dataset). + Usually this will not be a problem. +
  • +
  • + The second version of updateQRZ is sometimes a more useful way of + combining blocks, especially if you want to use the + reduce function in Intel's Threaded Building Blocks to + parallelise QRZ. (Contact me for what you need to do to make Newmat + compatible with Threaded Building Blocks). +
  • +
  • + See the function summary list for the older + depreciated function names. +
  • +
+

 

+

3.21 Singular value decomposition

+

+ next - skip - + up - start +

+

+ The singular value decomposition of an m x n Matrix + A (where m >= n) is a decomposition +

+
+    A  = U * D * V.t()
+
+ +

+ where U is m x n with U.t() * U equalling + the identity, D is an n x n DiagonalMatrix and V is an n x + n orthogonal matrix (type Matrix in Newmat). +

+

+ Singular value decompositions are useful for understanding the structure + of ill-conditioned matrices, solving least squares problems, and for + finding the eigenvalues of A.t() * A. +

+

+ To calculate the singular value decomposition of A (with + m >= n) use one of +

+
+    SVD(A, D, U, V);                  // U = A is OK
     SVD(A, D);
     SVD(A, D, U);                     // U = A is OK
     SVD(A, D, U, false);              // U (can = A) for workspace only
     SVD(A, D, U, V, false);           // U (can = A) for workspace only
-
- -

where A, U and V are of type Matrix and -D is a DiagonalMatrix. The values of A are not -changed unless A is also inserted as the third argument.

- -

The elements of D are sorted in descending order.

- -

To extend U to a square orthogonal matrix see the function for -extending an orthonormal set of columns.

-

Remember that the SVD decomposition is not completely unique. The signs of the elements in a column of U may be reversed -if the signs in the corresponding column in V are reversed. If a -number of the singular values are identical one can apply an orthogonal -transformation to the corresponding columns of U and the corresponding -columns of V.

-

If m < n apply the SVD transform to the transpose -of A and swap U and V. If necessary, extend U to a square matrix as described -above.

-

3.22 Eigenvalue -decomposition

-

next - skip - -up - start

-

An eigenvalue decomposition of a SymmetricMatrix A is a -decomposition

-
    A  = V * D * V.t()
-
- -

where V is an orthogonal matrix (type Matrix in -Newmat) and D is a DiagonalMatrix.

-

Eigenvalue analyses are used in a wide variety of engineering, statistical -and other mathematical analyses.

-

The package includes two algorithms: Jacobi and Householder. The first is -extremely reliable but much slower than the second.

-

The code is adapted from routines in Handbook for Automatic Computation, -Vol II, Linear Algebra by Wilkinson and Reinsch, published by Springer -Verlag.

-
    Jacobi(A,D,S,V);                  // A, S symmetric; S is workspace,
+
+ +

+ where A, U and V are of type + Matrix and D is a DiagonalMatrix. The values of + A are not changed unless A is also inserted as the third + argument. +

+ +

The elements of D are sorted in descending order.

+ +

+ To extend U to a square orthogonal matrix see the function for + extending an orthonormal set of columns. +

+

+ Remember that the SVD decomposition is not completely unique. The signs of + the elements in a column of U may be reversed if the signs in the + corresponding column in V are reversed. If a number of the + singular values are identical one can apply an orthogonal transformation + to the corresponding columns of U and the corresponding columns + of V. +

+

+ If m < n apply the SVD transform to the transpose of A + and swap U and V. If necessary, extend U to a square matrix as described + above. +

+

3.22 Eigenvalue decomposition

+

+ next - skip - + up - start +

+

+ An eigenvalue decomposition of a SymmetricMatrix A is a + decomposition +

+
+    A  = V * D * V.t()
+
+ +

+ where V is an orthogonal matrix (type Matrix in + Newmat) and D is a DiagonalMatrix. +

+

+ Eigenvalue analyses are used in a wide variety of engineering, statistical + and other mathematical analyses. +

+

+ The package includes two algorithms: Jacobi and Householder. The first is + extremely reliable but much slower than the second. +

+

+ The code is adapted from routines in + Handbook for Automatic Computation, Vol II, Linear Algebra by + Wilkinson and Reinsch, published by Springer Verlag. +

+
+    Jacobi(A,D,S,V);                  // A, S symmetric; S is workspace,
                                       //    S = A is OK; V is a matrix
     Jacobi(A,D);                      // A symmetric
     Jacobi(A,D,S);                    // A, S symmetric; S is workspace,
@@ -2422,197 +3287,268 @@ 

3.22 Eigenvalue eigenvalues(A,D,S); // A, S symmetric; S is for back // transforming, S = A is OK eigenvalues(A,D,V); // A symmetric; V is a matrix -

- -

where A, S are of type SymmetricMatrix, -D is of type DiagonalMatrix and V is of type -Matrix. The values of A are not changed unless A is -also inserted as the third argument. If you need eigenvectors use one of the -forms with matrix V. The eigenvectors are returned as the columns of -V.

- -

The elements of D are sorted in ascending order.

-

Remember that an eigenvalue decomposition is not completely -unique - see the comments about the SVD -decomposition.

-

See the function summary list for the older -depreciated function names.

-

3.23 Sorting

-

next - skip - -up - start

-

To sort the values in a matrix or vector, A, (in general this -operation makes sense only for vectors and diagonal matrices) use one of

-
    sort_ascending(A);
+
+ +

+ where A, S are of type SymmetricMatrix, + D is of type DiagonalMatrix and V is of type + Matrix. The values of A are not changed unless + A is also inserted as the third argument. If you need + eigenvectors use one of the forms with matrix V. The eigenvectors + are returned as the columns of V. +

+ +

The elements of D are sorted in ascending order.

+

+ Remember that an eigenvalue decomposition is not completely unique - see + the comments about the SVD decomposition. +

+

+ See the function summary list for the older + depreciated function names. +

+

3.23 Sorting

+

+ next - skip - + up - start +

+

+ To sort the values in a matrix or vector, A, (in general this + operation makes sense only for vectors and diagonal matrices) use one of +

+
+    sort_ascending(A);
 
     sort_descending(A);
-
- -

I use the quicksort algorithm. The algorithm is similar to that in -Sedgewick's algorithms in C++. If the sort seems to be failing (as quicksort -can do) an exception is thrown.

-

You will get incorrect results if you try to sort a band matrix - but why -would you want to sort a band matrix?

-

See the function summary list for the older -depreciated function names.

-

3.24 Fast Fourier transform -

-

next - skip - -up - start

-
   FFT(X, Y, F, G);                         // F=X and G=Y are OK
-
- -

where X, Y, F, G are ColumnVectors. -X and Y are the real and imaginary input vectors; F -and G are the real and imaginary output vectors. The lengths of -X and Y must be equal and should be the product of numbers -less than about 10 for fast execution.

-

The formula is

-
          n-1
+
+ +

+ I use the quicksort algorithm. The algorithm is similar to that in + Sedgewick's algorithms in C++. If the sort seems to be failing (as + quicksort can do) an exception is thrown. +

+

+ You will get incorrect results if you try to sort a band matrix - but why + would you want to sort a band matrix? +

+

+ See the function summary list for the older + depreciated function names. +

+

3.24 Fast Fourier transform

+

+ next - skip - + up - start +

+
+   FFT(X, Y, F, G);                         // F=X and G=Y are OK
+
+ +

+ where X, Y, F, G are ColumnVectors. + X and Y are the real and imaginary input vectors; + F and G are the real and imaginary output vectors. The + lengths of X and Y must be equal and should be the + product of numbers less than about 10 for fast execution. +

+

The formula is

+
+          n-1
    h[k] = SUM  z[j] exp (-2 pi i jk/n)
           j=0
-
- -

where z[j] is stored complex and stored in X(j+1) and -Y(j+1). Likewise h[k] is complex and stored in -F(k+1) and G(k+1). The fast Fourier algorithm takes order -n log(n) operations (for good values of n) rather than -n**2 that straight evaluation (see the file tmtf.cpp) takes. -

-

I use one of two methods:

-
    -
  • A program originally written by Sande and Gentleman. This requires that -n can be expressed as a product of small numbers.
  • -
  • A method of Carl de Boor (1980), Siam J Sci Stat Comput, pp 173-8. -The sines and cosines are calculated explicitly. This gives better accuracy, at -an expense of being a little slower than is otherwise possible. This is slower -than the Sande-Gentleman program but will work for all n --- although it -will be very slow for bad values of n.
  • -
-

Related functions

-
   FFTI(F, G, X, Y);                        // X=F and Y=G are OK
+
+ +

+ where z[j] is stored complex and stored in X(j+1) and + Y(j+1). Likewise h[k] is complex and stored in + F(k+1) and G(k+1). The fast Fourier algorithm takes + order n log(n) operations (for good values of + n) rather than n**2 that straight evaluation (see the file + tmtf.cpp) takes. +

+

I use one of two methods:

+
    +
  • + A program originally written by Sande and Gentleman. This requires that + n can be expressed as a product of small numbers. +
  • +
  • + A method of Carl de Boor (1980), Siam J Sci Stat Comput, pp + 173-8. The sines and cosines are calculated explicitly. This gives + better accuracy, at an expense of being a little slower than is + otherwise possible. This is slower than the Sande-Gentleman program but + will work for all n --- although it will be very slow for + bad values of n. +
  • +
+

Related functions

+
+   FFTI(F, G, X, Y);                        // X=F and Y=G are OK
    RealFFT(X, F, G);
    RealFFTI(F, G, X);
-
- -

FFTI is the inverse transform for FFT. RealFFT is -for the case when the input vector is real, that is Y = 0. I assume -the length of X, denoted by n, is even. That is, -n must be divisible by 2. The program sets the lengths of F and -G to n/2 + 1. RealFFTI is the inverse of -RealFFT.

-

See also the section on fast trigonometric -transforms.

-

There are also two dimensional versions

-
   FFT2(X, Y, F, G);                       // F=X and G=Y are OK
+
+ +

+ FFTI is the inverse transform for FFT. + RealFFT is for the case when the input vector is real, that is + Y = 0. I assume the length of X, denoted by n, is + even. That is, n must be divisible by 2. The program sets + the lengths of F and G to n/2 + 1. + RealFFTI is the inverse of RealFFT. +

+

+ See also the section on fast + trigonometric transforms. +

+

There are also two dimensional versions

+
+   FFT2(X, Y, F, G);                       // F=X and G=Y are OK
    FFT2I(F, G, X, Y);                      // inverse, X=F and Y=G are OK
-

where X, Y, F, G are of type Matrix. -X and Y are the real and imaginary input matrices; F -and G are the real and imaginary output matrices. The dimensions of Y -must be the same as those of X and should be the product of numbers -less than about 10 for fast execution.

-

The formula is

-
            m-1 n-1
+    

+ where X, Y, F, G are of type Matrix. + X and Y are the real and imaginary input matrices; + F and G are the real and imaginary output matrices. The + dimensions of Y must be the same as those of X and + should be the product of numbers less than about 10 for fast execution. +

+

The formula is

+
+            m-1 n-1
    h[p,q] = SUM SUM z[j,k] exp (-2 pi i (jp/m + kq/n))
             j=0 k=0
-
- -

where z[j,k] is stored complex and stored in X(j+1,k+1) and -Y(j+1,k+1) and X and Y have dimension m x n. Likewise h[p,q] is complex and stored in -F(p+1,q+1) and G(p+1,q+1). -

-

 

-

3.25 Fast trigonometric -transforms

-

next - skip - -up - start

-

These are the sin and cosine transforms as defined by Charles Van Loan -(1992) in Computational frameworks for the fast Fourier transform -published by SIAM. See page 229. Some other authors use slightly different -conventions. All the functions call the fast Fourier -transforms and require an even transform length, denoted by -m in these notes. That is, m must be divisible by 2. As with the -FFT m should be the product of numbers less than about 10 for fast -execution.

-

The functions I define are

-
   DCT(U,V);                // U, V are ColumnVectors, length m+1
+
+ +

+ where z[j,k] is stored complex and stored in + X(j+1,k+1) and Y(j+1,k+1) and X and + Y have dimension m x n. Likewise h[p,q] is + complex and stored in F(p+1,q+1) and G(p+1,q+1). +

+

 

+

3.25 Fast trigonometric transforms

+

+ next - skip - + up - start +

+

+ These are the sin and cosine transforms as defined by Charles Van Loan + (1992) in + Computational frameworks for the fast Fourier transform published + by SIAM. See page 229. Some other authors use slightly different + conventions. All the functions call the + fast Fourier transforms and require an + even transform length, denoted by m in these notes. That + is, m must be divisible by 2. As with the FFT m should be + the product of numbers less than about 10 for fast execution. +

+

The functions I define are

+
+   DCT(U,V);                // U, V are ColumnVectors, length m+1
    DCT_inverse(V,U);        // inverse of DCT
-   DST(U,V);                // U, V are ColumnVectors, length m+1
+   DST(U,V);                // U, V are ColumnVectors, length m+1
    DST_inverse(V,U);        // inverse of DST
-   DCT_II(U,V);             // U, V are ColumnVectors, length m
+   DCT_II(U,V);             // U, V are ColumnVectors, length m
    DCT_II_inverse(V,U);     // inverse of DCT_II
-   DST_II(U,V);             // U, V are ColumnVectors, length m
+   DST_II(U,V);             // U, V are ColumnVectors, length m
    DST_II_inverse(V,U);     // inverse of DST_II
-
- -

where the first argument is the input and the second argument is the output. -V = U is OK. The length of the output ColumnVector is set by the -functions.

-

Here are the formulae:

-

DCT

-
                   m-1                             k
+
+ +

+ where the first argument is the input and the second argument is the + output. V = U is OK. The length of the output ColumnVector is set + by the functions. +

+

Here are the formulae:

+

DCT

+
+                   m-1                             k
    v[k] = u[0]/2 + SUM { u[j] cos (pi jk/m) } + (-) u[m]/2
                    j=1
-
+
-

for k = 0...m, where u[j] and v[k] are stored in -U(j+1) and V(k+1).

-

DST

-
          m-1
+    

+ for k = 0...m, where u[j] and v[k] are stored + in U(j+1) and V(k+1). +

+

DST

+
+          m-1
    v[k] = SUM { u[j] sin (pi jk/m) }
           j=1
-
- -

for k = 1...(m-1), where u[j] and v[k] are stored -in U(j+1) and V(k+1)and where u[0] and u[m] -are ignored and v[0] and v[m] are set to zero. For the -inverse function v[0] and v[m] are ignored and u[0] -and u[m] are set to zero.

-

DCT_II

-
          m-1
+
+ +

+ for k = 1...(m-1), where u[j] and v[k] are + stored in U(j+1) and V(k+1)and where u[0] and + u[m] are ignored and v[0] and v[m] are set to + zero. For the inverse function v[0] and v[m] are ignored + and u[0] and u[m] are set to zero. +

+

DCT_II

+
+          m-1
    v[k] = SUM { u[j] cos (pi (j+1/2)k/m) }
           j=0
-
+
-

for k = 0...(m-1), where u[j] and v[k] are stored -in U(j+1) and V(k+1).

-

DST_II

-
           m
+    

+ for k = 0...(m-1), where u[j] and v[k] are + stored in U(j+1) and V(k+1). +

+

DST_II

+
+           m
    v[k] = SUM { u[j] sin (pi (j-1/2)k/m) }
           j=1
-
- -

for k = 1...m, where u[j] and v[k] are stored in -U(j) and V(k).

-

Note that the relationship between the subscripts in the formulae and those -used in newmat is different for DST_II (and DST_II_inverse).

-

3.26 Interface to Numerical -Recipes in C

-

next - skip - -up - start

-

This section refers to Numerical Recipes in C. This section is not -relevant to Numerical Recipes in C++. I'll put a note on the website soon -on how to interface with Numerical Recipes in C++.

-

This package can be used with the vectors and matrices defined in -Numerical Recipes in C. You need to edit the routines in Numerical -Recipes so that the elements are of the same type as used in this package. Eg -replace float by double, vector by dvector and matrix by dmatrix, etc. You may -need to edit the function definitions to use the version acceptable to your -compiler (if you are using the first edition of NRIC). You may need to enclose -the code from Numerical Recipes in extern "C" { ... }. You -will also need to include the matrix and vector utility routines.

-

Then any vector in Numerical Recipes with subscripts starting from 1 in a -function call can be accessed by a RowVector, ColumnVector or DiagonalMatrix in -the present package. Similarly any matrix with subscripts starting from 1 can -be accessed by an nricMatrix in the present package. The class nricMatrix is -derived from Matrix and can be used in place of Matrix. In each case, if you -wish to refer to a RowVector, ColumnVector, DiagonalMatrix or nricMatrix -X in an function from Numerical Recipes, use X.nric() in the -function call.

-

Numerical Recipes cannot change the dimensions of a matrix or vector. So -matrices or vectors must be correctly dimensioned before a Numerical Recipes -routine is called.

-

For example

-
   SymmetricMatrix B(44);
+
+ +

+ for k = 1...m, where u[j] and v[k] are stored + in U(j) and V(k). +

+

+ Note that the relationship between the subscripts in the formulae and + those used in newmat is different for DST_II (and DST_II_inverse). +

+

3.26 Interface to Numerical Recipes in C

+

+ next - skip - + up - start +

+

+ This section refers to Numerical Recipes in C. This section is + not relevant to Numerical Recipes in C++. I'll put a note on + the website soon on how to interface with Numerical Recipes in C++. +

+

+ This package can be used with the vectors and matrices defined in + Numerical Recipes in C. You need to edit the routines in Numerical + Recipes so that the elements are of the same type as used in this package. + Eg replace float by double, vector by dvector and matrix by dmatrix, etc. + You may need to edit the function definitions to use the version + acceptable to your compiler (if you are using the first edition of NRIC). + You may need to enclose the code from Numerical Recipes in + extern "C" { ... }. You will also need to include the + matrix and vector utility routines. +

+

+ Then any vector in Numerical Recipes with subscripts starting from 1 in a + function call can be accessed by a RowVector, ColumnVector or + DiagonalMatrix in the present package. Similarly any matrix with + subscripts starting from 1 can be accessed by an nricMatrix in the present + package. The class nricMatrix is derived from Matrix and can be used in + place of Matrix. In each case, if you wish to refer to a RowVector, + ColumnVector, DiagonalMatrix or nricMatrix X in an function from + Numerical Recipes, use X.nric() in the function call. +

+

+ Numerical Recipes cannot change the dimensions of a matrix or vector. So + matrices or vectors must be correctly dimensioned before a Numerical + Recipes routine is called. +

+

For example

+
+   SymmetricMatrix B(44);
    .....                             // load values into B
    nricMatrix BX = B;                // copy values to an nricMatrix
    DiagonalMatrix D(44);             // Matrices for output
@@ -2621,13 +3557,16 @@ 

3.26 Interface to Numerical jacobi(BX.nric(),44,D.nric(),V.nric(),&nrot); // jacobi from NRIC cout << D; // print eigenvalues -

+
-

3.27 Exceptions

-

next - skip - -up - start

-

Here is the class structure for exceptions:

-
Exception
+    

3.27 Exceptions

+

+ next - skip - + up - start +

+

Here is the class structure for exceptions:

+
+Exception
   Logic_error
     ProgramException                 miscellaneous matrix error
     IndexException                   index out of bounds
@@ -2645,469 +3584,673 @@ 

3.27 Exceptions

SolutionException no convergence in solution routine OverflowException floating point overflow Bad_alloc out of space (new fails) -
- -

I have attempted to mimic the exception class structure in the C++ standard -library, by defining the Logic_error and Runtime_error classes.

-

Suppose you have edited include.h to use my simulated -exceptions or to disable exceptions. If there is no catch statement or exceptions are disabled then my -Terminate() function in myexcept.h is called when you throw an -exception. This prints out -an error message, the dimensions and types of the matrices involved, the name -of the routine detecting the exception, and any other information set by the -Tracer class. Also see the section on error messages for additional notes on the messages generated -by the exceptions.

-

You can also print this information in a catch clause by printing Exception::what(). -

-

If you are using compiler supported exceptions then see the section -on catching exceptions.  -

-

See the file test_exc.cpp as an example of catching an exception -and printing the error message.

-

The 08 version of newmat defined a member function void -SetAction(int) to help customise the action when an exception is called. -This has been deleted in the 09 and later versions. Now include an instruction -such as cout << Exception::what() << endl; in the -Catch or CatchAll block to determine the action.

-

The library includes the alternatives of using the inbuilt exceptions -provided by a compiler, simulating exceptions, or disabling exceptions. See -customising for selecting the correct exception option. -

-

The rest of this section describes my partial simulation of exceptions for -compilers which do not support C++ exceptions. Skip the rest of this section and -the next section if you are using compiler supported exceptions. I use Carlos Vidal's article in -the September 1992 C Users Journal as a starting point.

-

Newmat does a partial clean up of memory following throwing an exception - -see the next section. However, the present version will leave a little heap -memory unrecovered under some circumstances. I would not expect this to be a -major problem, but it is something that needs to be sorted out.

-

The functions/macros I define are Try, Throw, Catch, CatchAll and -CatchAndThrow. Try, Throw, Catch and CatchAll correspond to try, throw, catch -and catch(...) in the C++ standard. A list of Catch clauses must be terminated -by either CatchAll or CatchAndThrow but not both. Throw takes an Exception as -an argument or takes no argument (for passing on an exception). I do not have a -version of Throw for specifying which exceptions a function might throw. Catch -takes an exception class name as an argument; CatchAll and CatchAndThrow don't -have any arguments. Try, Catch and CatchAll must be followed by blocks enclosed -in curly brackets.

-

I have added another macro ReThrow to mean a rethrow, Throw(). This was -necessary to enable the package to be compatible with both my exception package -and C++ exceptions.

-

If you want to throw an exception, use a statement like

-
   Throw(Exception("Error message\n"));
-
- -

It is important to have the exception declaration in the Throw statement, -rather than as a separate statement.

-

All exception classes must be derived from the class, Exception, defined in -newmat and can contain only static variables. See the examples in newmat if you -want to define additional exceptions.

-

Note that the simulation exception mechanism does not work if you define -arrays of matrices.

-

3.28 Cleanup after an -exception

-

next - skip - -up - start

-

This section is about the simulated exceptions used in newmat. It is -irrelevant if you are using the exceptions built into a compiler or have set -the disable-exceptions option.

-

The simulated exception mechanisms in newmat are based on the C functions -setjmp and longjmp. These functions do not call destructors so can lead to -garbage being left on the heap. (I refer to memory allocated by new as -heap memory). For example, when you call

-
   Matrix A(20,30);
-
- -

a small amount of space is used on the stack containing the row and column -dimensions of the matrix and 600 doubles are allocated on the heap for the -actual values of the matrix. At the end of the block in which A is declared, -the destructor for A is called and the 600 doubles are freed. The locations on -the stack are freed as part of the normal operations of the stack. If you leave -the block using a longjmp command those 600 doubles will not be freed and will -occupy space until the program terminates.

-

To overcome this problem newmat keeps a list of all the currently declared -matrices and its exception mechanism will return heap memory when you do a -Throw and Catch.

-

However it will not return heap memory from objects from other packages. -

-

If you want the mechanism to work with another class you will have to do -four things:

-
    -
  1. derive your class from class Janitor defined in except.h;
  2. -
  3. define a function void CleanUp() in that class to return all heap -memory;
  4. -
  5. include the following lines in the class definition
          public:
    +
    + +

    + I have attempted to mimic the exception class structure in the C++ + standard library, by defining the Logic_error and Runtime_error classes. +

    +

    + Suppose you have edited include.h to use my + simulated exceptions or to disable exceptions. If there is + no catch statement or exceptions are disabled then my + Terminate() function in myexcept.h is called when you + throw an exception. This prints out an error message, the dimensions and + types of the matrices involved, the name of the routine detecting the + exception, and any other information set by the + Tracer class. Also see the section on + error messages for additional notes on the messages + generated by the exceptions. +

    +

    + You can also print this information in a catch clause by printing + Exception::what(). +

    +

    + If you are using compiler supported exceptions then see the + section on catching exceptions.  +

    +

    + See the file test_exc.cpp as an example of catching an exception + and printing the error message. +

    +

    + The 08 version of newmat defined a member function + void SetAction(int) to help customise the action when an + exception is called. This has been deleted in the 09 and later versions. + Now include an instruction such as + cout << Exception::what() << endl; in the + Catch or CatchAll block to determine the action. +

    +

    + The library includes the alternatives of using the inbuilt exceptions + provided by a compiler, simulating exceptions, or disabling exceptions. + See customising for selecting the correct exception + option. +

    +

    + The rest of this section describes my partial simulation of exceptions for + compilers which do not support C++ exceptions. Skip the rest of this + section and the next section if you are using compiler supported + exceptions. I use Carlos Vidal's article in the September 1992 + C Users Journal as a starting point. +

    +

    + Newmat does a partial clean up of memory following throwing an exception - + see the next section. However, the present version will leave a little + heap memory unrecovered under some circumstances. I would not expect this + to be a major problem, but it is something that needs to be sorted out. +

    +

    + The functions/macros I define are Try, Throw, Catch, CatchAll and + CatchAndThrow. Try, Throw, Catch and CatchAll correspond to try, throw, + catch and catch(...) in the C++ standard. A list of Catch clauses must be + terminated by either CatchAll or CatchAndThrow but not both. Throw takes + an Exception as an argument or takes no argument (for passing on an + exception). I do not have a version of Throw for specifying which + exceptions a function might throw. Catch takes an exception class name as + an argument; CatchAll and CatchAndThrow don't have any arguments. Try, + Catch and CatchAll must be followed by blocks enclosed in curly brackets. +

    +

    + I have added another macro ReThrow to mean a rethrow, Throw(). This was + necessary to enable the package to be compatible with both my exception + package and C++ exceptions. +

    +

    If you want to throw an exception, use a statement like

    +
    +   Throw(Exception("Error message\n"));
    +
    + +

    + It is important to have the exception declaration in the Throw statement, + rather than as a separate statement. +

    +

    + All exception classes must be derived from the class, Exception, defined + in newmat and can contain only static variables. See the examples in + newmat if you want to define additional exceptions. +

    +

    + Note that the simulation exception mechanism does not work if you define + arrays of matrices. +

    +

    3.28 Cleanup after an exception

    +

    + next - skip - + up - start +

    +

    + This section is about the simulated exceptions used in newmat. It + is irrelevant if you are using the exceptions built into a compiler + or have set the disable-exceptions option. +

    +

    + The simulated exception mechanisms in newmat are based on the C functions + setjmp and longjmp. These functions do not call destructors so can lead to + garbage being left on the heap. (I refer to memory allocated by + new as heap memory). For example, when you call +

    +
    +   Matrix A(20,30);
    +
    + +

    + a small amount of space is used on the stack containing the row and column + dimensions of the matrix and 600 doubles are allocated on the heap for the + actual values of the matrix. At the end of the block in which A is + declared, the destructor for A is called and the 600 doubles are freed. + The locations on the stack are freed as part of the normal operations of + the stack. If you leave the block using a longjmp command those 600 + doubles will not be freed and will occupy space until the program + terminates. +

    +

    + To overcome this problem newmat keeps a list of all the currently declared + matrices and its exception mechanism will return heap memory when you do a + Throw and Catch. +

    +

    + However it will not return heap memory from objects from other packages. +

    +

    + If you want the mechanism to work with another class you will have to do + four things: +

    +
      +
    1. derive your class from class Janitor defined in except.h;
    2. +
    3. + define a function void CleanUp() in that class to return all + heap memory; +
    4. +
    5. + include the following lines in the class definition +
      +      public:
                void* operator new(size_t size)
                { do_not_link=true; void* t = ::operator new(size); return t; }
                void operator delete(void* t) { ::operator delete(t); }
      -
      - -
    6. -
    7. be sure to include a copy constructor in you class definition, that is, -something like
            X(const X&);
      -
      - -
    8. -
    -

    Use CleanUp() rather than cleanup() since this is what is -defined in class Janitor.

    -

    Note that the function CleanUp() does somewhat the same duties as -the destructor. However CleanUp() has to do the cleaning for -the class you are working with and also the classes it is derived from. So it -will often be wrong to use exactly the same code for both CleanUp() -and the destructor or to define your destructor as a call to -CleanUp().

    -

    3.29 Non-linear -applications

    -

    next - skip - -up - start

    -

    Files solution.h, solution.cpp contain a class for solving for x in -y = f(x) where x is a one-dimensional continuous -monotonic function. This is not a matrix thing at all but is included because -it is a useful program and because it is a simpler version of the coding technique used -in the non-linear least squares.

    -

    Files newmatnl.h, newmatnl.cpp contain a series of classes for non-linear -least squares and maximum likelihood. These classes work on very well-behaved -functions but need upgrading for less well-behaved functions. I haven't followed -the usual practice of inflating the values of the diagonal elements of the -matrix of second derivatives. I originally thought I could avoid this if my -program had a good line search. But this was wrong and when I use this program -on all but the most well-behaved problems I run the fit first with the diagonal -elements inflated by a factor of 2 to 5 and the critical value for the stopping -criterion set to something like 50. Then rerun with with no inflation factor and -critical value 0.0001.

    -

    Documentation for both of these is in the definition files. Simple examples -are in sl_ex.cpp, nl_ex.cpp and garch.cpp.

    -

    3.30 Standard template -library

    -

    next - skip - -up - start

    -

    The standard template library (STL) is the set of container templates -(vector, deque, list etc) defined by the C++ standards committee. Newmat is -intended to be compatible with the STL in the sense that you can store matrices -in the standard containers. I have defined == and -inequality operators which seem to be required by some versions of the STL.

    -

    If you want to use the container classes with Newmat please note

    -
      -
    • Don't use simulated exceptions.
    • -
    • Make sure the option DO_FREE_CHECK is not -turned on.
    • -
    • You can store only one type of matrix in a container. If you want to use a -variety of types use the GenericMatrix type or store pointers to the matrices. -
    • -
    • The vector and deque container templates like to copy their elements. For -the vector container this happens when you insert an element anywhere except at -the end or when you append an element and the current vector storage overflows. -Since Newmat does not have copy-on-write this could get very inefficient.
    • -
    • You won't be able to sort the container or do anything that would call an -inequality operator.
    • -
    -

    3.31 Namespace

    -

    next - skip - -up - start

    -

    Namespace is used to avoid name -clashes between different libraries. I have included the namespace capability. -Activate the line #define use_namespace in include.h. Then -include either the statement

    -
       using namespace NEWMAT;
    -
    - -

    at the beginning of any file that needs to access the newmat library or

    -
       using namespace RBD_LIBRARIES;
    -
    - -

    at the beginning of any file that needs to access all my libraries.

    -

    This works correctly with Borland C++ version 5 and -Builder 5 and 6.

    -

    Microsoft Visual C++ version 5 works in my example -and test files, but fails with apparently insignificant changes (it may be more -reliable if you have applied service pack 3). If you #include -"newmatap.h", but no other newmat include file, then also #include -"newmatio.h". It seems to work with Microsoft -Visual C++ version 6 if you have applied at least service pack 2.

    -

    My use of namespace does not work with Gnu g++ version -2.8.1 but does work with versions 3.x.

    -

    I have defined the following namespaces:

    -
      -
    • RBD_COMMON for functions and classes used by most of my libraries
    • -
    • NEWMAT for the newmat library
    • -
    • RBD_LIBRARIES for all my libraries
    • -
    -

    3.32 Updating the Cholesky matrix

    - - -

    next - skip - -up - start

    - - -

    Suppose X is matrix and U has been formed with either

    - - -
       SymmetricMatrix A; A << X.t() * X;
    -   UpperTriangularMatrix U = Cholesky(A).t();
    -

    or

    -
       UpperTriangularMatrix U;
    -   QRZ(X, U);
    -

    See sections 3.19 and 3.20.

    -

    Now suppose we want to append an extra row to X or delete a row from X -or rearrange the columns of X. The functions described here allow you to -update U without  recalculating it.

    +
+ +
  • + be sure to include a copy constructor in you class definition, that is, + something like +
    +      X(const X&);
    +
    +
  • + +

    + Use CleanUp() rather than cleanup() since this is what + is defined in class Janitor. +

    +

    + Note that the function CleanUp() does somewhat the same duties as + the destructor. However CleanUp() has to do the + cleaning for the class you are working with and also the classes it + is derived from. So it will often be wrong to use exactly the same code + for both CleanUp() + and the destructor or to define your destructor as a call to + CleanUp(). +

    +

    3.29 Non-linear applications

    +

    + next - skip - + up - start +

    +

    + Files solution.h, solution.cpp contain a class for solving for x in + y = f(x) where x is a one-dimensional + continuous monotonic function. This is not a matrix thing at all but is + included because it is a useful program and because it is a simpler + version of the coding technique used in the non-linear least squares. +

    +

    + Files newmatnl.h, newmatnl.cpp contain a series of classes for non-linear + least squares and maximum likelihood. These classes work on very + well-behaved functions but need upgrading for less well-behaved functions. + I haven't followed the usual practice of inflating the values of the + diagonal elements of the matrix of second derivatives. I originally + thought I could avoid this if my program had a good line search. But this + was wrong and when I use this program on all but the most well-behaved + problems I run the fit first with the diagonal elements inflated by a + factor of 2 to 5 and the critical value for the stopping criterion set to + something like 50. Then rerun with with no inflation factor and critical + value 0.0001. +

    +

    + Documentation for both of these is in the definition files. Simple + examples are in sl_ex.cpp, nl_ex.cpp and garch.cpp. +

    +

    3.30 Standard template library

    +

    + next - skip - + up - start +

    +

    + The standard template library (STL) is the set of + container templates (vector, deque, list etc) defined by the C++ + standards committee. Newmat is intended to be compatible with the STL in + the sense that you can store matrices in the standard containers. I have + defined == and inequality operators which + seem to be required by some versions of the STL. +

    +

    If you want to use the container classes with Newmat please note

    +
      +
    • Don't use simulated exceptions.
    • +
    • + Make sure the option DO_FREE_CHECK is + not turned on. +
    • +
    • + You can store only one type of matrix in a container. If you want to use + a variety of types use the GenericMatrix type or store pointers to the + matrices. +
    • +
    • + The vector and deque container templates like to copy their elements. + For the vector container this happens when you insert an element + anywhere except at the end or when you append an element and the current + vector storage overflows. Since Newmat does not have + copy-on-write this could get very inefficient. +
    • +
    • + You won't be able to sort the container or do anything that would call + an inequality operator. +
    • +
    +

    3.31 Namespace

    +

    + next - skip - + up - start +

    +

    + Namespace is used to avoid name clashes between different + libraries. I have included the namespace capability. Activate the line + #define use_namespace in include.h. Then include either + the statement +

    +
    +   using namespace NEWMAT;
    +
    +

    + at the beginning of any file that needs to access the newmat library or +

    +
    +   using namespace RBD_LIBRARIES;
    +
    -
       update_Cholesky(U, x);                    // x is a RowVector
    +    

    at the beginning of any file that needs to access all my libraries.

    +

    + This works correctly with Borland C++ version 5 and + Builder 5 and 6. +

    +

    + Microsoft Visual C++ version 5 works in my example + and test files, but fails with apparently insignificant changes (it may be + more reliable if you have applied service pack 3). If you #include + "newmatap.h", but no other newmat include file, then also + #include "newmatio.h". It seems to work with + Microsoft Visual C++ version 6 if you have + applied at least service pack 2. +

    +

    + My use of namespace does not work with Gnu g++ version + 2.8.1 but does work with versions 3.x. +

    +

    I have defined the following namespaces:

    +
      +
    • RBD_COMMON for functions and classes used by most of my libraries
    • +
    • NEWMAT for the newmat library
    • +
    • RBD_LIBRARIES for all my libraries
    • +
    +

    3.32 Updating the Cholesky matrix

    + +

    + next - skip - + up - start +

    + +

    + Suppose X is matrix and U has been formed with either +

    + +
    +   SymmetricMatrix A; A << X.t() * X;
    +   UpperTriangularMatrix U = Cholesky(A).t();
    +

    or

    +
    +   UpperTriangularMatrix U;
    +   QRZ(X, U);
    +

    See sections 3.19 and 3.20.

    +

    + Now suppose we want to append an extra row to X or delete a row + from X or rearrange the columns of X. The functions + described here allow you to update + U without  recalculating it. +

    + +
    +   update_Cholesky(U, x);                    // x is a RowVector
        downdate_Cholesky(U, x);                  // x is a RowVector
        right_circular_update_Cholesky(U, j, k);  // j and k are integers
        left_circular_update_Cholesky(U, j, k);   // j and k are integers
    -

    update_Cholesky carries out the modification of U corresponding to appending -an extra row x to X.

    - - -

    downdate_Cholesky carries out the modification corresponding -to removing a row x from X. A ProgramException exception is -thrown if the modification fails.

    - - -

    right_circular_update_Cholesky supposes that columns j,j+1,...k of X are -replaced by columns k,j,j+1,...k-1.

    - - -

    left_circular_update_Cholesky supposes that columns j,j+1,...k of X are replaced -by columns j+1,...k,j.

    - - -

    These functions are based on a contribution from Nick Bennett of -Schlumberger-Doll Research. See also the LINPACK User's Guide, Chapter 10, -Dongarra et. al., SIAM, Philadelphia, 1979.

    - - -

    Where you want to append a number of new rows consider using the update -routine in section 3.20.

    - - -

    See the function summary list for the older -depreciated function names.

    - - -

    3.33 Accessing C functions

    - - -

    next - skip - -up - start

    - - -

    You have a C function that uses one and two dimensional arrays as -vectors and matrices. You want to access it from Newmat.

    - - -

    One dimensional arrays are easy. Set up a ColumnVector, RowVector -or DiagonalMatrix with the correct dimension and where the function has a -double* argument enter X.data() where X denotes the -ColumnVector, RowVector or DiagonalMatrix. (I am assuming you -have left Real being typedefed as a double). If you have a -const double* argument use X.const_data().

    - - -

    You can't do this with two dimensional arrays where you have a double** -argument. Newmat includes classes RealStarStar and ConstRealStarStar for this situation. -To access a Matrix A from a function c_function(double** a) -use either

    - - -
       c_function(RealStarStar(A));
    -

    or

    -
       RealStarStar a(A);
    +    

    + update_Cholesky carries out the modification of + U corresponding to appending an extra row x to + X. +

    + +

    + downdate_Cholesky carries out the modification corresponding to + removing a row x from X. A + ProgramException exception is thrown if the modification fails. +

    + +

    + right_circular_update_Cholesky supposes that columns + j,j+1,...k of X are replaced by columns + k,j,j+1,...k-1. +

    + +

    + left_circular_update_Cholesky supposes that columns + j,j+1,...k of X are replaced by columns + j+1,...k,j. +

    + +

    + These functions are based on a contribution from Nick Bennett of + Schlumberger-Doll Research. See also the LINPACK User's Guide, Chapter 10, + Dongarra et. al., SIAM, Philadelphia, 1979. +

    + +

    + Where you want to append a number of new rows consider using the update + routine in section 3.20. +

    + +

    + See the function summary list for the older + depreciated function names. +

    + +

    3.33 Accessing C functions

    + +

    + next - skip - + up - start +

    + +

    + You have a C function that uses one and two dimensional arrays as + vectors and matrices. You want to access it from Newmat. +

    + +

    + One dimensional arrays are easy. Set up a ColumnVector, + RowVector or DiagonalMatrix with the correct dimension and + where the function has a double* argument enter + X.data() where X denotes the ColumnVector, + RowVector or DiagonalMatrix. (I am assuming you have left + Real being typedefed as a double). If you have a + const double* argument use X.const_data(). +

    + +

    + You can't do this with two dimensional arrays where you have a + double** argument. Newmat includes classes + RealStarStar and ConstRealStarStar for this situation. To + access a Matrix A from a function + c_function(double** a) use either +

    + +
       c_function(RealStarStar(A));
    +

    or

    +
    +   RealStarStar a(A);
        c_function(a);
    -

    If the argument is const double** use ConstRealStarStar.

    - - -

    The Matrix A must be correctly dimensioned and must not be -resized or set equal to another matrix between setting up the RealStarStar -object and its use in the function. Also the following construction will not -work

    - - -
       double** a = RealStarStar(A);      // wrong
    +    

    + If the argument is const double** use ConstRealStarStar. +

    + +

    + The Matrix A must be correctly dimensioned and must not be + resized or set equal to another matrix between setting up the + RealStarStar object and its use in the function. Also the following + construction will not work +

    + +
    +   double** a = RealStarStar(A);      // wrong
        c_function(a);
    -

    since the RealStarStar structure will have been destroyed before you -get to the second line.

    - - -

    3.34 Simple integer array class

    - - -

    next - skip - -up - start

    - - -

    This is primarily for use within Newmat. You can set up a simple array -of integers with the SimpleIntArray class. Here are the descriptions of -the constructors and functions.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    SimpleIntArray A; Constructs int array of length zero
    SimpleIntArray A(n); Constructs int array of length n - -individual elements are not initialised
    A = i; sets values to i where i is an int -variable
    A = B; sets values to those of B where -B is -a SimpleIntArray, change size if necessary.
    n = A.size(); return the length of A
    A.resize(n); change the length of A, don't keep -values
    A.resize_keep(n); change the length of A, do keep -values; if length is being increased set new elements to zero.
    int x = A[i]; element access; i runs from 0 to -n-1
    int* d = A.data(); get beginning of data array
    const int* d = A.data(); get beginning of data array as const -int* if A is const
    const int* d = A.const_data(); get beginning of data array as const -int*
    A.cleanup() resize to zero length
    - - 

    3.35 - -Extend orthonormal set of columns

    -

    next - skip - -up - start

    -

    Suppose a Matrix A's first n columns are orthonormal so that -A.Columns(1,n).t() * A.Columns(1,n) is the identity matrix. Suppose -we want to fill out the remaining columns of A to make them orthonormal so -that A.t() * A is the identity matrix. Then use the function

    -
       extend_orthonormal(A, n);
    -

    Matrix A is then replaced by the matrix with the additional -columns.

    -

    Use this function to extend U from the QRZ or -SVD decompositions to form a square (orthogonal) matrix.

    -

    Notes:

    -
      -
    • the first n columns of A must be orthonormal
    • -
    • n must be less or equal to the number of columns of A
    • -
    • the number of columns of A must be less than or equal to the number of - rows of A
    • -
    - -

    3.36 Miscellaneous functions

    -

    next - skip - -up - start

    -

    The section includes some miscellaneous functions I have needed for my work. So -far there are only the Helmert transforms.

    -

    Helmert transforms

    -

    This section refers to the Helmert transform used in some statistical -packages for extracting contrasts. It is different from the Helmert transform -used in geodesy. The version of the transform I am going to use is based on the -n x n matrix

    -
    | 1/sqrt(1*2)                       | * | -1  1              |
    +    

    + since the RealStarStar structure will have been destroyed before + you get to the second line. +

    + +

    3.34 Simple integer array class

    + +

    + next - skip - + up - start +

    + +

    + This is primarily for use within Newmat. You can set up a simple + array of integers with the SimpleIntArray class. Here are the + descriptions of the constructors and functions. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + SimpleIntArray A; + + Constructs int array of length zero +
    + SimpleIntArray A(n); + + Constructs int array of length n - individual elements are + not initialised +
    A = i; + sets values to i where i is an int variable +
    A = B; + sets values to those of B where B is a SimpleIntArray, + change size if necessary. +
    n = A.size(); + return the length of A +
    A.resize(n); + change the length of A, don't keep values +
    + A.resize_keep(n); + + change the length of A, do keep values; if length is being + increased set new elements to zero. +
    int x = A[i]; + element access; i runs from 0 to n-1 +
    + int* d = A.data(); + + get beginning of data array +
    + const int* d = A.data(); + + get beginning of data array as const int* if A is const +
    + const int* d = A.const_data(); + + get beginning of data array as const int* +
    A.cleanup()resize to zero length
    + +   +

    3.35 Extend orthonormal set of columns

    +

    + next - skip - + up - start +

    +

    + Suppose a Matrix A's first n columns are + orthonormal so that A.Columns(1,n).t() * A.Columns(1,n) is the + identity matrix. Suppose we want to fill out the remaining columns of + A to make them orthonormal so that A.t() * A is the + identity matrix. Then use the function +

    +
       extend_orthonormal(A, n);
    +

    + Matrix A is then replaced by the matrix with the + additional columns. +

    +

    + Use this function to extend U from the QRZ or + SVD decompositions to form a square (orthogonal) + matrix. +

    +

    Notes:

    +
      +
    • the first n columns of A must be orthonormal
    • +
    • + n must be less or equal to the number of columns of A +
    • +
    • + the number of columns of A must be less than or equal to the + number of rows of A +
    • +
    + +

    3.36 Miscellaneous functions

    +

    + next - skip - + up - start +

    +

    + The section includes some miscellaneous functions I have needed for my + work. So far there are only the Helmert transforms. +

    +

    Helmert transforms

    +

    + This section refers to the Helmert transform used in some statistical + packages for extracting contrasts. It is different from the Helmert + transform used in geodesy. The version of the transform I am going to use + is based on the n x n matrix +

    +
    +| 1/sqrt(1*2)                       | * | -1  1              |
     |     1/sqrt(2*3)                   |   | -1 -1  2           |
     |          1/sqrt(3*4)              |   | -1 -1 -1  3        |
     |               ...                 |   |  ...               |
     |                  1/(sqrt(n-1)*n)  |   | -1 -1  ...  -1 n-1 |
     |                         1/sqrt(n) |   |  1  1  ...       1 | 
    -

    You can interpret multiplying a column vector by this matrix as follows. Form -the k-th element in the resulting column vector by taking the k+1-th -element and subtracting the average of the previous k elements. Then -multiply by sqrt((k+1)/k) so we get an orthonormal transform. The -last element is just the sum divided by sqrt(n). Usually one will omit -the last element since we want just the contrasts.

    -

    Here are the functions. X and Y are ColumnVectors, A -and B are matrices, b is a boolean, j, n are -integers, x is a Real.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    A = Helmert(n, b);
    -A = Helmert(n);
    Return the n x n -Helmert matrix or the (n-1) x n version with the last row omitted.
    Y = Helmert(X,b);
    -Y = Helmert(X);
    Multiply by the Helmert matrix.
    Y = Helmert(n,j,b);
    -Y = Helmert(n,j);
    Return j-th column of Helmert -matrix as a ColumnVector.
    X = Helmert_transpose(Y,b);
    -X = Helmert_transpose(Y);
    Multiply by the transpose of the -Helmert matrix.
    x = Helmert_transpose(Y,j,b);
    -x = Helmert_transpose(Y,j);
    Multiply by the transpose of the -Helmert matrix, return just the j-th element.
    B = Helmert(A,b);
    -B = Helmert(A);
    Multiply a Matrix by the Helmert -matrix.
    A = Helmert_transpose(B,b);
    -A = Helmert_transpose(B);
    Multiply a Matrix by the transpose of -the Helmert matrix.
    - -

    If b is true the full Helmert matrix is used, if it is false or -omitted the n-th row (or n-column of the transpose) is omitted.

    -

     

    - -

    4. Error messages

    -

    next - skip - -up - start

    -

    Most error messages are self-explanatory. The message gives the size of the -matrices involved. Matrix types are referred to by the following codes:

    -
       Matrix or vector                   Rect
    +    

    + You can interpret multiplying a column vector by this matrix as follows. + Form the k-th element in the resulting column vector by taking the + k+1-th element and subtracting the average of the previous + k elements. Then multiply by sqrt((k+1)/k) so we get + an orthonormal transform. The last element is just the sum divided by + sqrt(n). Usually one will omit the last element since we want just + the contrasts. +

    +

    + Here are the functions. X and Y are ColumnVectors, + A and B are matrices, b is a boolean, + j, n are integers, x is a Real. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + A = Helmert(n, b);
    + A = Helmert(n); +
    + Return the n x n Helmert matrix or the (n-1) x + n version with the last row omitted. +
    + Y = Helmert(X,b);
    + Y = Helmert(X); +
    + Multiply by the Helmert matrix. +
    + Y = Helmert(n,j,b);
    + Y = Helmert(n,j); +
    + Return j-th column of Helmert matrix as a ColumnVector. +
    + X = Helmert_transpose(Y,b);
    + X = Helmert_transpose(Y); +
    + Multiply by the transpose of the Helmert matrix. +
    + x = Helmert_transpose(Y,j,b);
    + x = Helmert_transpose(Y,j); +
    + Multiply by the transpose of the Helmert matrix, return just the + j-th element. +
    + B = Helmert(A,b);
    + B = Helmert(A); +
    + Multiply a Matrix by the Helmert matrix. +
    + A = Helmert_transpose(B,b);
    + A = Helmert_transpose(B); +
    + Multiply a Matrix by the transpose of the Helmert matrix. +
    + +

    + If b is true the full Helmert matrix is used, if it is false or + omitted the n-th row (or n-column of the transpose) is + omitted. +

    +

     

    + +

    4. Error messages

    +

    + next - skip - + up - start +

    +

    + Most error messages are self-explanatory. The message gives the size of + the matrices involved. Matrix types are referred to by the following + codes: +

    +
    +   Matrix or vector                   Rect
        Symmetric matrix                   Sym
        Band matrix                        Band
        Symmetric band matrix              SmBnd
    @@ -3118,540 +4261,727 @@ 

    4. Error messages

    Diagonal matrix Diag Crout matrix (LU matrix) Crout Band LU matrix BndLU -
    - -

    Other codes should not occur.

    -

    See the section on exceptions for more details on the -structure of the exception classes.

    -

    I have defined a class Tracer that is intended to help locate the place -where an error has occurred. At the beginning of a function I suggest you -include a statement like

    -
       Tracer tr("name");
    -
    - -

    where name is the name of the function. This name will be printed as part of -the error message, if an exception occurs in that function, or in a function -called from that function. You can change the name as you proceed through a -function with the ReName function

    -
       tr.ReName("new name");
    -
    - -

    if, for example, you want to track progress through the function.

    -

    5. Notes on the design of the -library

    -

    next - skip - -up - start

    - - - - - -
    5.1 -Safety, usability, efficiency
    -5.2 Matrix vs array library
    -5.3 Design questions
    -5.4 Data storage
    -5.5 Memory management - 1
    -5.6 Memory management - 2
    -5.7 Evaluation of expressions
    5.8 Explosion in the number of operations
    -5.9 Destruction of temporaries
    -5.10 A calculus of matrix types
    -5.11 Pointer arithmetic
    -5.12 Error handling
    -5.13 Sparse matrices
    -5.14 Complex matrices
    -

    I describe some of the ideas behind this package, some of the decisions that -I needed to make and give some details about the way it works. You don't need -to read this part of the documentation in order to use the package.

    -

    It isn't obvious what is the best way of going about structuring a matrix -package. I don't think you can figure this out with thought experiments. -Different people have to try out different approaches. And someone else may -have to figure out which is best. Or, more likely, the ultimate packages will -lift some ideas from each of a variety of trial packages. So, I don't claim my -package is an ultimate package, but simply a trial of a number of ideas. -The following pages give some background on these ideas.

    -

    5.1 Safety, usability, -efficiency

    -

    next - skip - -up - start

    -

    Some general comments

    -

    A library like newmat needs to balance safety, -usability and efficiency.

    -

    By safety, I mean getting the right answer, and not causing crashes -or damage to the computer system.

    -

    By usability, I mean being easy to learn and use, including not being -too complicated, being intuitive, saving the users' time, being nice to use. -

    -

    Efficiency means minimising the use of computer memory and time.

    -

    In the early days of computers the emphasis was on efficiency. But computer -power gets cheaper and cheaper, halving in price every 18 months. On the other -hand the unaided human brain is probably not a lot better than it was 100,000 -years ago! So we should expect the balance to shift to put more emphasis on -safety and usability and a little less on efficiency. So I don't mind if my -programs are a little less efficient than programs written in pure C (or -Fortran) if I gain substantially in safety and usability. But I would mind if -they were a lot less efficient.

    -

    Type of use

    -

    Second reason for putting extra emphasis on safety and usability is the way -I and, I suspect, most other users actually use newmat. Most completed -programs are used only a few times. Some result is required for a client, paper -or thesis. The program is developed and tested, the result is obtained, and the -program archived. Of course bits of the program will be recycled for the next -project. But it may be less usual for the same program to be run over and over -again. So the cost, computer time + people time, is in the development time and -often, much less in the actual time to run the final program. So good use of -people time, especially during development is really important. This means you -need highly usable libraries.

    -

    So if you are dealing with matrices, you want the good interface that I have -tried to provide in newmat, and, of course, reliable methods underneath -it.

    -

    Of course, efficiency is still important. We often want to run the biggest -problem our computer will handle and often a little bigger. The C++ language -almost lets us have both worlds. We can define a reasonably good interface, and -get good efficiency in the use of the computer.

    -

    Levels of access

    -

    We can imagine the black box model of a newmat. Suppose the -inside is hidden but can be accessed by the methods described in the -reference section. Then the interface is reasonably -consistent and intuitive. Matrices can be accessed and manipulated in much the -same way as doubles or ints in regular C. All accesses are checked. It is most -unlikely that an incorrect index will crash the system. In general, users do -not need to use pointers, so one shouldn't get pointers pointing into space. -And, hopefully, you will get simpler code with less errors.

    -

    There are some exceptions to this. In particular, the C-like subscripts are not checked for validity. They give -faster access but with a lower level of safety.

    -

    Then there is the data() function which takes you to -the data array within a matrix. This takes you right inside the black -box. But this is what you have to use if you are writing, for example, a -new matrix factorisation, and require fast access to the data array. I have -tried to write code to simplify access to the interior of a rectangular matrix, -see file newmatrm.cpp, but I don't regard this as very successful, as yet, and -have not included it in the documentation. Ideally we should have improved -versions of this code for each of the major types of matrix. But, in reality, -most of my matrix factorisations are written in what is basically the C -language with very little C++.

    -

    So our box is not very black. You have a choice of how far you -penetrate. On the outside you have a good level of safety, but in some cases -efficiency is compromised a little. If you penetrate inside the box -safety is reduced but you can get better efficiency.

    -

    Some performance data

    -

    This section looks at the performance on newmat for simple sums, -comparing it with C code and with a simple array program. -(This is now very old data).

    -

    The following table lists the time (in seconds) for carrying out the -operations X=A+B;, X=A+B+C;, X=A+B+C+D;, X=A+B+C+D+E; where -X,A,B,C,D,E are of type ColumnVector, with a variety of programs. I am -using Microsoft VC++, version 6 in console mode under windows 2000 on a PC with -a 1 ghz Pentium III and 512 mbytes of memory.

    -
        length    iters. newmat      C C-res.  subs.  array
    +
    + +

    Other codes should not occur.

    +

    + See the section on exceptions for more details on + the structure of the exception classes. +

    +

    + I have defined a class Tracer that is intended to help locate the place + where an error has occurred. At the beginning of a function I suggest you + include a statement like +

    +
    +   Tracer tr("name");
    +
    + +

    + where name is the name of the function. This name will be printed as part + of the error message, if an exception occurs in that function, or in a + function called from that function. You can change the name as you proceed + through a function with the ReName function +

    +
    +   tr.ReName("new name");
    +
    + +

    if, for example, you want to track progress through the function.

    +

    5. Notes on the design of the library

    +

    + next - skip - + up - start +

    + + + + + +
    + 5.1 Safety, usability, efficiency
    + 5.2 Matrix vs array library
    + 5.3 Design questions
    + 5.4 Data storage
    + 5.5 Memory management - 1
    + 5.6 Memory management - 2
    + 5.7 Evaluation of expressions +
    + 5.8 Explosion in the number of operations
    + 5.9 Destruction of temporaries
    + 5.10 A calculus of matrix types
    + 5.11 Pointer arithmetic
    + 5.12 Error handling
    + 5.13 Sparse matrices
    + 5.14 Complex matrices +
    +

    + I describe some of the ideas behind this package, some of the decisions + that I needed to make and give some details about the way it works. You + don't need to read this part of the documentation in order to use the + package. +

    +

    + It isn't obvious what is the best way of going about structuring a matrix + package. I don't think you can figure this out with + thought experiments. Different people have to try out different + approaches. And someone else may have to figure out which is best. Or, + more likely, the ultimate packages will lift some ideas from each of a + variety of trial packages. So, I don't claim my package is an + ultimate package, but simply a trial of a number of ideas. The + following pages give some background on these ideas. +

    +

    5.1 Safety, usability, efficiency

    +

    + next - skip - + up - start +

    +

    Some general comments

    +

    + A library like newmat needs to balance safety, + usability and efficiency. +

    +

    + By safety, I mean getting the right answer, and not causing crashes + or damage to the computer system. +

    +

    + By usability, I mean being easy to learn and use, including not + being too complicated, being intuitive, saving the users' time, being nice + to use. +

    +

    + Efficiency means minimising the use of computer memory and time. +

    +

    + In the early days of computers the emphasis was on efficiency. But + computer power gets cheaper and cheaper, halving in price every 18 months. + On the other hand the unaided human brain is probably not a lot better + than it was 100,000 years ago! So we should expect the balance to shift to + put more emphasis on safety and usability and a little less on efficiency. + So I don't mind if my programs are a little less efficient than programs + written in pure C (or Fortran) if I gain substantially in safety and + usability. But I would mind if they were a lot less efficient. +

    +

    Type of use

    +

    + Second reason for putting extra emphasis on safety and usability is the + way I and, I suspect, most other users actually use newmat. Most + completed programs are used only a few times. Some result is required for + a client, paper or thesis. The program is developed and tested, the result + is obtained, and the program archived. Of course bits of the program will + be recycled for the next project. But it may be less usual for the same + program to be run over and over again. So the cost, computer time + people + time, is in the development time and often, much less in the actual time + to run the final program. So good use of people time, especially during + development is really important. This means you need highly usable + libraries. +

    +

    + So if you are dealing with matrices, you want the good interface that I + have tried to provide in newmat, and, of course, reliable methods + underneath it. +

    +

    + Of course, efficiency is still important. We often want to run the biggest + problem our computer will handle and often a little bigger. The C++ + language almost lets us have both worlds. We can define a reasonably good + interface, and get good efficiency in the use of the computer. +

    +

    Levels of access

    +

    + We can imagine the black box model of a newmat. Suppose the + inside is hidden but can be accessed by the methods described in the + reference section. Then the interface is reasonably + consistent and intuitive. Matrices can be accessed and manipulated in much + the same way as doubles or ints in regular C. All accesses are checked. It + is most unlikely that an incorrect index will crash the system. In + general, users do not need to use pointers, so one shouldn't get pointers + pointing into space. And, hopefully, you will get simpler code with less + errors. +

    +

    + There are some exceptions to this. In particular, the + C-like subscripts are not checked for validity. + They give faster access but with a lower level of safety. +

    +

    + Then there is the data() function which takes you + to the data array within a matrix. This takes you right inside the + black box. But this is what you have to use if you are writing, for + example, a new matrix factorisation, and require fast access to the data + array. I have tried to write code to simplify access to the interior of a + rectangular matrix, see file newmatrm.cpp, but I don't regard this as very + successful, as yet, and have not included it in the documentation. Ideally + we should have improved versions of this code for each of the major types + of matrix. But, in reality, most of my matrix factorisations are written + in what is basically the C language with very little C++. +

    +

    + So our box is not very black. You have a choice of how far + you penetrate. On the outside you have a good level of safety, but in some + cases efficiency is compromised a little. If you penetrate inside the + box safety is reduced but you can get better efficiency. +

    +

    Some performance data

    +

    + This section looks at the performance on newmat for simple sums, + comparing it with C code and with a simple array program. (This is now + very old data). +

    +

    + The following table lists the time (in seconds) for carrying out the + operations X=A+B;, X=A+B+C;, X=A+B+C+D;, + X=A+B+C+D+E; where X,A,B,C,D,E are of type ColumnVector, + with a variety of programs. I am using Microsoft VC++, version 6 in + console mode under windows 2000 on a PC with a 1 ghz Pentium III and 512 + mbytes of memory. +

    +
        length    iters. newmat      C C-res.  subs.  array
     X = A + B
    -         2   5000000   27.8    0.3    8.8    1.9    9.5 
    -        20    500000    3.0    0.3    1.1    1.9    1.2 
    -       200     50000    0.5    0.3    0.4    1.9    0.3 
    -      2000      5000    0.4    0.3    0.4    2.0    1.0 
    -     20000       500    4.5    4.5    4.5    6.7    4.4 
    -    200000        50    5.2    4.7    5.5    5.8    5.2 
    +         2   5000000   27.8    0.3    8.8    1.9    9.5
    +        20    500000    3.0    0.3    1.1    1.9    1.2
    +       200     50000    0.5    0.3    0.4    1.9    0.3
    +      2000      5000    0.4    0.3    0.4    2.0    1.0
    +     20000       500    4.5    4.5    4.5    6.7    4.4
    +    200000        50    5.2    4.7    5.5    5.8    5.2
     
     X = A + B + C
    -         2   5000000   36.6    0.4    8.9    2.5   12.2 
    -        20    500000    4.0    0.4    1.2    2.5    1.6 
    -       200     50000    0.8    0.3    0.5    2.5    0.5 
    -      2000      5000    3.6    4.4    4.6    9.0    4.4 
    -     20000       500    6.8    5.4    5.4    9.6    6.8 
    -    200000        50    8.6    6.0    6.7    7.1    8.6 
    +         2   5000000   36.6    0.4    8.9    2.5   12.2
    +        20    500000    4.0    0.4    1.2    2.5    1.6
    +       200     50000    0.8    0.3    0.5    2.5    0.5
    +      2000      5000    3.6    4.4    4.6    9.0    4.4
    +     20000       500    6.8    5.4    5.4    9.6    6.8
    +    200000        50    8.6    6.0    6.7    7.1    8.6
     
     X = A + B + C + D
    -         2   5000000   44.0    0.7    9.3    3.1   14.6 
    -        20    500000    4.9    0.6    1.5    3.1    1.9 
    -       200     50000    1.0    0.6    0.8    3.2    0.8 
    -      2000      5000    5.6    6.6    6.8   11.5    5.9 
    -     20000       500    9.0    6.7    6.8   11.0    8.5 
    -    200000        50   11.9    7.1    7.9    9.5   12.0 
    +         2   5000000   44.0    0.7    9.3    3.1   14.6
    +        20    500000    4.9    0.6    1.5    3.1    1.9
    +       200     50000    1.0    0.6    0.8    3.2    0.8
    +      2000      5000    5.6    6.6    6.8   11.5    5.9
    +     20000       500    9.0    6.7    6.8   11.0    8.5
    +    200000        50   11.9    7.1    7.9    9.5   12.0
     
     X = A + B + C + D + E
    -         2   5000000   50.6    1.0    9.5    3.8   17.1 
    -        20    500000    5.7    0.8    1.7    3.9    2.4 
    -       200     50000    1.3    0.9    1.0    3.9    1.0 
    -      2000      5000    7.0    8.3    8.2   13.8    7.1 
    -     20000       500   11.5    8.1    8.4   13.2   11.0 
    -    200000        50   15.2    8.7    9.5   12.4   15.4 
    +         2   5000000   50.6    1.0    9.5    3.8   17.1
    +        20    500000    5.7    0.8    1.7    3.9    2.4
    +       200     50000    1.3    0.9    1.0    3.9    1.0
    +      2000      5000    7.0    8.3    8.2   13.8    7.1
    +     20000       500   11.5    8.1    8.4   13.2   11.0
    +    200000        50   15.2    8.7    9.5   12.4   15.4
     
    -

    I have graphed the results -and included rather more array lengths.

    - -

    The first column gives the lengths of the arrays, the second the number of -iterations and the remaining columns the total time required in seconds. If the -only thing that consumed time was the double precision addition then the -numbers within each block of the table would be the same. The summation is -repeated 5 times within each loop, for example:

    -
       for (i=1; i<=m; ++i)
    +    

    + I have graphed the results and + included rather more array lengths. +

    + +

    + The first column gives the lengths of the arrays, the second the number of + iterations and the remaining columns the total time required in seconds. + If the only thing that consumed time was the double precision addition + then the numbers within each block of the table would be the same. The + summation is repeated 5 times within each loop, for example: +

    +
    +   for (i=1; i<=m; ++i)
        {
           X1 = A1+B1+C1; X2 = A2+B2+C2; X3 = A3+B3+C3;
           X4 = A4+B4+C4; X5 = A5+B5+C5;
        }
    -

    The column labelled newmat is using the standard newmat add. The column labelled C uses the usual C method: while -(j1--) *x1++ = *a1++ + *b1++; . The following column also includes an -X.resize() in the outer loop to correspond to the reassignment of -memory that newmat would do. In the next column the calculation is using -the usual C style for loop -and accessing the elements using newmat subscripts such as -A(i). The final column is the time taken by a -simple array package. This uses an alternative method for avoiding temporaries -and unnecessary copies that does not involve runtime tests. It does its sums in blocks of 4 and copies in blocks of -8 in the same way that newmat does.

    -

    Here are my conclusions.

    -
      -
    • Newmat does very badly for length 2 and doesn't do well for -length 20. There is a lot of code in newmat for -determining which sum algorithm to use and it is not surprising that this -impacts on performance for small lengths. -However the array program is also having difficulty with length 2 so it -is unlikely that the problem could be completely eliminated.
    • -
    • For arrays of length 2000 or longer newmat is doing about as well as -C and slightly better than C with resize in the X=A+B table. For the -other two tables it tends to be slower, but not dramatically so.
    • -
    • It is really important for fast processing with the Pentium III to stay -within the Pentium cache.
    • -
    • Addition using the newmat subscripts, while considerably slower than -the others, is still surprisingly good for the longer arrays.
    • -
    • The array program and newmat are similar for -lengths 2000 or higher (the longer times for the array program for the longest -arrays shown on the graph are probably a quirk of the timing program).
    • -
    -

    In summary: for the situation considered here, newmat is doing very -well for large ColumnVectors, even for sums with several terms, but not so well -for shorter ColumnVectors.

    -

    5.2 Matrix vs array -library

    -

    next - skip - -up - start

    -

    The newmat library is for the manipulation of matrices, including the -standard operations such as multiplication as understood by numerical analysts, -engineers and mathematicians.

    -

    A matrix is a two dimensional array of numbers. However, very special -operations such as matrix multiplication are defined specifically for matrices. -This means that a matrix library, as I understand the term, is different -from a general array library. Here are some contrasting properties.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    FeatureMatrix -libraryArray -library
    ExpressionsMatrix expressions; -* means matrix multiply; inverse functionArithmetic operations, if -supported, mean elementwise combination of arrays
    Element accessAccess to the elements of a -matrixHigh speed access to elements -directly and perhaps with iterators
    Elementary functionsFor example: determinant, -traceMatrix multiplication as a -function
    Advanced functionsFor example: eigenvalue -analysis 
    Element typesReal and possibly -complexWide range - real, integer, string -etc
    TypesRectangular, symmetric, diagonal, -etcOne, two and three dimensional -arrays, at least
    -

    Both types of library need to support access to sub-matrices or sub-arrays, -have good efficiency and storage management, and graceful exit for errors. In -both cases, we probably need two versions, one optimised for large matrices or -arrays and one for small matrices or arrays.

    -

    It may be possible to amalgamate the two sets of requirements to some -extent. However newmat is definitely oriented towards the matrix library -set.

    -

    5.3 Design questions

    -

    next - skip - -up - start

    -

    Even within the bounds set by the requirements of a matrix library there is -a substantial opportunity for variation between what different matrix packages -might provide. It is not possible to build a matrix package that will meet -everyone's requirements. In many cases if you put in one facility, you impose -overheads on everyone using the package. This both in storage required for the -program and in efficiency. Likewise a package that is optimised towards -handling large matrices is likely to become less efficient for very small -matrices where the administration time for the matrix may become significant -compared with the time to carry out the operations. It is better to provide a -variety of packages (hopefully compatible) so that most users can find one that -meets their requirements. This package is intended to be one of these packages; -but not all of them.

    -

    Since my background is in statistical methods, this package is oriented -towards the kinds things you need for statistical analyses.

    -

    Now looking at some specific questions.

    -

    What size of matrices?

    -

    A matrix library may target small matrices (say 3 x 3), or medium sized -matrices, or very large matrices.

    -

    A library targeting very small matrices will seek to minimise -administration. A library for medium sized or very large matrices can spend -more time on administration in order to conserve space or optimise the -evaluation of expressions. A library for very large matrices will need to pay -special attention to storage and numerical properties. This library is designed -for medium sized matrices. This means it is worth introducing some -optimisations, but I don't have to worry about setting up some form of virtual -memory.

    -

    Which matrix types?

    -

    As well as the usual rectangular matrices, matrices occurring repeatedly in -numerical calculations are upper and lower triangular matrices, symmetric -matrices and diagonal matrices. This is particularly the case in calculations -involving least squares and eigenvalue calculations. So as a first stage these -were the types I decided to include.

    -

    It is also necessary to have types row vector and column vector. In a -matrix package, in contrast to an array package, it is necessary -to have both these types since they behave differently in matrix expressions. -The vector types can be derived for the rectangular matrix type, so having them -does not greatly increase the complexity of the package.

    -

    The problem with having several matrix types is the number of versions of -the binary operators one needs. If one has 5 distinct matrix types then a -simple library will need 25 versions of each of the binary operators. In fact, -we can evade this problem, but at the cost of some complexity.

    -

    What element types?

    -

    Ideally we would allow element types double, float, complex and int, at -least. It might be reasonably easy, using templates or equivalent, to provide a -library which could handle a variety of element types. However, as soon as one -starts implementing the binary operators between matrices with different -element types, again one gets an explosion in the number of operations one -needs to consider. At the present time the compilers I deal with are not up to -handling this problem with templates. (Of course, when I started writing -newmat there were no templates). But even when the compilers do meet the -specifications of the draft standard, writing a matrix package that allows for -a variety of element types using the template mechanism is going to be very -difficult. I am inclined to use templates in an array library but not in -a matrix library.

    -

    Hence I decided to implement only one element type. But the user can decide -whether this is float or double. The package assumes elements are of type Real. -The user typedefs Real to float or double.

    -

    It might also be worth including symmetric and triangular matrices with -extra precision elements (double or long double) to be used for storage only -and with a minimum of operations defined. These would be used for accumulating -the results of sums of squares and product matrices or multi-stage QR -decompositions.

    -

    Allow matrix expressions

    -

    I want to be able to write matrix expressions the way I would on paper. So -if I want to multiply two matrices and then add the transpose of a third one I -can write something like X = A * B + C.t();. I want this expression to -be evaluated with close to the same efficiency as a hand-coded version. This is -not so much of a problem with expressions including a multiply since the -multiply will dominate the time. However, it is not so easy to achieve with -expressions with just + and -.

    -

    A second requirement is that temporary matrices generated during the -evaluation of an expression are destroyed as quickly as possible.

    -

    A desirable feature is that a certain amount of intelligence be -displayed in the evaluation of an expression. For example, in the expression -X = A.i() * B; where i() denotes inverse, it would be -desirable if the inverse wasn't explicitly calculated.

    -

    Naming convention

    -

    How are classes and public member functions to be named? As a general rule I -have spelt identifiers out in full with individual words being capitalised. For -example UpperTriangularMatrix. If you don't like this you can #define or -typedef shorter names. This convention means you can select an abbreviation -scheme that makes sense to you.

    -

    Exceptions to the general rule are the functions for transpose and inverse. -To make matrix expressions more like the corresponding mathematical formulae, I -have used the single letter abbreviations, t() and i().

    -

    I am now switching to using lowercase for functions with individual -words separated by "_". This is following the convention in -the standard library and I think it looks neater. Class names will remain with -individual words being capitalised.

    -

    Row and column index ranges

    -

    In mathematical work matrix subscripts usually start at one. In C, array -subscripts start at zero. In Fortran, they start at one. Possibilities for this -package were to make them start at 0 or 1 or be arbitrary.

    -

    Alternatively one could specify an index set for indexing the rows -and columns of a matrix. One would be able to add or multiply matrices only if -the appropriate row and column index sets were identical.

    -

    In fact, I adopted the simpler convention of making the rows and columns of -a matrix be indexed by an integer starting at one, following the traditional -convention. In an earlier version of the package I had them starting at zero, -but even I was getting mixed up when trying to use this earlier package. So I -reverted to the more usual notation and started at 1.

    -

    Element access - method and checking

    -

    We want to be able to use the notation A(i,j) to specify the -(i,j)-th element of a matrix. This is the way mathematicians expect to -address the elements of matrices. I consider the notation A[i][j] -totally alien. However I include this as an option to help people converting -from C.

    -

    There are two ways of working out the address of A(i,j). One is -using a dope vector which contains the first address of each row. -Alternatively you can calculate the address using the formula appropriate for -the structure of A. I use this second approach. It is probably slower, -but saves worrying about an extra bit of storage.

    -

    The other question is whether to check for i and j being -in range. I do carry out this check following years of experience with both -systems that do and systems that don't do this check. I would hope that the -routines I supply with this package will reduce your need to access elements of -matrices so speed of access is not a high priority.

    -

    Use iterators

    -

    Iterators are an alternative way of providing fast access to the elements of -an array or matrix when they are to be accessed sequentially. They need to be -customised for each type of matrix. I have not implemented iterators in this -package, although some iterator like functions are used internally for some row -and column functions.

    -

    5.4 Data storage

    -

    next - skip - -up - start

    -

    The stack and heap

    -

    To understand how newmat stores matrices you need to know a little bit -about the heap and stack.

    -

    The data values of variables or objects in a C++ program are stored in either -of two sections of memory called the stack and the heap. Sometimes -there is more than one heap to cater for different sized variables.

    -

    If you declare an automatic variable

    -
       int x;
    -

    then the value of x is stored on the stack. As you declare more -variables the stack gets bigger. When you exit a block (i.e a section of code -delimited by curly brackets {...}) the memory used by the automatic -variables declared in the block is released and the stack shrinks.

    -

    When you declare a variable with new, for example,

    -
       int* y = new int;
    -

    the pointer y is stored on the stack but the value it is -pointing to is stored on the heap. Memory on the heap is not -released until the program explicitly does this with a delete statement

    -
       delete y;
    -

    or the program exits.

    -

    On the stack, variables and objects are is always added to the end of -the stack and are removed in the reverse order to that in which they are -added - that is the last on will be the first off. This is not the case with the -heap, where the variables and objects can be removed in any order. So one -can get alternating pieces of used and unused memory. When a new variable or -object is declared on the heap the system needs to search for piece of -unused memory large enough to hold it. This means that storing on the heap -will usually be a slower process than storing on the stack. There is also -likely to be waste space on the heap because of gaps between the used -blocks of memory that are too small for the next object you want to store on the -heap. There is also the possibility of wasting space if you forget to -remove a variable or object on the heap even though you have finished -using it. However, the stack is usually limited to holding small objects -with size known at compile time. Large objects, objects whose size you don't -know at compile time, and objects that you want to persist after the end of the -block need to be stored on the heap.

    -

    In C++, the constructor/destructor system enables one to build -complicated objects such as matrices that behave as automatic variables stored -on the stack, so the programmer doesn't have to worry about deleting them -at the end of the block, but which really utilise the heap for storing -their data.

    -

    Structure of matrix objects

    -

    Each matrix object contains the basic information such as the number of rows -and columns, the amount of memory used, a status variable and a pointer to the data array which is on -the heap. So if you declare a matrix

    -
       Matrix A(1000,1000);
    -

    there is an small amount of memory used on the stack for storing the numbers -of rows and columns, the amount of  memory used, the status variable and -the pointer together with 1,000,000 Real locations stored on the heap. -When you exit the block in which A is declared, the heap memory used by -A is automatically returned to the system, as well as the memory used on -the stack.

    -

    Of course, if you use new to declare a matrix

    -
       Matrix* B = new Matrix(1000,1000);
    -

    both the information about the size and the actual data are stored on heap -and not deleted until the program exits or you do an explicit delete:

    -
       delete B;
    -

    If you carry out an assignment with = or << or do a -resize() the data array currently associated with a matrix is destroyed and -a new array generated. For example

    -
       Matrix A(1000,1000);
    +    

    + The column labelled newmat is using the standard newmat add. + The column labelled C uses the usual C method: + while (j1--) *x1++ = *a1++ + *b1++; . The following column also + includes an X.resize() in the outer loop to correspond to the + reassignment of memory that newmat would do. In the next column the + calculation is using the usual C style for loop and accessing the + elements using newmat subscripts such as A(i). The final + column is the time taken by a simple array package. This uses an + alternative method for avoiding temporaries and unnecessary copies that + does not involve runtime tests. It does its sums in blocks of 4 and copies + in blocks of 8 in the same way that newmat does. +

    +

    Here are my conclusions.

    +
      +
    • + Newmat does very badly for length 2 and doesn't do well for + length 20. There is a lot of code in newmat for determining which + sum algorithm to use and it is not surprising that this impacts on + performance for small lengths. However the array program is also + having difficulty with length 2 so it is unlikely that the problem could + be completely eliminated. +
    • +
    • + For arrays of length 2000 or longer newmat is doing about as well + as C and slightly better than C with resize in the X=A+B table. + For the other two tables it tends to be slower, but not dramatically so. +
    • +
    • + It is really important for fast processing with the Pentium III to stay + within the Pentium cache. +
    • +
    • + Addition using the newmat subscripts, while considerably slower + than the others, is still surprisingly good for the longer arrays. +
    • +
    • + The array program and newmat are similar for lengths 2000 + or higher (the longer times for the array program for the longest arrays + shown on the graph are probably a quirk of the timing program). +
    • +
    +

    + In summary: for the situation considered here, newmat is doing very + well for large ColumnVectors, even for sums with several terms, but not so + well for shorter ColumnVectors. +

    +

    5.2 Matrix vs array library

    +

    + next - skip - + up - start +

    +

    + The newmat library is for the manipulation of matrices, including + the standard operations such as multiplication as understood by numerical + analysts, engineers and mathematicians. +

    +

    + A matrix is a two dimensional array of numbers. However, very special + operations such as matrix multiplication are defined specifically for + matrices. This means that a matrix library, as I understand the + term, is different from a general array library. Here are some + contrasting properties. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    FeatureMatrix libraryArray library
    Expressions + Matrix expressions; * means matrix multiply; inverse + function + + Arithmetic operations, if supported, mean elementwise combination of + arrays +
    Element accessAccess to the elements of a matrix + High speed access to elements directly and perhaps with iterators +
    Elementary functionsFor example: determinant, traceMatrix multiplication as a function
    Advanced functionsFor example: eigenvalue analysis 
    Element typesReal and possibly complexWide range - real, integer, string etc
    TypesRectangular, symmetric, diagonal, etc + One, two and three dimensional arrays, at least +
    +

    + Both types of library need to support access to sub-matrices or + sub-arrays, have good efficiency and storage management, and graceful exit + for errors. In both cases, we probably need two versions, one optimised + for large matrices or arrays and one for small matrices or arrays. +

    +

    + It may be possible to amalgamate the two sets of requirements to some + extent. However newmat is definitely oriented towards the matrix + library set. +

    +

    5.3 Design questions

    +

    + next - skip - + up - start +

    +

    + Even within the bounds set by the requirements of a matrix library there + is a substantial opportunity for variation between what different matrix + packages might provide. It is not possible to build a matrix package that + will meet everyone's requirements. In many cases if you put in one + facility, you impose overheads on everyone using the package. This both in + storage required for the program and in efficiency. Likewise a package + that is optimised towards handling large matrices is likely to become less + efficient for very small matrices where the administration time for the + matrix may become significant compared with the time to carry out the + operations. It is better to provide a variety of packages (hopefully + compatible) so that most users can find one that meets their requirements. + This package is intended to be one of these packages; but not all of them. +

    +

    + Since my background is in statistical methods, this package is oriented + towards the kinds things you need for statistical analyses. +

    +

    Now looking at some specific questions.

    +

    What size of matrices?

    +

    + A matrix library may target small matrices (say 3 x 3), or medium sized + matrices, or very large matrices. +

    +

    + A library targeting very small matrices will seek to minimise + administration. A library for medium sized or very large matrices can + spend more time on administration in order to conserve space or optimise + the evaluation of expressions. A library for very large matrices will need + to pay special attention to storage and numerical properties. This library + is designed for medium sized matrices. This means it is worth introducing + some optimisations, but I don't have to worry about setting up some form + of virtual memory. +

    +

    Which matrix types?

    +

    + As well as the usual rectangular matrices, matrices occurring repeatedly + in numerical calculations are upper and lower triangular matrices, + symmetric matrices and diagonal matrices. This is particularly the case in + calculations involving least squares and eigenvalue calculations. So as a + first stage these were the types I decided to include. +

    +

    + It is also necessary to have types row vector and column vector. In a + matrix package, in contrast to an array package, it is + necessary to have both these types since they behave differently in matrix + expressions. The vector types can be derived for the rectangular matrix + type, so having them does not greatly increase the complexity of the + package. +

    +

    + The problem with having several matrix types is the number of versions of + the binary operators one needs. If one has 5 distinct matrix types then a + simple library will need 25 versions of each of the binary operators. In + fact, we can evade this problem, but at the cost of some complexity. +

    +

    What element types?

    +

    + Ideally we would allow element types double, float, complex and int, at + least. It might be reasonably easy, using templates or equivalent, to + provide a library which could handle a variety of element types. However, + as soon as one starts implementing the binary operators between matrices + with different element types, again one gets an explosion in the number of + operations one needs to consider. At the present time the compilers I deal + with are not up to handling this problem with templates. (Of course, when + I started writing newmat there were no templates). But even when + the compilers do meet the specifications of the draft standard, writing a + matrix package that allows for a variety of element types using the + template mechanism is going to be very difficult. I am inclined to use + templates in an array library but not in a matrix library. +

    +

    + Hence I decided to implement only one element type. But the user can + decide whether this is float or double. The package assumes elements are + of type Real. The user typedefs Real to float or double. +

    +

    + It might also be worth including symmetric and triangular matrices with + extra precision elements (double or long double) to be used for storage + only and with a minimum of operations defined. These would be used for + accumulating the results of sums of squares and product matrices or + multi-stage QR decompositions. +

    +

    Allow matrix expressions

    +

    + I want to be able to write matrix expressions the way I would on paper. So + if I want to multiply two matrices and then add the transpose of a third + one I can write something like X = A * B + C.t();. I want this + expression to be evaluated with close to the same efficiency as a + hand-coded version. This is not so much of a problem with expressions + including a multiply since the multiply will dominate the time. However, + it is not so easy to achieve with expressions with just + and + -. +

    +

    + A second requirement is that temporary matrices generated during the + evaluation of an expression are destroyed as quickly as possible. +

    +

    + A desirable feature is that a certain amount of intelligence be + displayed in the evaluation of an expression. For example, in the + expression X = A.i() * B; where i() denotes inverse, it + would be desirable if the inverse wasn't explicitly calculated. +

    +

    Naming convention

    +

    + How are classes and public member functions to be named? As a general rule + I have spelt identifiers out in full with individual words being + capitalised. For example UpperTriangularMatrix. If you don't like + this you can #define or typedef shorter names. This convention means you + can select an abbreviation scheme that makes sense to you. +

    +

    + Exceptions to the general rule are the functions for transpose and + inverse. To make matrix expressions more like the corresponding + mathematical formulae, I have used the single letter abbreviations, + t() and i(). +

    +

    + I am now switching to using lowercase for functions with individual words + separated by "_". This is following the convention in + the standard library and I think it looks neater. Class names will remain + with individual words being capitalised. +

    +

    Row and column index ranges

    +

    + In mathematical work matrix subscripts usually start at one. In C, array + subscripts start at zero. In Fortran, they start at one. Possibilities for + this package were to make them start at 0 or 1 or be arbitrary. +

    +

    + Alternatively one could specify an index set for indexing the rows + and columns of a matrix. One would be able to add or multiply matrices + only if the appropriate row and column index sets were identical. +

    +

    + In fact, I adopted the simpler convention of making the rows and columns + of a matrix be indexed by an integer starting at one, following the + traditional convention. In an earlier version of the package I had them + starting at zero, but even I was getting mixed up when trying to use this + earlier package. So I reverted to the more usual notation and started at + 1. +

    +

    Element access - method and checking

    +

    + We want to be able to use the notation A(i,j) to specify the + (i,j)-th element of a matrix. This is the way mathematicians + expect to address the elements of matrices. I consider the notation + A[i][j] totally alien. However I include this as an option to + help people converting from C. +

    +

    + There are two ways of working out the address of A(i,j). One is + using a dope vector which contains the first address of each row. + Alternatively you can calculate the address using the formula appropriate + for the structure of A. I use this second approach. It is + probably slower, but saves worrying about an extra bit of storage. +

    +

    + The other question is whether to check for i and j being + in range. I do carry out this check following years of experience with + both systems that do and systems that don't do this check. I would hope + that the routines I supply with this package will reduce your need to + access elements of matrices so speed of access is not a high priority. +

    +

    Use iterators

    +

    + Iterators are an alternative way of providing fast access to the elements + of an array or matrix when they are to be accessed sequentially. They need + to be customised for each type of matrix. I have not implemented iterators + in this package, although some iterator like functions are used internally + for some row and column functions. +

    +

    5.4 Data storage

    +

    + next - skip - + up - start +

    +

    The stack and heap

    +

    + To understand how newmat stores matrices you need to know a little + bit about the heap and stack. +

    +

    + The data values of variables or objects in a C++ program are stored in + either of two sections of memory called the stack and the + heap. Sometimes there is more than one heap to cater for + different sized variables. +

    +

    If you declare an automatic variable

    +
       int x;
    +

    + then the value of x is stored on the stack. As you declare + more variables the stack gets bigger. When you exit a block (i.e a section + of code delimited by curly brackets {...}) the memory used by the + automatic variables declared in the block is released and the + stack shrinks. +

    +

    When you declare a variable with new, for example,

    +
       int* y = new int;
    +

    + the pointer y is stored on the stack but the value it is + pointing to is stored on the heap. Memory on the heap is not + released until the program explicitly does this with a + delete statement +

    +
       delete y;
    +

    or the program exits.

    +

    + On the stack, variables and objects are is always added to the end + of the stack and are removed in the reverse order to that in which + they are added - that is the last on will be the first off. This is not + the case with the heap, where the variables and objects can be + removed in any order. So one can get alternating pieces of used and unused + memory. When a new variable or object is declared on the heap the + system needs to search for piece of unused memory large enough to hold it. + This means that storing on the heap will usually be a slower + process than storing on the stack. There is also likely to be waste + space on the heap because of gaps between the used blocks of memory + that are too small for the next object you want to store on the + heap. There is also the possibility of wasting space if you forget + to remove a variable or object on the heap even though you have + finished using it. However, the stack is usually limited to holding + small objects with size known at compile time. Large objects, objects + whose size you don't know at compile time, and objects that you want to + persist after the end of the block need to be stored on the heap. +

    +

    + In C++, the constructor/destructor system enables one to + build complicated objects such as matrices that behave as automatic + variables stored on the stack, so the programmer doesn't have to + worry about deleting them at the end of the block, but which really + utilise the heap for storing their data. +

    +

    Structure of matrix objects

    +

    + Each matrix object contains the basic information such as the number of + rows and columns, the amount of memory used, a status variable and a + pointer to the data array which is on the heap. So if you declare a matrix +

    +
       Matrix A(1000,1000);
    +

    + there is an small amount of memory used on the stack for storing the + numbers of rows and columns, the amount of  memory used, the status + variable and the pointer together with 1,000,000 Real locations + stored on the heap. When you exit the block in which A is declared, + the heap memory used by A is automatically returned to the system, + as well as the memory used on the stack. +

    +

    Of course, if you use new to declare a matrix

    +
       Matrix* B = new Matrix(1000,1000);
    +

    + both the information about the size and the actual data are stored on heap + and not deleted until the program exits or you do an explicit delete: +

    +
       delete B;
    +

    + If you carry out an assignment with = or << or do + a resize() the data array currently associated with a matrix is + destroyed and a new array generated. For example +

    +
    +   Matrix A(1000,1000);
        Matrix B(50, 50);
        ... put some values in B
        A = B;
    -

    At the last step the heap memory associated with A is returned to the -system and a new block of heap memory is assigned to contain the new values. -This happens even if there is no change in the amount of memory required.

    -

    One block or several

    -

    The elements of the matrix are stored as a single array. Alternatives would -have been to store each row as a separate array or a set of adjacent rows as a -separate array. The present solution simplifies the program but limits the size -of matrices in 16 bit PCs that have a 64k byte limit on the size of arrays (I -don't use the huge keyword). The large arrays may also cause problems -for memory management in smaller machines. [The 16 bit PC problem has largely -gone away but it was a problem when much of newmat was written. Now, -occasionally I run into the 32 bit PC problem.]

    -

    By row or by column or other

    -

    In Fortran two dimensional arrays are stored by column. In most other -systems they are stored by row. I have followed this later convention. This -makes it easier to interface with other packages written in C but harder to -interface with those written in Fortran. This may have been a wrong decision. -Most work on the efficient manipulation of large matrices is being done in -Fortran. It would have been easier to use this work if I had adopted the -Fortran convention.

    -

    An alternative would be to store the elements by mid-sized rectangular -blocks. This might impose less strain on memory management when one needs to -access both rows and columns.

    -

    Storage of symmetric matrices

    -

    Symmetric matrices are stored as lower triangular matrices. The decision was -pretty arbitrary, but it does slightly simplify the Cholesky decomposition -program.

    -

    5.5 Memory management - -reference counting or status variable?

    -

    next - skip - -up - start

    -

    Consider the instruction

    -
       X = A + B + C;
    -
    - -

    To evaluate this a simple program will add A to B putting -the total in a temporary T1. Then it will add T1 to -C creating another temporary T2 which will be copied into -X. T1 and T2 will sit around till the end of the -execution of the statement and perhaps of the block. It would be faster if the -program recognised that T1 was temporary and stored the sum of -T1 and C back into T1 instead of creating -T2 and then avoided the final copy by just assigning the contents of -T1 to X rather than copying. In this case there will be no -temporaries requiring deletion. (More precisely there will be a header to be -deleted but no contents).

    -

    For an instruction like

    -
       X = (A * B) + (C * D);
    -
    - -

    we can't easily avoid one temporary being left over, so we would like this -temporary deleted as quickly as possible.

    -

    I provide the functionality for doing all this by attaching a status -variable to each matrix. This indicates if the matrix is temporary so that its -memory is available for recycling or deleting. Any matrix operation checks the -status variables of the matrices it is working with and recycles or deletes any -temporary memory.

    -

    An alternative or additional approach would be to use reference counting -and delayed copying - also known as copy on write. If a program -requests a matrix to be copied, the copy is delayed until an instruction is -executed which modifies the memory of either the original matrix or the copy. -If the original matrix is deleted before either matrix is modified, in effect, -the values of the original matrix are transferred to the copy without any -actual copying taking place. This solves the difficult problem of returning an -object from a function without copying and saves the unnecessary copying in the -previous examples.

    -

    There are downsides to the delayed copying approach. Typically, for delayed -copying one uses a structure like the following:

    -
       Matrix
    +    

    + At the last step the heap memory associated with A is returned to + the system and a new block of heap memory is assigned to contain the new + values. This happens even if there is no change in the amount of memory + required. +

    +

    One block or several

    +

    + The elements of the matrix are stored as a single array. Alternatives + would have been to store each row as a separate array or a set of adjacent + rows as a separate array. The present solution simplifies the program but + limits the size of matrices in 16 bit PCs that have a 64k byte limit on + the size of arrays (I don't use the huge keyword). The large + arrays may also cause problems for memory management in smaller machines. + [The 16 bit PC problem has largely gone away but it was a problem when + much of newmat was written. Now, occasionally I run into the 32 bit + PC problem.] +

    +

    By row or by column or other

    +

    + In Fortran two dimensional arrays are stored by column. In most other + systems they are stored by row. I have followed this later convention. + This makes it easier to interface with other packages written in C but + harder to interface with those written in Fortran. This may have been a + wrong decision. Most work on the efficient manipulation of large matrices + is being done in Fortran. It would have been easier to use this work if I + had adopted the Fortran convention. +

    +

    + An alternative would be to store the elements by mid-sized rectangular + blocks. This might impose less strain on memory management when one needs + to access both rows and columns. +

    +

    Storage of symmetric matrices

    +

    + Symmetric matrices are stored as lower triangular matrices. The decision + was pretty arbitrary, but it does slightly simplify the Cholesky + decomposition program. +

    +

    + 5.5 Memory management - reference counting or status + variable? +

    +

    + next - skip - + up - start +

    +

    Consider the instruction

    +
    +   X = A + B + C;
    +
    + +

    + To evaluate this a simple program will add A to + B putting the total in a temporary T1. Then it will add + T1 to C creating another temporary T2 which + will be copied into X. T1 and T2 will sit + around till the end of the execution of the statement and perhaps of the + block. It would be faster if the program recognised that T1 was + temporary and stored the sum of T1 and C back into + T1 instead of creating T2 and then avoided the final + copy by just assigning the contents of T1 to X rather + than copying. In this case there will be no temporaries requiring + deletion. (More precisely there will be a header to be deleted but no + contents). +

    +

    For an instruction like

    +
    +   X = (A * B) + (C * D);
    +
    + +

    + we can't easily avoid one temporary being left over, so we would like this + temporary deleted as quickly as possible. +

    +

    + I provide the functionality for doing all this by attaching a status + variable to each matrix. This indicates if the matrix is temporary so that + its memory is available for recycling or deleting. Any matrix operation + checks the status variables of the matrices it is working with and + recycles or deletes any temporary memory. +

    +

    + An alternative or additional approach would be to use + reference counting and delayed copying - also known as + copy on write. If a program requests a matrix to be copied, the + copy is delayed until an instruction is executed which modifies the memory + of either the original matrix or the copy. If the original matrix is + deleted before either matrix is modified, in effect, the values of the + original matrix are transferred to the copy without any actual copying + taking place. This solves the difficult problem of returning an object + from a function without copying and saves the unnecessary copying in the + previous examples. +

    +

    + There are downsides to the delayed copying approach. Typically, for + delayed copying one uses a structure like the following: +

    +
    +   Matrix
          |
          +------> Array Object
          |          |
    @@ -3661,169 +4991,210 @@ 

    5.5 Memory management - | +------ Dimension information -

    - -

    where the arrows denote a pointer to a data structure. If one wants to -access the Data array one will need to track through two pointers. If -one is going to write, one will have to check whether one needs to copy first. -This is not important when one is going to access the whole array, say, for a -add operation. But if one wants to access just a single element, then it -imposes a significant additional overhead on that operation. Any subscript -operation would need to check whether an update was required - even read since -it is hard for the compiler to tell whether a subscript access is a read or -write.

    -

    Some matrix libraries don't bother to do this. So if you write A = -B; and then modify an element of one of A or B, then the -same element of the other is also modified. I don't think this is acceptable -behaviour.

    -

    Delayed copy does not provide the additional functionality of my approach -but I suppose it would be possible to have both delayed copy and tagging -temporaries.

    -

    My approach does not automatically avoid all copying. In particular, you -need use a special technique to return a matrix from a function without -copying.

    -

    5.6 Memory management - -accessing contiguous locations

    -

    next - skip - -up - start

    -

    Modern computers work faster if one accesses memory by running through -contiguous locations rather than by jumping around all over the place. Newmat -stores matrices by rows so that algorithms that access -memory by running along rows will tend to work faster than one that runs down -columns. A number of the algorithms used in Newmat were developed before this -was an issue and so are not as efficient as possible.

    -

    I have gradually upgrading the algorithms to access memory by rows. The -following table shows the current status of this process.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    FunctionContiguous memory accessComment
    Add, subtractYes 
    MultiplyYes 
    ConcatenateYes 
    TransposeNo 
    Invert and solveYesMostly
    CholeskyYes 
    QRZ, QRZTYes 
    updateQRZ, updateQRZTPartially 
    SVDNo 
    JacobiNoNot an issue; used only for smaller matrices
    EigenvaluesNo 
    SortYesQuick-sort is naturally good
    FFT?Could be improved?
    -

    This is now all rather out of date. With Pentiums, at least, the important -requirement for speed seems to be to minimise transfers between the RAM memory -and the on-chip memory. There isn't much you can do about add and subtract, but -there lots of possibilities for some of the other operations.

    -

    5.7 Evaluation of expressions - -lazy evaluation

    -

    next - skip - -up - start

    -

    Consider the instruction

    -
       X = B - X;
    -
    - -

    A simple program will subtract X from B, store the result -in a temporary T1 and copy T1 into X. It would be -faster if the program recognised that the result could be stored directly into -X. This would happen automatically if the program could look at the -instruction first and mark X as temporary.

    -

    C programmers would expect to avoid the same problem with

    -
       X = X - B;
    -
    - -

    by using an operator -=

    -
       X -= B;
    -
    - -

    However this is an unnatural notation for non C users and it may be nicer to -write X = X - B; and know that the program will carry out the -simplification.

    -

    Another example where this intelligent analysis of an instruction is helpful -is in

    -
       X = A.i() * B;
    -
    - -

    where i() denotes inverse. Numerical analysts know it is -inefficient to evaluate this expression by carrying out the inverse operation -and then the multiply. Yet it is a convenient way of writing the instruction. -It would be helpful if the program recognised this expression and carried out -the more appropriate approach.

    -

    I regard this interpretation of A.i() * B as just providing a -convenient notation. The objective is not primarily to correct the errors of -people who are unaware of the inefficiency of A.i() * B if interpreted -literally.

    -

    There is a third reason for the two-stage evaluation of expressions and this -is probably the most important one. In C++ it is quite hard to return an -expression from a function such as (*, + etc) without a copy. -This is particularly the case when an assignment (=) is involved. The -mechanism described here provides one way for avoiding this in matrix -expressions.

    -

    The C++ standard (section 12.8/15) allows the compiler to optimise away the -copy when returning an object from a function (but there will still be one copy -is an assignment (=) is involved). This means special handling of returns from a -function is less important when a modern optimising compiler is being -used. 

    -

    To carry out this intelligent analysis of an instruction matrix -expressions are evaluated in two stages. In the the first stage a tree -representation of the expression is formed. For example (A+B)*C is -represented by a tree

    -
    
    +
    + +

    + where the arrows denote a pointer to a data structure. If one wants to + access the Data array one will need to track through two pointers. + If one is going to write, one will have to check whether one needs to copy + first. This is not important when one is going to access the whole array, + say, for a add operation. But if one wants to access just a single + element, then it imposes a significant additional overhead on that + operation. Any subscript operation would need to check whether an update + was required - even read since it is hard for the compiler to tell whether + a subscript access is a read or write. +

    +

    + Some matrix libraries don't bother to do this. So if you write + A = B; and then modify an element of one of A or + B, then the same element of the other is also modified. I don't + think this is acceptable behaviour. +

    +

    + Delayed copy does not provide the additional functionality of my approach + but I suppose it would be possible to have both delayed copy and tagging + temporaries. +

    +

    + My approach does not automatically avoid all copying. In particular, you + need use a special technique to return a matrix from a function without + copying. +

    +

    + 5.6 Memory management - accessing contiguous + locations +

    +

    + next - skip - + up - start +

    +

    + Modern computers work faster if one accesses memory by running through + contiguous locations rather than by jumping around all over the place. + Newmat stores matrices by rows so that algorithms that + access memory by running along rows will tend to work faster than one that + runs down columns. A number of the algorithms used in Newmat were + developed before this was an issue and so are not as efficient as + possible. +

    +

    + I have gradually upgrading the algorithms to access memory by rows. The + following table shows the current status of this process. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    FunctionContiguous memory accessComment
    Add, subtractYes 
    MultiplyYes 
    ConcatenateYes 
    TransposeNo 
    Invert and solveYesMostly
    CholeskyYes 
    QRZ, QRZTYes 
    updateQRZ, updateQRZTPartially 
    SVDNo 
    JacobiNoNot an issue; used only for smaller matrices
    EigenvaluesNo 
    SortYesQuick-sort is naturally good
    FFT?Could be improved?
    +

    + This is now all rather out of date. With Pentiums, at least, the important + requirement for speed seems to be to minimise transfers between the RAM + memory and the on-chip memory. There isn't much you can do about add and + subtract, but there lots of possibilities for some of the other + operations. +

    +

    5.7 Evaluation of expressions - lazy evaluation

    +

    + next - skip - + up - start +

    +

    Consider the instruction

    +
    +   X = B - X;
    +
    + +

    + A simple program will subtract X from B, store the + result in a temporary T1 and copy T1 into X. It + would be faster if the program recognised that the result could be stored + directly into X. This would happen automatically if the program + could look at the instruction first and mark X as temporary. +

    +

    C programmers would expect to avoid the same problem with

    +
    +   X = X - B;
    +
    + +

    by using an operator -=

    +
    +   X -= B;
    +
    + +

    + However this is an unnatural notation for non C users and it may be nicer + to write X = X - B; and know that the program will carry out the + simplification. +

    +

    + Another example where this intelligent analysis of an instruction is + helpful is in +

    +
    +   X = A.i() * B;
    +
    + +

    + where i() denotes inverse. Numerical analysts know it is + inefficient to evaluate this expression by carrying out the inverse + operation and then the multiply. Yet it is a convenient way of writing the + instruction. It would be helpful if the program recognised this expression + and carried out the more appropriate approach. +

    +

    + I regard this interpretation of A.i() * B as just providing a + convenient notation. The objective is not primarily to correct the errors + of people who are unaware of the inefficiency of A.i() * B if + interpreted literally. +

    +

    + There is a third reason for the two-stage evaluation of expressions and + this is probably the most important one. In C++ it is quite hard to return + an expression from a function such as (*, + etc) without + a copy. This is particularly the case when an assignment (=) is + involved. The mechanism described here provides one way for avoiding this + in matrix expressions. +

    +

    + The C++ standard (section 12.8/15) allows the compiler to optimise away + the copy when returning an object from a function (but there will still be + one copy is an assignment (=) is involved). This + means special handling of returns from a function is less important when a + modern optimising compiler is being used.  +

    +

    + To carry out this intelligent analysis of an instruction matrix + expressions are evaluated in two stages. In the the first stage a tree + representation of the expression is formed. For example + (A+B)*C is represented by a tree +

    +
    
            *
           / \
          +   C
    @@ -3831,158 +5202,224 @@ 

    5.7 Evaluation of expressions - A B

    -

    Rather than adding A and B the + operator yields -an object of a class AddedMatrix which is just a pair of pointers to -A and B. Then the * operator yields a -MultipliedMatrix which is a pair of pointers to the AddedMatrix -and C. The tree is examined for any simplifications and then evaluated -recursively.

    -

    Further possibilities not yet included are to recognise A.t()*A and -A.t()+A as symmetric or to improve the efficiency of evaluation of -expressions like A+B+C, A*B*C, A*B.t() (t() -denotes transpose).

    -

    One of the disadvantages of the two-stage approach is that the types of -matrix expressions are determined at run-time. So the compiler will not detect -errors of the type

    -
       Matrix M;
    +    

    + Rather than adding A and B the + operator + yields an object of a class AddedMatrix which is just a pair of + pointers to A and B. Then the * operator yields + a MultipliedMatrix which is a pair of pointers to the + AddedMatrix and C. The tree is examined for any + simplifications and then evaluated recursively. +

    +

    + Further possibilities not yet included are to recognise + A.t()*A and A.t()+A as symmetric or to improve the + efficiency of evaluation of expressions like A+B+C, + A*B*C, A*B.t() (t() denotes transpose). +

    +

    + One of the disadvantages of the two-stage approach is that the types of + matrix expressions are determined at run-time. So the compiler will not + detect errors of the type +

    +
    +   Matrix M;
        DiagonalMatrix D;
        ....;
        D = M;
    -
    - -

    We don't allow conversions using = when information would be lost. -Such errors will be detected when the statement is executed.

    -

    5.8 How to overcome an -explosion in number of operations

    -

    next - skip - -up - start

    -

    The package attempts to solve the problem of the large number of versions of -the binary operations required when one has a variety of types.

    -

    With n types of matrices the binary operations will each require -n-squared separate algorithms. Some reduction in the number may be -possible by carrying out conversions. However, the situation rapidly becomes -impossible with more than 4 or 5 types. Doug Lea told me that it was possible -to avoid this problem. I don't know what his solution is. Here's mine.

    -

    Each matrix type includes routines for extracting individual rows or -columns. I assume a row or column consists of a sequence of zeros, a sequence -of stored values and then another sequence of zeros. Only a single algorithm is -then required for each binary operation. The rows can be located very quickly -since most of the matrices are stored row by row. Columns must be copied and so -the access is somewhat slower. As far as possible my algorithms access the -matrices by row.

    -

    There is another approach. Each of the matrix types defined in this package -can be set up so both rows and columns have their elements at equal intervals -provided we are prepared to store the rows and columns in up to three chunks. -With such an approach one could write a single "generic" algorithm -for each of multiply and add. This would be a reasonable alternative to my -approach.

    -

    I provide several algorithms for operations like + . If one is adding two -matrices of the same type then there is no need to access the individual rows -or columns and a faster general algorithm is appropriate.

    -

    Generally the method works well. However symmetric matrices are not always -handled very efficiently (yet) since complete rows are not stored explicitly. -

    -

    The original version of the package did not use this access by row or column -method and provided the multitude of algorithms for the combination of -different matrix types. The code file length turned out to be just a little -longer than the present one when providing the same facilities with 5 distinct -types of matrices. It would have been very difficult to increase the number of -matrix types in the original version. Apparently 4 to 5 types is about the -break even point for switching to the approach adopted in the present package. -

    -

    However it must also be admitted that there is a substantial overhead in the -approach adopted in the present package for small matrices. The test program -developed for the original version of the package takes 30 to 50% longer to run -with the current version (though there may be some other reasons for this). -This is for matrices in the range 6x6 to 10x10.

    -

    To try to improve the situation a little I do provide an ordinary matrix -multiplication routine for the case when all the matrices involved are -rectangular.

    -

    5.9 Destruction of -temporaries

    -

    next - skip - -up - start

    -

    Versions before version 5 of newmat did not work correctly with Gnu C++ -(version 5 or earlier). This was because the tree structure used to represent a -matrix expression was set up on the stack.  Early versions of Gnu C++ destroyed temporary structures as soon as the -function that accesses them finished. To overcome this problem, there was an -option to store the temporaries forming the tree structure on the heap (created -with new) and to delete them explicitly. Now that the C++ standards committee -has said that temporary structures should not be destroyed before a statement -finishes, I have deleted this option.

    -

    5.10 A calculus of matrix -types

    -

    next - skip - -up - start

    -

    The program needs to be able to work out the class of the result of a matrix -expression. This is to check that a conversion is legal or to determine the -class of an intermediate result. To assist with this, a class MatrixType is -defined. Operators +, -, *, >= are -defined to calculate the types of the results of expressions or to check that -conversions are legal.

    -

    Early versions of newmat stored the types of the results of -operations in a table. So, for example, if you multiplied an -UpperTriangularMatrix by a LowerTriangularMatrix, newmat would look up -the table and see that the result was of type Matrix. With this approach the -exploding number of operations problem recurred although -not as seriously as when code had to be written for each pair of types. But -there was always the suspicion that somewhere, there was an error in one of -those 9x9 tables, that would be very hard to find. And the problem would get -worse as additional matrix types or operators were included.

    -

    The present version of newmat solves the problem by assigning -attributes such as diagonal or band or upper -triangular to each matrix type. Which attributes a matrix type has, is -stored as bits in an integer. As an example, the DiagonalMatrix type has the -bits corresponding to diagonal, symmetric and band equal -to 1. By looking at the attributes of each of the operands of a binary -operator, the program can work out the attributes of the result of the -operation with simple bitwise operations. Hence it can deduce an appropriate -type. The symmetric attribute is a minor problem because -symmetric * symmetric does not yield symmetric unless both -operands are diagonal. But otherwise very simple code can be used to -deduce the attributes of the result of a binary operation.

    -

    Tables of the types resulting from the binary operators are output at the -beginning of the test program.

    -

    5.11 Pointer arithmetic

    -

    next - skip - -up - start

    -

    Suppose you do something like

    -
       int* y = new int[100];
    +
    + +

    + We don't allow conversions using = when information would be + lost. Such errors will be detected when the statement is executed. +

    +

    + 5.8 How to overcome an explosion in number of + operations +

    +

    + next - skip - + up - start +

    +

    + The package attempts to solve the problem of the large number of versions + of the binary operations required when one has a variety of types. +

    +

    + With n types of matrices the binary operations will each require + n-squared separate algorithms. Some reduction in the number may be + possible by carrying out conversions. However, the situation rapidly + becomes impossible with more than 4 or 5 types. Doug Lea told me that it + was possible to avoid this problem. I don't know what his solution is. + Here's mine. +

    +

    + Each matrix type includes routines for extracting individual rows or + columns. I assume a row or column consists of a sequence of zeros, a + sequence of stored values and then another sequence of zeros. Only a + single algorithm is then required for each binary operation. The rows can + be located very quickly since most of the matrices are stored row by row. + Columns must be copied and so the access is somewhat slower. As far as + possible my algorithms access the matrices by row. +

    +

    + There is another approach. Each of the matrix types defined in this + package can be set up so both rows and columns have their elements at + equal intervals provided we are prepared to store the rows and columns in + up to three chunks. With such an approach one could write a single + "generic" algorithm for each of multiply and add. This would be + a reasonable alternative to my approach. +

    +

    + I provide several algorithms for operations like + . If one is adding two + matrices of the same type then there is no need to access the individual + rows or columns and a faster general algorithm is appropriate. +

    +

    + Generally the method works well. However symmetric matrices are not always + handled very efficiently (yet) since complete rows are not stored + explicitly. +

    +

    + The original version of the package did not use this access by row or + column method and provided the multitude of algorithms for the combination + of different matrix types. The code file length turned out to be just a + little longer than the present one when providing the same facilities with + 5 distinct types of matrices. It would have been very difficult to + increase the number of matrix types in the original version. Apparently 4 + to 5 types is about the break even point for switching to the approach + adopted in the present package. +

    +

    + However it must also be admitted that there is a substantial overhead in + the approach adopted in the present package for small matrices. The test + program developed for the original version of the package takes 30 to 50% + longer to run with the current version (though there may be some other + reasons for this). This is for matrices in the range 6x6 to 10x10. +

    +

    + To try to improve the situation a little I do provide an ordinary matrix + multiplication routine for the case when all the matrices involved are + rectangular. +

    +

    5.9 Destruction of temporaries

    +

    + next - skip - + up - start +

    +

    + Versions before version 5 of newmat did not work correctly with Gnu C++ + (version 5 or earlier). This was because the tree structure used to + represent a matrix expression was set up on the stack.  Early + versions of Gnu C++ destroyed temporary structures as soon as the function + that accesses them finished. To overcome this problem, there was an option + to store the temporaries forming the tree structure on the heap (created + with new) and to delete them explicitly. Now that the C++ standards + committee has said that temporary structures should not be destroyed + before a statement finishes, I have deleted this option. +

    +

    5.10 A calculus of matrix types

    +

    + next - skip - + up - start +

    +

    + The program needs to be able to work out the class of the result of a + matrix expression. This is to check that a conversion is legal or to + determine the class of an intermediate result. To assist with this, a + class MatrixType is defined. Operators +, -, *, + >= are defined to calculate the types of the results of + expressions or to check that conversions are legal. +

    +

    + Early versions of newmat stored the types of the results of + operations in a table. So, for example, if you multiplied an + UpperTriangularMatrix by a LowerTriangularMatrix, newmat would look + up the table and see that the result was of type Matrix. With this + approach the exploding number of operations problem + recurred although not as seriously as when code had to be written for each + pair of types. But there was always the suspicion that somewhere, there + was an error in one of those 9x9 tables, that would be very hard to find. + And the problem would get worse as additional matrix types or operators + were included. +

    +

    + The present version of newmat solves the problem by assigning + attributes such as diagonal or band or + upper triangular to each matrix type. Which attributes a matrix + type has, is stored as bits in an integer. As an example, the + DiagonalMatrix type has the bits corresponding to diagonal, + symmetric and band equal to 1. By looking at the attributes + of each of the operands of a binary operator, the program can work out the + attributes of the result of the operation with simple bitwise operations. + Hence it can deduce an appropriate type. The symmetric attribute is + a minor problem because symmetric * symmetric does not yield + symmetric unless both operands are diagonal. But otherwise + very simple code can be used to deduce the attributes of the result of a + binary operation. +

    +

    + Tables of the types resulting from the binary operators are output at the + beginning of the test program. +

    +

    5.11 Pointer arithmetic

    +

    + next - skip - + up - start +

    +

    Suppose you do something like

    +
    +   int* y = new int[100];
        y += 200;          // y points to something outside the array
    -   // y is never accessed
    -
    - -

    Then the standard says that the behaviour of the program is undefined -even if y is never accessed. (You are allowed to calculate a pointer -value one location beyond the end of the array). In practice, a program like -this does not cause any problems with any compiler I have come across and -no-one has reported any such problems to me.

    -

    However, this error is detected by Borland's Code Guard -bound's checker and this makes it very difficult to use this to use Code -Guard to detect other problems since the output is swamped by reports of -this error.

    -

    Now consider

    -
       int* y = new int[100];
    +   // y is never accessed
    +
    + +

    + Then the standard says that the behaviour of the program is + undefined even if y is never accessed. (You are allowed to + calculate a pointer value one location beyond the end of the array). In + practice, a program like this does not cause any problems with any + compiler I have come across and no-one has reported any such problems to + me. +

    +

    + However, this error is detected by Borland's + Code Guard bound's checker and this makes it very difficult to use + this to use Code Guard to detect other problems since the output is + swamped by reports of this error. +

    +

    Now consider

    +
    +   int* y = new int[100];
        y += 200;          // y points to something outside the array
        y -= 150;          // y points to something inside the array
    -   // y is accessed
    -
    - -

    Again this is not strictly correct but does not seem to cause a problem. But -it is much more doubtful than the previous example.

    -

    I removed most instances of the second version of the problem from Newmat09. -Hopefully the remainder of these instances were removed from Newmat10. In addition, most instances of the first version of the -problem have also been fixed.

    -

    There is one exception. The interface to the Numerical -Recipes in C does still contain the second version of the problem. This is -inevitable because of the way Numerical Recipes in C stores vectors and -matrices. If you are running the test program with a -bounds checking program, edit tmt.h to disable the testing of the NRIC -interface.

    -

    The rule does does cause a problem for authors of matrix and -multidimensional array packages. If we want to run down a column of a matrix we -would like to do something like

    -
       // set values of column 1
    +   // y is accessed
    +
    + +

    + Again this is not strictly correct but does not seem to cause a problem. + But it is much more doubtful than the previous example. +

    +

    + I removed most instances of the second version of the problem from + Newmat09. Hopefully the remainder of these instances were removed from + Newmat10. In addition, most instances of the first version of the problem + have also been fixed. +

    +

    + There is one exception. The interface to the + Numerical Recipes in C does still contain the second + version of the problem. This is inevitable because of the way Numerical + Recipes in C stores vectors and matrices. If you are running the + test program with a bounds checking program, edit + tmt.h to disable the testing of the NRIC interface. +

    +

    + The rule does does cause a problem for authors of matrix and + multidimensional array packages. If we want to run down a column of a + matrix we would like to do something like +

    +
    +   // set values of column 1
        Matrix A;
        ... set dimensions and put values in A
        Real* a = A.data();               // points to first element
    @@ -3993,13 +5430,16 @@ 

    5.11 Pointer arithmetic

    *a = something to put in first element of row a += nc; // jump to next element of column } -
    +
    -

    If the matrix has more than one column the last execution of a += -nc; will run off the end of the space allocated to the matrix and we'll -get a bounds error report.

    -

    Instead we have to use a program like

    -
       // set values of column 1
    +    

    + If the matrix has more than one column the last execution of + a += nc; will run off the end of the space allocated to the + matrix and we'll get a bounds error report. +

    +

    Instead we have to use a program like

    +
    +   // set values of column 1
        Matrix A;
        ... set dimensions and put values in A
        Real* a = A.data();               // points to first element
    @@ -4014,1105 +5454,1604 @@ 

    5.11 Pointer arithmetic

    a += nc; // jump to next element of column } } -
    - -

    which is more complicated and consequently introduces more chance of error. -

    -

    5.12 Error handling -

    -

    next - skip - -up - start

    -

    The library now does have a moderately graceful exit from errors. One can -use either the simulated exceptions or the compiler supported exceptions. When -newmat08 was released (in 1995), compiler exception handling in the compilers I -had access to was unreliable. I recommended you used my simulated exceptions. -In 1997 compiler supported exceptions seemed to work on a variety of -compilers - but not all compilers. This was still true in 2001. One compiler -company was still having problems in 2003 (not sure about 2004). Try using the -compiler supported exceptions if you have a recent compiler, but if you are -getting strange crashes or errors try going back to my simulated exceptions.

    -

    The approach in the present library, attempting to simulate C++ exceptions, -is not completely satisfactory, but seems a good interim solution for those who -cannot use compiler supported exceptions. People who don't want exceptions in -any shape or form, can set the option to exit the program if an exception is -thrown.

    -

    The exception mechanism cannot clean-up objects explicitly created by new. -This must be explicitly carried out by the package writer or the package user. -I have not yet done this completely with the present package so occasionally a -little garbage may be left behind after an exception. I don't think this is a -big problem, but it is one that needs fixing.

    -

    5.13 Sparse matrices

    -

    next - skip - -up - start

    -

    The library does not support sparse matrices.

    -

    For sparse matrices there is going to be some kind of structure vector. It -is going to have to be calculated for the results of expressions in much the -same way that types are calculated. In addition, a whole new set of row and -column operations would have to be written.

    -

    Sparse matrices are important for people solving large sets of differential -equations as well as being important for statistical and operational research -applications.

    -

    But there are packages being developed specifically for sparse matrices and -these might present the best approach, at least where sparse matrices are the -main interest.

    -

    5.14 Complex matrices

    -

    next - skip - -up - start

    -

    The package does not yet support matrices with complex elements. There are -at least two approaches to including these. One is to have matrices with -complex elements.

    -

    This probably means making new versions of the basic row and column -operations for Real*Complex, Complex*Complex, Complex*Real and similarly for -+ and -. This would be OK, except that if I also want to do -this for sparse matrices, then when you put these together, the whole thing -will get out of hand.

    -

    The alternative is to represent a Complex matrix by a pair of Real matrices. -One probably needs another level of decoding expressions but I think it might -still be simpler than the first approach. But there is going to be a problem -with accessing elements and it does not seem possible to solve this in an -entirely satisfactory way.

    -

    Complex matrices are used extensively by electrical engineers and physicists -and really should be fully supported in a comprehensive package.

    -

    You can simulate most complex operations by representing Z = X + iY -by

    -
        /  X   Y \
    -    \ -Y   X / 
    -
    - -

    Most matrix operations will simulate the corresponding complex operation, -when applied to this matrix. But, of course, this matrix is essentially twice as big as you -would need with a genuine complex matrix library.

    - - -

     

    - - -

    6. Function summary

    - - -

    next - skip - -up - start

    - - -

    6.1 Member functions for matrices -and matrix expressions
    -6.2 Member functions for matrices
    -6.3 Operators
    -6.3 Global functions - newmat.h
    -6.4 Global functions - newmatap.h
    -6.5 Other classes - member functions

    - - -

    This section lists member and global functions for matrices defined in -newmat.h. Where there are alternative names the lower-case non-capitalised -versions are the preferred ones.

    - - -

    6.1 Member functions for matrices and matrix expressions

    -

    next - -skip - up - start

    -

    Member functions for matrices and matrix expressions. These do not apply to -CroutMatrix and BandLUMatrix -unless explicitly noted.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    Unary operators

    (see also - operators)

    .t()matrix transpose
    .reverse()
    - .Reverse()
    reverse order of elements (not band matrices)
    .i()invert matrix or solve (also works with CroutMatrix and BandLUMatrix)
    .sum_rows()sum elements in each row
    .sum_columns()sum elements in each column
    .sum_square_rows()sum squares of elements in each row
    .sum_square_columns()sum squares of elements in each column
    Change type.as_row()
    - .AsRow()
    interpret matrix body as a single row
    .as_column()
    - .AsColumn()
    interpret matrix body as a single column
    .as_diagonal()
    - .AsDiagonal()
    interpret matrix body as a diagonal matrix
    .as_matrix()
    - .AsMatrix()
    interpret matrix body as a rectangular matrix
    .as_scalar()
    - .AsScalar()
    convert 1x1 to Real
    Submatrices.submatrix(int,int,int,int)
    - .SubMatrix(int,int,int,int)
    submatrix
    .sym_submatrix(int,int)
    - .SymSubMatrix(int,int)
    submatrix with same row and column range
    .row(int)
    - .Row(int)
    select a row of a matrix
    .rows(int,int)
    - .Rows(int,int)
    select a range of rows of a matrix
    .column(int)
    - .Column(int,int)
    select a column of a matrix
    .columns(int)
    - .Columns(int,int)
    select a range of columns of a matrix
    Scalar functions - maxima & - minima

    (also global versions of maximum(), minimum(),  - maximum_absolute_value(), mimimum_absolute_value())

    .maximum_absolute_value()
    - .
    MaximumAbsoluteValue()
    maximum absolute value of elements
    .maximum_absolute_value1(int&)
    - .MaximumAbsoluteValue1(int&)
    maximum absolute value, return location
    .maximum_absolute_value2(int&,int&)
    - .MaximumAbsoluteValue2(int&,int&)
    maximum absolute value, return location
    .minimum_absolute_value()
    - .MinimumAbsoluteValue()
    minimum absolute value of elements
    .minimum_absolute_value1(int&)
    - .MinimumAbsoluteValue1(int&)
    minimum absolute value, return location
    .minimum_absolute_value2(int&,int&)
    - .MinimumAbsoluteValue2(int&,int&)
    minimum absolute value, return location
    .maximum()
    - .Maximum()
    maximum value of elements
    .maximum1(int&)
    - .Maximum1(int&)
    maximum value, return location
    .maximum2(int&,int&)
    - .Maximum2(int&,int&)
    maximum value, return location
    .minimum()
    - .Minimum()
    minimum value of elements
    .minimum1(int&)
    - .Minimum1(int&)
    minimum value, return location
    .minimum2(int&,int&)
    - .Minimum2(int&,int&)
    minimum value, return location
    Scalar functions - numerical

    - (also global versions of these functions)

    .log_determinant()
    - .LogDeterminant()
    natural logarithm of the determinant (also works with CroutMatrix and BandLUMatrix)
    .determinant()
    - .Determinant()
    determinant (also works with CroutMatrix and BandLUMatrix)
    .sum_square()
    - .SumSquare()
    sum of squares of elements
    .norm_Frobenius()
    - .norm_frobenius()
    - .NormFrobenius()
    square root of sum of squares of elements
    .sum_absolute_value()
    - .SumAbsoluteValue()
    sum of absolute values of elements
    .sum()
    - .Sum()
    sum of elements
    .trace()
    - .Trace()
    trace of a matrix
    .norm1()
    - .Norm1()
    maximum of sum of absolute values of elements of a column
    .norm_infinity()
    - .NormInfinity()
    maximum of sum of absolute values of elements of a row
    Scalar functions - size and shape.bandwidth()
    - .BandWidth()
    bandwidth of matrix (also works with CroutMatrix and BandLUMatrix)
    -

     

    -

    6.2 Member functions for matrices

    -

    next - skip - up - start

    -

    Member functions for matrices but not matrix expressions. These do not apply -to CroutMatrix and BandLUMatrix unless explicitly noted.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    Element access

    (see - also operators)

    .element(int,int)access element - subscripts start at 0
    .element(int)access element - subscripts start at 0
    Copying.inject(const GeneralMatrix&)
    - .Inject(const GeneralMatrix&)
    copy elements into a matrix
    .swap(Matrix&)swap bodies of two matrices of same type (also global - version, also works with CroutMatrix and BandLUMatrix)
    Scalar functions - size and - shape

    (also work with CroutMatrix and BandLUMatrix)

    .type()
    - .Type()
    type of a matrix
    .nrows()
    - .Nrows()
    number of rows
    .ncols()
    - .Ncols()
    number of columns
    .size()
    - .Storage()
    number of stored elements (including unused elements in band - matrices)
    .size2()size of second array (BandLUMatrix only)
    .data()
    - .Store()
    pointer to stored elements
    .const_data()constant pointer to stored elements
    .const_data2()constant pointer to second array (BandLUMatrix only)
    .const_data_indx()constant pointer to row swap array (CroutMatrix and BandLUMatrix - only)
    Scalar functions - numerical.is_zero()
    - .IsZero()
    test all elements are exactly zero (also global version)
    .is_singular()
    - .IsSingular()
    test for exact singularity (CroutMatrix and BandLUMatrix - only)
    .even_exchanges()true if there have been an even number of row exchanges (CroutMatrix and BandLUMatrix - only)
    Memory management.release()
    - .Release()
    release memory after next operation
    .release(int)
    - .Release(int)
    release memory after specified number of operations
    .release_and_delete()
    - .ReleaseAndDelete()
    delete after next operation
    .for_return()
    - .ForReturn()
    place in an envelope for efficient return from a function
    Change dimensions.resize(int)
    - .ReSize(int)
    change the dimensions (vectors and square matrices)
    .resize(int,int)
    - .ReSize(int,int)
    change the dimensions (non-square matrices, triangular band - matrices and symmetric band matrices)
    .resize(int,int,int)
    - .ReSize(int,int,int)
    change the dimensions (band matrices)
    .resize(const GeneralMatrix&)
    - .ReSize(const GeneralMatrix&)
    change dimensions to match those of another matrix
    .cleanup()
    - .CleanUp()
    resize to 0x0
    .resize_keep(int)change the dimensions, keep values (vectors and square matrices, - not band)
    .resize_keep(int,int)change the dimensions , keep values (non-square matrices)
    -

     

    -

    6.3 Operators

    -

    next - -skip - up - start

    -

    Operators for matrices and matrix expressions. These do not apply to CroutMatrix and BandLUMatrix -unless explicitly noted.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    Element access

    - (matrices only, not functions of a matrix)

    ()access element - subscripts start at 1
    ()access element - subscripts start at 1
    []access element C style - subscripts start at zero; if - SETUP_C_SUBSCRIPTS is defined.
    Unary operators-change sign of elements
    Binary operators+, +=add matrices
    -, -=subtract matrices
    *, *=matrix multiplication
    |, |=horizontal concatenation
    &, &=vertical stacking
    ==test for exact equality (also works with CroutMatrix and BandLUMatrix)
    !=test for inequality (i.e. not exact equality, also works with CroutMatrix and BandLUMatrix)
    Matrix and scalar+, +=add Real to matrix
    -, -=subtract Real from matrix; subtract matrix from Real
    *, *=multiply matrix by Real
    /, /=divide matrix by Real
    Copying=copy matrix (error if there is loss of data,  also works with CroutMatrix and BandLUMatrix)
    =copy Real - to all elements
    <<copy matrix (no error if there is loss of data)
    Enter values<<enter list of values into matrix
    Output

    (header in newmatio.h)

    <<print matrix to file
    -

     

    - -

    6.4 Global functions - newmat.h

    -

    next - -skip - -up - start

    -

    Operators for matrices and matrix expressions. These do not apply to CroutMatrix and BandLUMatrix.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    Binary operators

    (see - also operators)

    SP(const BaseMatrix&, const BaseMatrix&)element-wise product of two matrices
    KP(const BaseMatrix&, const BaseMatrix&)Kronecker product of two matrices
    crossproduct(const Matrix&, const Matrix&)
    - CrossProduct(const Matrix&, const Matrix&)
    cross product of two 3x1 or 1x3 matrices or vectors.
    crossproduct_rows(const Matrix&, const Matrix&)
    - CrossProductRows(const Matrix&, const Matrix&)
    row-wise cross product
    crossproduct_columns(const Matrix&, const Matrix&)
    - CrossProductColumns(const Matrix&, const Matrix&)
    column-wise cross product
    Scalar functions - numericaldotproduct(const Matrix&, const Matrix&)
    -
    DotProduct(const Matrix&, const Matrix&)
    dot product of two vectors
    - -

     

    - - -

    6.5 Global functions - newmatap.h

    -

    next - skip - -up - start

    - -

    Advanced operators for matrices and matrix expressions. These do not apply to CroutMatrix and BandLUMatrix.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    QR transformQRZT(Matrix&, LowerTriangularMatrix&)transposed version of QRZ transform
    QRZT(const Matrix&, Matrix&, Matrix&)transposed version of QRZ transform - solve part
    QRZT(Matrix&, Matrix&, LowerTriangularMatrix&, Matrix&)both of previous two lines
    QRZ(Matrix&, UpperTriangularMatrix&)QRZ transform
    QRZ(const Matrix&, Matrix&, Matrix&)QRZ transform - solve part
    QRZ(Matrix&, Matrix&, UpperTriangularMatrix&, Matrix&)both of previous two lines
    updateQRZT(Matrix&, LowerTriangularMatrix&)
    - UpdateQRZT(Matrix&, LowerTriangularMatrix&)
    add extra columns to transposed version of QRZ - transform
    updateQRZ(Matrix&, UpperTriangularMatrix&)
    - UpdateQRZ(Matrix&, UpperTriangularMatrix&)
    add extra rows to QRZ transform
    updateQRZ(const Matrix&, Matrix&, Matrix&)
    - UpdateQRZ(const Matrix&, Matrix&, Matrix&)
    combine the results of the solve parts of QRZ - transforms on two blocks of data
    updateQRZ(UpperTriangularMatrix&, UpperTriangularMatrix&)
    - UpdateQRZ(UpperTriangularMatrix&, UpperTriangularMatrix&)
    combine the results of QRZ transforms on two - blocks of data
    updateQRZ(const UpperTriangularMatrix&, Matrix&, Matrix&)
    - UpdateQRZ(const UpperTriangularMatrix&, Matrix&, Matrix&)
    combine the results of the solve parts of QRZ - transforms on two blocks of data
    Extend orthonormal setextend_orthonormal(Matrix&, int)extend a set of orthonormal columns
    Cholesky - decompositionCholesky(const SymmetricMatrix&)Cholesky decomposition of symmetric matrix
    Cholesky(const SymmetricBandMatrix&)Cholesky decomposition of symmetric band matrix
    Update Cholesky - decompositionupdate_Cholesky (UpperTriangularMatrix&, - RowVector)
    - UpdateCholesky (UpperTriangularMatrix&, - RowVector)
    add extra row to Cholesky/QR decomposition
    downdate_Cholesky (UpperTriangularMatrix&, - RowVector)
    - DowndateCholesky (UpperTriangularMatrix&, - RowVector)
    remove row from Cholesky/QR decomposition
    right_circular_update_Cholesky (UpperTriangularMatrix&, - int, int)
    - RightCircularUpdateCholesky (UpperTriangularMatrix&, - int, int)
    rearrange columns in Cholesky/QR decomposition
    left_circular_update_Cholesky (UpperTriangularMatrix&, - int, int)
    - LeftCircularUpdateCholesky (UpperTriangularMatrix&, - int, int)
    rearrange columns in Cholesky/QR decomposition
    Singular value - decompositionSVD(const Matrix&, DiagonalMatrix&, - Matrix&, Matrix&, bool, bool)singular value decomposition - get U and V
    SVD(const Matrix&, DiagonalMatrix&)SVD decomposition - get just singular values
    SVD(const Matrix& A, DiagonalMatrix& D, - Matrix&, bool)SVD decomposition - get U
    Eigenvalue - decomposition of a symmetric matrixJacobi(const SymmetricMatrix&, - DiagonalMatrix&)Jacobi eigenvalue decomposition - get only eigenvalues
    Jacobi(const SymmetricMatrix&, - DiagonalMatrix&, SymmetricMatrix&)Jacobi eigenvalue decomposition - get only - eigenvalues
    Jacobi(const SymmetricMatrix&, - DiagonalMatrix&, Matrix&)Jacobi eigenvalue decomposition - get - eigenvalues and eigenvectors
    Jacobi(const SymmetricMatrix&, - DiagonalMatrix&, SymmetricMatrix&, Matrix&, bool)Jacobi eigenvalue decomposition - get - eigenvalues and eigenvectors
    eigenvalues(const SymmetricMatrix&, - DiagonalMatrix&)
    - EigenValues(const SymmetricMatrix&, - DiagonalMatrix&)
    Householder eigenvalue decomposition - get only - eigenvalues
    eigenvalues(const SymmetricMatrix&, - DiagonalMatrix&, SymmetricMatrix&)
    - EigenValues(const SymmetricMatrix&, - DiagonalMatrix&, SymmetricMatrix&)
    Householder eigenvalue decomposition with back - transform - get only eigenvalues
    eigenvalues(const SymmetricMatrix&, - DiagonalMatrix&, Matrix&)
    - EigenValues(const SymmetricMatrix&, - DiagonalMatrix&, Matrix&)
    Householder eigenvalue decomposition - get - eigenvalues and eigenvectors
    Sortingsort_ascending(GeneralMatrix&)
    - SortAscending(GeneralMatrix&)
    ascending sort
    sort_descending(GeneralMatrix&)
    - SortDescending(GeneralMatrix&)
    descending sort
    Fast Fourier - transformFFT(const ColumnVector&, const - ColumnVector&, ColumnVector&, ColumnVector&)fast Fourier transform
    FFTI(const ColumnVector&, const - ColumnVector&, ColumnVector&, ColumnVector&)fast Fourier transform - inverse
    RealFFT(const ColumnVector&, ColumnVector&, - ColumnVector&)FFT of real vector
    RealFFTI(const ColumnVector&, const - ColumnVector&, ColumnVector&)FFT of real vector - inverse
    FFT2(const Matrix& U, const Matrix& V, - Matrix& X, Matrix& Y)two dimensional FFT
    FFT2I(const Matrix& U, const Matrix& V, - Matrix& X, Matrix& Y)two dimensional FFT - inverse
    Fast - trigonometric transformDCT_II(const ColumnVector&, ColumnVector&)type II discrete cosine transform
    DCT_II_inverse(const ColumnVector&, - ColumnVector&)type II discrete cosine transform - inverse
    DST_II(const ColumnVector&, ColumnVector&)type II discrete sine transform
    DST_II_inverse(const ColumnVector&, - ColumnVector&)type II discrete sine transform - inverse
    DCT(const ColumnVector&, ColumnVector&)discrete cosine transform
    DCT_inverse(const ColumnVector&, - ColumnVector&)discrete cosine transform - inverse
    DST(const ColumnVector&, ColumnVector&)discrete sine transform
    DST_inverse(const ColumnVector&, - ColumnVector&)discrete sine transform - inverse
    - Helmert transformHelmert(int, bool=false)return Helmert transform matrix
    Helmert(const ColumnVector&, bool=false)
    - Helmert(const Matrix&, bool=false)
    multiply by Helmert transform matrix
    Helmert(int, int, bool=false)return column of Helmert transform matrix
    Helmert_transpose(const ColumnVector&, bool=false)
    - Helmert_transpose(const Matrix&, bool=false)
    multiply by transpose of Helmert transform - matrix
    Helmert_transpose(const ColumnVector&, int, bool=false)multiply by transpose of Helmert transform - matrix, return one element of result
    - -

     

    -

    6.6 Other classes - member functions

    -

    next - skip - -up - start

    - -

     

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Classfunction namedescription
    LogAndSign.pow_eq(int)
    - .PowEq(int)
    raise to a power
    .change_sign()
    - .ChangeSign()
    change sign
    .log_value()
    - .LogValue()
    return the natural logarithm of the value
    .sign()
    - .Sign()
    return the sign
    .value()
    - .Value()
    return the value (no log transform)
    MatrixType.value()
    - .Value()
    return the value (as character string)
    .is_diagonal()has diagonal attribute
    .is_symmetric() has symmetric attribute
    .is_band()has band attribute
    MatrixBandWidth.upper()
    - .Upper()
    return upper band width
    .lower()
    - .Lower()
    return lower bandwidth
    SimpleIntArray.size()
    - .Size()
    return size of array
    .data()
    - .Data()
    return a pointer to the data
    .const_data()return a constant pointer to the data
    .resize()
    - .Resize()
    change the size of an array
    .resize_keep()
    - .resize(true)
    - .Resize(true)
    change the size of an array - keep the values
    .cleanup()
    - .CleanUp()
    resize to zero
    - - -

     

    - - -

    7. Change history

    -

    next - skip - -up - start

    -

    Newmat11 - November, 2008:

    -

    Remove work-arounds for older compilers, Borland Builder 6 and -Open Watcom compatibility, SquareMatrix, -load from array of ints, crossproducts, Cholesky and QRZ update functions, swap -functions, FFT2, access to arrays in traditional C functions, SimpleIntArray -class, compatibility with Numerical Recipes in C++, sum_rows(), sum_columns(), sum_squares_rows() and -sum_squares_columns() functions, extend_orthogonal function, resize_keep -function, speed-ups and -bug-fixes, change to lower case for functions, can copy CroutMatrix, -BandLUMatrix, Helmert transform, compatibility fix for G++ 4.1, start inserting -comments for Doxygen, SP_eq, scientific format for output, fix for 64 bits.

    -

    Newmat10A - October, 2002, Newmat10B - January 2005:

    -

    Fix error in Kronecker product; fixes for Intel and GCC3 -compilers.

    -

    Newmat10 - January, 2002:

    -

    Improve compatibility with GCC, fix errors in FFT and -GenericMatrix, update simulated exceptions, maxima, minima, determinant, dot -product and Frobenius norm functions, update make files for CC and GCC, faster -FFT, A.ReSize(B), fix pointer arithmetic, << for loading -data into rows, IdentityMatrix, Kronecker product, sort singular values.

    -

    Newmat09 - September, 1997:

    -

    Operator ==, !=, +=, -=, -*=, /=, |=, &=. Follow new rules for -for (int i; ... ) construct. Change Boolean, TRUE, FALSE to bool, true, -false. Change ReDimension to ReSize. SubMatrix allows zero rows and columns. -Scalar +, - or * matrix is OK. Simplify simulated -exceptions. Fix non-linear programs for AT&T compilers. Dummy inequality -operators. Improve internal row/column operations. Improve matrix LU -decomposition. Improve sort. Reverse function. IsSingular function. Fast trig -transforms. Namespace definitions.

    -

    Newmat08A - July, 1995:

    -

    Fix error in SVD.

    -

    Newmat08 - January, 1995:

    -

    Corrections to improve compatibility with Gnu, Watcom. -Concatenation of matrices. Elementwise products. Option to use compilers -supporting exceptions. Correction to exception module to allow global -declarations of matrices. Fix problem with inverse of symmetric matrices. Fix -divide-by-zero problem in SVD. Include new QR routines. Sum function. -Non-linear optimisation. GenericMatrices.

    -

    Newmat07 - January, 1993

    -

    Minor corrections to improve compatibility with Zortech, -Microsoft and Gnu. Correction to exception module. Additional FFT functions. -Some minor increases in efficiency. Submatrices can now be used on RHS of =. -Option for allowing C type subscripts. Method for loading short lists of -numbers.

    -

    Newmat06 - December 1992:

    -

    Added band matrices; 'real' changed to 'Real' (to avoid -potential conflict in complex class); Inject doesn't check for no loss of -information; fixes for AT&T C++ version 3.0; real(A) becomes A.AsScalar(); -CopyToMatrix becomes AsMatrix, etc; .c() is no longer required (to be deleted -in next version); option for version 2.1 or later. Suffix for include files -changed to .h; BOOL changed to Boolean (BOOL doesn't work in g++ v 2.0); -modifications to allow for compilers that destroy temporaries very quickly; -(Gnu users - see the section of compilers). Added CleanUp, -LinearEquationSolver, primitive version of exceptions.

    -

    Newmat05 - June 1992:

    -

    For private release only

    -

    Newmat04 - December 1991:

    -

    Fix problem with G++1.40, some extra documentation -

    -

    Newmat03 - November 1991:

    -

    Col and Cols become Column and Columns. Added Sort, SVD, -Jacobi, Eigenvalues, FFT, real conversion of 1x1 matrix, Numerical Recipes -in C interface, output operations, various scalar functions. Improved -return from functions. Reorganised setting options in "include.hxx". -

    -

    Newmat02 - July 1991:

    -

    Version with matrix row/column operations and numerous -additional functions.

    -

    Matrix - October 1990:

    -

    Early version of package.

    - -

     

    -

    8. Problem report form -

    - -

    next - skip - up - -start

    - -

    Copy and paste this to your editor; fill it out and email to robert at statsresearch.co.nz

    -

    But first look in my web page -http://www.robertnz.net to see if the bug has -already been reported.

    -
     Version: ............... newmat11 (20 November 2008)
    +
    + +

    + which is more complicated and consequently introduces more chance of + error. +

    +

    5.12 Error handling

    +

    + next - skip - + up - start +

    +

    + The library now does have a moderately graceful exit from errors. One can + use either the simulated exceptions or the compiler supported exceptions. + When newmat08 was released (in 1995), compiler exception handling in the + compilers I had access to was unreliable. I recommended you used my + simulated exceptions. In 1997 compiler supported exceptions seemed to work + on a variety of compilers - but not all compilers. This was still true in + 2001. One compiler company was still having problems in 2003 (not sure + about 2004). Try using the compiler supported exceptions if you have a + recent compiler, but if you are getting strange crashes or errors try + going back to my simulated exceptions. +

    +

    + The approach in the present library, attempting to simulate C++ + exceptions, is not completely satisfactory, but seems a good interim + solution for those who cannot use compiler supported exceptions. People + who don't want exceptions in any shape or form, can set the option to exit + the program if an exception is thrown. +

    +

    + The exception mechanism cannot clean-up objects explicitly created by new. + This must be explicitly carried out by the package writer or the package + user. I have not yet done this completely with the present package so + occasionally a little garbage may be left behind after an exception. I + don't think this is a big problem, but it is one that needs fixing. +

    +

    5.13 Sparse matrices

    +

    + next - skip - + up - start +

    +

    The library does not support sparse matrices.

    +

    + For sparse matrices there is going to be some kind of structure vector. It + is going to have to be calculated for the results of expressions in much + the same way that types are calculated. In addition, a whole new set of + row and column operations would have to be written. +

    +

    + Sparse matrices are important for people solving large sets of + differential equations as well as being important for statistical and + operational research applications. +

    +

    + But there are packages being developed specifically for sparse matrices + and these might present the best approach, at least where sparse matrices + are the main interest. +

    +

    5.14 Complex matrices

    +

    + next - skip - + up - start +

    +

    + The package does not yet support matrices with complex elements. There are + at least two approaches to including these. One is to have matrices with + complex elements. +

    +

    + This probably means making new versions of the basic row and column + operations for Real*Complex, Complex*Complex, Complex*Real and similarly + for + and -. This would be OK, except that if I also + want to do this for sparse matrices, then when you put these together, the + whole thing will get out of hand. +

    +

    + The alternative is to represent a Complex matrix by a pair of Real + matrices. One probably needs another level of decoding expressions but I + think it might still be simpler than the first approach. But there is + going to be a problem with accessing elements and it does not seem + possible to solve this in an entirely satisfactory way. +

    +

    + Complex matrices are used extensively by electrical engineers and + physicists and really should be fully supported in a comprehensive + package. +

    +

    + You can simulate most complex operations by representing + Z = X + iY by +

    +
    +    /  X   Y \
    +    \ -Y   X /
    +
    + +

    + Most matrix operations will simulate the corresponding complex operation, + when applied to this matrix. But, of course, this matrix is essentially + twice as big as you would need with a genuine complex matrix library. +

    + +

     

    + +

    6. Function summary

    + +

    + next - skip - + up - start +

    + +

    + 6.1 Member functions for matrices and matrix expressions
    + 6.2 Member functions for matrices
    + 6.3 Operators
    + 6.3 Global functions - newmat.h
    + 6.4 Global functions - newmatap.h
    + 6.5 Other classes - member functions +

    + +

    + This section lists member and global functions for matrices defined in + newmat.h. Where there are alternative names the lower-case + non-capitalised versions are the preferred ones. +

    + +

    + 6.1 Member functions for matrices and + matrix expressions +

    +

    + next - + skip - up - + start +

    +

    + Member functions for matrices and matrix expressions. These do not apply + to CroutMatrix and BandLUMatrix unless explicitly noted. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    + Unary operators +

    (see also operators)

    +
    .t()matrix transpose
    + .reverse()
    + .Reverse() +
    reverse order of elements (not band matrices)
    .i() + invert matrix or solve (also works with CroutMatrix and BandLUMatrix) +
    .sum_rows()sum elements in each row
    .sum_columns()sum elements in each column
    .sum_square_rows()sum squares of elements in each row
    .sum_square_columns()sum squares of elements in each column
    Change type + .as_row()
    + .AsRow() +
    interpret matrix body as a single row
    + .as_column()
    + .AsColumn() +
    interpret matrix body as a single column
    + .as_diagonal()
    + .AsDiagonal() +
    interpret matrix body as a diagonal matrix
    + .as_matrix()
    + .AsMatrix() +
    interpret matrix body as a rectangular matrix
    + .as_scalar()
    + .AsScalar() +
    convert 1x1 to Real
    Submatrices + .submatrix(int,int,int,int)
    + .SubMatrix(int,int,int,int) +
    submatrix
    + .sym_submatrix(int,int)
    + .SymSubMatrix(int,int) +
    submatrix with same row and column range
    + .row(int)
    + .Row(int) +
    select a row of a matrix
    + .rows(int,int)
    + .Rows(int,int) +
    select a range of rows of a matrix
    + .column(int)
    + .Column(int,int) +
    select a column of a matrix
    + .columns(int)
    + .Columns(int,int) +
    select a range of columns of a matrix
    + Scalar functions - maxima & minima +

    + (also global versions of maximum(), minimum(),  + maximum_absolute_value(), mimimum_absolute_value()) +

    +
    + .maximum_absolute_value()
    + .
    MaximumAbsoluteValue() +
    maximum absolute value of elements
    + .maximum_absolute_value1(int&)
    + .MaximumAbsoluteValue1(int&) +
    maximum absolute value, return location
    + .maximum_absolute_value2(int&,int&)
    + .MaximumAbsoluteValue2(int&,int&) +
    maximum absolute value, return location
    + .minimum_absolute_value()
    + .MinimumAbsoluteValue() +
    minimum absolute value of elements
    + .minimum_absolute_value1(int&)
    + .MinimumAbsoluteValue1(int&) +
    minimum absolute value, return location
    + .minimum_absolute_value2(int&,int&)
    + .MinimumAbsoluteValue2(int&,int&) +
    minimum absolute value, return location
    + .maximum()
    + .Maximum() +
    maximum value of elements
    + .maximum1(int&)
    + .Maximum1(int&) +
    maximum value, return location
    + .maximum2(int&,int&)
    + .Maximum2(int&,int&) +
    maximum value, return location
    + .minimum()
    + .Minimum() +
    minimum value of elements
    + .minimum1(int&)
    + .Minimum1(int&) +
    minimum value, return location
    + .minimum2(int&,int&)
    + .Minimum2(int&,int&) +
    minimum value, return location
    + Scalar functions - numerical +

    (also global versions of these functions)

    +
    + .log_determinant()
    + .LogDeterminant() +
    + natural logarithm of the determinant (also works with CroutMatrix and + BandLUMatrix) +
    + .determinant()
    + .Determinant() +
    + determinant (also works with CroutMatrix and BandLUMatrix) +
    + .sum_square()
    + .SumSquare() +
    sum of squares of elements
    + .norm_Frobenius()
    + .norm_frobenius()
    + .NormFrobenius() +
    square root of sum of squares of elements
    + .sum_absolute_value()
    + .SumAbsoluteValue() +
    sum of absolute values of elements
    + .sum()
    + .Sum() +
    sum of elements
    + .trace()
    + .Trace() +
    trace of a matrix
    + .norm1()
    + .Norm1() +
    + maximum of sum of absolute values of elements of a column +
    + .norm_infinity()
    + .NormInfinity() +
    + maximum of sum of absolute values of elements of a row +
    + Scalar functions - size and shape + + .bandwidth()
    + .BandWidth() +
    + bandwidth of matrix (also works with CroutMatrix and BandLUMatrix) +
    +

     

    +

    6.2 Member functions for matrices

    +

    + next - skip - + up - start +

    +

    + Member functions for matrices but not matrix expressions. These do not + apply to CroutMatrix and BandLUMatrix unless explicitly noted. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    + Element access +

    (see also operators)

    +
    .element(int,int)access element - subscripts start at 0
    .element(int)access element - subscripts start at 0
    Copying + .inject(const GeneralMatrix&)
    + .Inject(const GeneralMatrix&) +
    copy elements into a matrix
    .swap(Matrix&) + swap bodies of two matrices of same type (also global version, also + works with CroutMatrix and BandLUMatrix) +
    + Scalar functions - size and shape +

    (also work with CroutMatrix and BandLUMatrix)

    +
    + .type()
    + .Type() +
    type of a matrix
    + .nrows()
    + .Nrows() +
    number of rows
    + .ncols()
    + .Ncols() +
    number of columns
    + .size()
    + .Storage() +
    + number of stored elements (including unused elements in band matrices) +
    .size2()size of second array (BandLUMatrix only)
    + .data()
    + .Store() +
    pointer to stored elements
    .const_data()constant pointer to stored elements
    .const_data2() + constant pointer to second array (BandLUMatrix only) +
    .const_data_indx() + constant pointer to row swap array (CroutMatrix and BandLUMatrix only) +
    + Scalar functions - numerical + + .is_zero()
    + .IsZero() +
    + test all elements are exactly zero (also global version) +
    + .is_singular()
    + .IsSingular() +
    + test for exact singularity (CroutMatrix and BandLUMatrix only) +
    .even_exchanges() + true if there have been an even number of row exchanges (CroutMatrix + and BandLUMatrix only) +
    Memory management + .release()
    + .Release() +
    release memory after next operation
    + .release(int)
    + .Release(int) +
    release memory after specified number of operations
    + .release_and_delete()
    + .ReleaseAndDelete() +
    delete after next operation
    + .for_return()
    + .ForReturn() +
    + place in an envelope for efficient return from a function +
    Change dimensions + .resize(int)
    + .ReSize(int) +
    change the dimensions (vectors and square matrices)
    + .resize(int,int)
    + .ReSize(int,int) +
    + change the dimensions (non-square matrices, triangular band matrices + and symmetric band matrices) +
    + .resize(int,int,int)
    + .ReSize(int,int,int) +
    change the dimensions (band matrices)
    + .resize(const GeneralMatrix&)
    + .ReSize(const GeneralMatrix&) +
    change dimensions to match those of another matrix
    + .cleanup()
    + .CleanUp() +
    resize to 0x0
    .resize_keep(int) + change the dimensions, keep values (vectors and square matrices, not + band) +
    .resize_keep(int,int) + change the dimensions , keep values (non-square matrices) +
    +

     

    +

    6.3 Operators

    +

    + next - + skip - up - + start +

    +

    + Operators for matrices and matrix expressions. These do not apply to + CroutMatrix and BandLUMatrix unless explicitly noted. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    + Element access +

    (matrices only, not functions of a matrix)

    +
    ()access element - subscripts start at 1
    ()access element - subscripts start at 1
    [] + access element C style - subscripts start at zero; if + SETUP_C_SUBSCRIPTS is defined. +
    Unary operators-change sign of elements
    Binary operators+, +=add matrices
    -, -=subtract matrices
    *, *=matrix multiplication
    |, |=horizontal concatenation
    &, &=vertical stacking
    == + test for exact equality (also works with CroutMatrix and + BandLUMatrix) +
    != + test for inequality (i.e. not exact equality, also works with + CroutMatrix and BandLUMatrix) +
    + Matrix and scalar + +, +=add Real to matrix
    -, -= + subtract Real from matrix; subtract matrix from Real +
    *, *=multiply matrix by Real
    /, /=divide matrix by Real
    Copying= + copy matrix (error if there is loss of data,  also works + with CroutMatrix and BandLUMatrix) +
    =copy Real to all elements
    <<copy matrix (no error if there is loss of data)
    Enter values<<enter list of values into matrix
    + Output +

    (header in newmatio.h)

    +
    <<print matrix to file
    +

     

    + +

    6.4 Global functions - newmat.h

    +

    + next - + skip - up - + start +

    +

    + Operators for matrices and matrix expressions. These do not apply to + CroutMatrix and BandLUMatrix. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    + Binary operators +

    (see also operators)

    +
    + SP(const BaseMatrix&, const BaseMatrix&) + element-wise product of two matrices
    + KP(const BaseMatrix&, const BaseMatrix&) + Kronecker product of two matrices
    + crossproduct(const Matrix&, const Matrix&)
    + CrossProduct(const Matrix&, const Matrix&) +
    + cross product of two 3x1 or 1x3 matrices or vectors. +
    + crossproduct_rows(const Matrix&, const Matrix&)
    + CrossProductRows(const Matrix&, const Matrix&) +
    row-wise cross product
    + crossproduct_columns(const Matrix&, const Matrix&)
    + CrossProductColumns(const Matrix&, const Matrix&) +
    column-wise cross product
    Scalar functions - numerical + dotproduct(const Matrix&, const Matrix&)
    DotProduct(const Matrix&, const Matrix&) +
    dot product of two vectors
    + +

     

    + +

    6.5 Global functions - newmatap.h

    +

    + next - skip - + up - start +

    + +

    + Advanced operators for matrices and matrix expressions. These do not apply + to CroutMatrix and BandLUMatrix. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    + QR transform + + QRZT(Matrix&, LowerTriangularMatrix&) + transposed version of QRZ transform
    + QRZT(const Matrix&, Matrix&, Matrix&) + + transposed version of QRZ transform - solve part +
    + QRZT(Matrix&, Matrix&, LowerTriangularMatrix&, + Matrix&) + both of previous two lines
    + QRZ(Matrix&, UpperTriangularMatrix&) + QRZ transform
    + QRZ(const Matrix&, Matrix&, Matrix&) + QRZ transform - solve part
    + QRZ(Matrix&, Matrix&, UpperTriangularMatrix&, + Matrix&) + both of previous two lines
    + updateQRZT(Matrix&, LowerTriangularMatrix&)
    + UpdateQRZT(Matrix&, LowerTriangularMatrix&) +
    + add extra columns to transposed version of QRZ transform +
    + updateQRZ(Matrix&, UpperTriangularMatrix&)
    + UpdateQRZ(Matrix&, UpperTriangularMatrix&) +
    add extra rows to QRZ transform
    + updateQRZ(const Matrix&, Matrix&, Matrix&)
    + UpdateQRZ(const Matrix&, Matrix&, Matrix&) +
    + combine the results of the solve parts of QRZ transforms on two blocks + of data +
    + updateQRZ(UpperTriangularMatrix&, + UpperTriangularMatrix&)
    + UpdateQRZ(UpperTriangularMatrix&, UpperTriangularMatrix&) +
    + combine the results of QRZ transforms on two blocks of data +
    + updateQRZ(const UpperTriangularMatrix&, Matrix&, + Matrix&)
    + UpdateQRZ(const UpperTriangularMatrix&, Matrix&, Matrix&) +
    + combine the results of the solve parts of QRZ transforms on two blocks + of data +
    + Extend orthonormal set + + extend_orthonormal(Matrix&, int) + extend a set of orthonormal columns
    + Cholesky decomposition + + Cholesky(const SymmetricMatrix&) + + Cholesky decomposition of symmetric matrix +
    + Cholesky(const SymmetricBandMatrix&) + + Cholesky decomposition of symmetric band matrix +
    + Update Cholesky decomposition + + update_Cholesky (UpperTriangularMatrix&, RowVector)
    + UpdateCholesky (UpperTriangularMatrix&, RowVector) +
    + add extra row to Cholesky/QR decomposition +
    + downdate_Cholesky (UpperTriangularMatrix&, RowVector)
    + DowndateCholesky (UpperTriangularMatrix&, RowVector) +
    + remove row from Cholesky/QR decomposition +
    + right_circular_update_Cholesky (UpperTriangularMatrix&, + int, int)
    + RightCircularUpdateCholesky (UpperTriangularMatrix&, int, + int) +
    + rearrange columns in Cholesky/QR decomposition +
    + left_circular_update_Cholesky (UpperTriangularMatrix&, int, + int)
    + LeftCircularUpdateCholesky (UpperTriangularMatrix&, int, + int) +
    + rearrange columns in Cholesky/QR decomposition +
    + Singular value decomposition + + SVD(const Matrix&, DiagonalMatrix&, Matrix&, + Matrix&, bool, bool) + + singular value decomposition - get U and V +
    + SVD(const Matrix&, DiagonalMatrix&) + + SVD decomposition - get just singular values +
    + SVD(const Matrix& A, DiagonalMatrix& D, Matrix&, + bool) + SVD decomposition - get U
    + Eigenvalue decomposition of a symmetric matrix + + Jacobi(const SymmetricMatrix&, DiagonalMatrix&) + + Jacobi eigenvalue decomposition - get only eigenvalues +
    + Jacobi(const SymmetricMatrix&, DiagonalMatrix&, + SymmetricMatrix&) + + Jacobi eigenvalue decomposition - get only eigenvalues +
    + Jacobi(const SymmetricMatrix&, DiagonalMatrix&, + Matrix&) + + Jacobi eigenvalue decomposition - get eigenvalues and eigenvectors +
    + Jacobi(const SymmetricMatrix&, DiagonalMatrix&, + SymmetricMatrix&, Matrix&, bool) + + Jacobi eigenvalue decomposition - get eigenvalues and eigenvectors +
    + eigenvalues(const SymmetricMatrix&, DiagonalMatrix&)
    + EigenValues(const SymmetricMatrix&, DiagonalMatrix&) +
    + Householder eigenvalue decomposition - get only eigenvalues +
    + eigenvalues(const SymmetricMatrix&, DiagonalMatrix&, + SymmetricMatrix&)
    + EigenValues(const SymmetricMatrix&, DiagonalMatrix&, + SymmetricMatrix&) +
    + Householder eigenvalue decomposition with back transform - get only + eigenvalues +
    + eigenvalues(const SymmetricMatrix&, DiagonalMatrix&, + Matrix&)
    + EigenValues(const SymmetricMatrix&, DiagonalMatrix&, + Matrix&) +
    + Householder eigenvalue decomposition - get eigenvalues and + eigenvectors +
    + Sorting + + sort_ascending(GeneralMatrix&)
    + SortAscending(GeneralMatrix&) +
    ascending sort
    + sort_descending(GeneralMatrix&)
    + SortDescending(GeneralMatrix&) +
    descending sort
    + Fast Fourier transform + + FFT(const ColumnVector&, const ColumnVector&, + ColumnVector&, ColumnVector&) + fast Fourier transform
    + FFTI(const ColumnVector&, const ColumnVector&, + ColumnVector&, ColumnVector&) + fast Fourier transform - inverse
    + RealFFT(const ColumnVector&, ColumnVector&, + ColumnVector&) + FFT of real vector
    + RealFFTI(const ColumnVector&, const ColumnVector&, + ColumnVector&) + FFT of real vector - inverse
    + FFT2(const Matrix& U, const Matrix& V, Matrix& X, + Matrix& Y) + two dimensional FFT
    + FFT2I(const Matrix& U, const Matrix& V, Matrix& X, + Matrix& Y) + two dimensional FFT - inverse
    + Fast trigonometric transform + + DCT_II(const ColumnVector&, ColumnVector&) + type II discrete cosine transform
    + DCT_II_inverse(const ColumnVector&, ColumnVector&) + + type II discrete cosine transform - inverse +
    + DST_II(const ColumnVector&, ColumnVector&) + type II discrete sine transform
    + DST_II_inverse(const ColumnVector&, ColumnVector&) + + type II discrete sine transform - inverse +
    + DCT(const ColumnVector&, ColumnVector&) + discrete cosine transform
    + DCT_inverse(const ColumnVector&, ColumnVector&) + discrete cosine transform - inverse
    + DST(const ColumnVector&, ColumnVector&) + discrete sine transform
    + DST_inverse(const ColumnVector&, ColumnVector&) + discrete sine transform - inverse
    + Helmert transform + Helmert(int, bool=false)return Helmert transform matrix
    + Helmert(const ColumnVector&, bool=false)
    + Helmert(const Matrix&, bool=false) +
    multiply by Helmert transform matrix
    Helmert(int, int, bool=false) + return column of Helmert transform matrix +
    + Helmert_transpose(const ColumnVector&, bool=false)
    + Helmert_transpose(const Matrix&, bool=false) +
    + multiply by transpose of Helmert transform matrix +
    + Helmert_transpose(const ColumnVector&, int, bool=false) + + multiply by transpose of Helmert transform matrix, return one element + of result +
    + +

     

    +

    6.6 Other classes - member functions

    +

    + next - skip - + up - start +

    + +

     

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Classfunction namedescription
    + LogAndSign + + .pow_eq(int)
    + .PowEq(int) +
    raise to a power
    + .change_sign()
    + .ChangeSign() +
    change sign
    + .log_value()
    + .LogValue() +
    + return the natural logarithm of the value +
    + .sign()
    + .Sign() +
    return the sign
    + .value()
    + .Value() +
    return the value (no log transform)
    + MatrixType + + .value()
    + .Value() +
    return the value (as character string)
    .is_diagonal()has diagonal attribute
    .is_symmetric()has symmetric attribute
    .is_band()has band attribute
    + MatrixBandWidth + + .upper()
    + .Upper() +
    return upper band width
    + .lower()
    + .Lower() +
    return lower bandwidth
    + SimpleIntArray + + .size()
    + .Size() +
    return size of array
    + .data()
    + .Data() +
    return a pointer to the data
    .const_data()return a constant pointer to the data
    + .resize()
    + .Resize() +
    change the size of an array
    + .resize_keep()
    + .resize(true)
    + .Resize(true) +
    + change the size of an array - keep the values +
    + .cleanup()
    + .CleanUp() +
    resize to zero
    + +

     

    + +

    7. Change history

    +

    + next - skip - + up - start +

    +

    Newmat11 - November, 2008:

    +

    + Remove work-arounds for older compilers, Borland Builder 6 and Open Watcom + compatibility, SquareMatrix, load from array of ints, crossproducts, + Cholesky and QRZ update functions, swap functions, FFT2, access to arrays + in traditional C functions, SimpleIntArray class, compatibility with + Numerical Recipes in C++, sum_rows(), sum_columns(), sum_squares_rows() + and sum_squares_columns() functions, extend_orthogonal function, + resize_keep function, speed-ups and bug-fixes, change to lower case for + functions, can copy CroutMatrix, BandLUMatrix, Helmert transform, + compatibility fix for G++ 4.1, start inserting comments for Doxygen, + SP_eq, scientific format for output, fix for 64 bits. +

    +

    Newmat10A - October, 2002, Newmat10B - January 2005:

    +

    + Fix error in Kronecker product; fixes for Intel and GCC3 compilers. +

    +

    Newmat10 - January, 2002:

    +

    + Improve compatibility with GCC, fix errors in FFT and GenericMatrix, + update simulated exceptions, maxima, minima, determinant, dot product and + Frobenius norm functions, update make files for CC and GCC, faster FFT, + A.ReSize(B), fix pointer arithmetic, << for + loading data into rows, IdentityMatrix, Kronecker product, sort singular + values. +

    +

    Newmat09 - September, 1997:

    +

    + Operator ==, !=, +=, -=, *=, + /=, |=, &=. Follow new rules for + for (int i; ... ) construct. Change Boolean, TRUE, FALSE to bool, + true, false. Change ReDimension to ReSize. SubMatrix allows zero rows and + columns. Scalar +, - or * matrix is OK. + Simplify simulated exceptions. Fix non-linear programs for AT&T + compilers. Dummy inequality operators. Improve internal row/column + operations. Improve matrix LU decomposition. Improve sort. Reverse + function. IsSingular function. Fast trig transforms. Namespace + definitions. +

    +

    Newmat08A - July, 1995:

    +

    Fix error in SVD.

    +

    Newmat08 - January, 1995:

    +

    + Corrections to improve compatibility with Gnu, Watcom. Concatenation of + matrices. Elementwise products. Option to use compilers supporting + exceptions. Correction to exception module to allow global declarations of + matrices. Fix problem with inverse of symmetric matrices. Fix + divide-by-zero problem in SVD. Include new QR routines. Sum function. + Non-linear optimisation. GenericMatrices. +

    +

    Newmat07 - January, 1993

    +

    + Minor corrections to improve compatibility with Zortech, Microsoft and + Gnu. Correction to exception module. Additional FFT functions. Some minor + increases in efficiency. Submatrices can now be used on RHS of =. Option + for allowing C type subscripts. Method for loading short lists of numbers. +

    +

    Newmat06 - December 1992:

    +

    + Added band matrices; 'real' changed to 'Real' (to avoid potential conflict + in complex class); Inject doesn't check for no loss of information; fixes + for AT&T C++ version 3.0; real(A) becomes A.AsScalar(); CopyToMatrix + becomes AsMatrix, etc; .c() is no longer required (to be deleted in next + version); option for version 2.1 or later. Suffix for include files + changed to .h; BOOL changed to Boolean (BOOL doesn't work in g++ v 2.0); + modifications to allow for compilers that destroy temporaries very + quickly; (Gnu users - see the section of compilers). Added CleanUp, + LinearEquationSolver, primitive version of exceptions. +

    +

    Newmat05 - June 1992:

    +

    For private release only

    +

    Newmat04 - December 1991:

    +

    Fix problem with G++1.40, some extra documentation

    +

    Newmat03 - November 1991:

    +

    + Col and Cols become Column and Columns. Added Sort, SVD, Jacobi, + Eigenvalues, FFT, real conversion of 1x1 matrix, + Numerical Recipes in C interface, output operations, various scalar + functions. Improved return from functions. Reorganised setting options in + "include.hxx". +

    +

    Newmat02 - July 1991:

    +

    + Version with matrix row/column operations and numerous additional + functions. +

    +

    Matrix - October 1990:

    +

    Early version of package.

    + +

     

    +

    8. Problem report form

    + +

    + next - skip - + up - start +

    + +

    + Copy and paste this to your editor; fill it out and email to robert + at statsresearch.co.nz +

    +

    + But first look in my web page + http://www.robertnz.net to see if + the bug has already been reported. +

    +
    + Version: ............... newmat11 (20 November 2008)
      Your email address: ....
      Today's date: ..........
      Your machine: ..........
    @@ -5124,22 +7063,25 @@ 

    8. Problem report form -

    - -
    -----------------------------------------------------------
    -
    +
    -

     

    +
    +-----------------------------------------------------------
    +
    -

     

    -

    return to top
    -return to online documentation page

    -

     

    -

     

    -

     

    -

     

    -

     

    -

     

    -

     

    - - \ No newline at end of file +

     

    + +

     

    +

    + return to top
    + return to online documentation page +

    +

     

    +

     

    +

     

    +

     

    +

     

    +

     

    +

     

    + + diff --git a/extern/newmat/nm_b55.mak b/extern/newmat/nm_b55.mak index c7c4503..98911c2 100644 --- a/extern/newmat/nm_b55.mak +++ b/extern/newmat/nm_b55.mak @@ -14,7 +14,7 @@ CC = bcc32 -W- -v- -H- -3 -N -Og -Oi -Ov -f -I$(INCLUDEPATH) .cpp.obj: $(CC) -c {$< } -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -231,4 +231,3 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_b56.mak b/extern/newmat/nm_b56.mak index 8414f19..0a372d3 100644 --- a/extern/newmat/nm_b56.mak +++ b/extern/newmat/nm_b56.mak @@ -14,7 +14,7 @@ CC = bcc32 -W- -v- -H- -6 -Og -Oi -Ov -I$(INCLUDEPATH) .cpp.obj: $(CC) -c {$< } -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -231,4 +231,3 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_cc.mak b/extern/newmat/nm_cc.mak index cb3a735..84e7800 100644 --- a/extern/newmat/nm_cc.mak +++ b/extern/newmat/nm_cc.mak @@ -10,11 +10,11 @@ PRE = ./ .cpp.o: rm -f $*.cxx - ln $*.cpp $*.cxx + ln $*.cpp $*.cxx $(CXX) $(CXXFLAGS) -c $*.cxx - rm $*.cxx + rm $*.cxx -everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch +everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch newmat_lobj = newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o newmat6.o newmat7.o newmat8.o newmatex.o bandmat.o submat.o myexcept.o cholesky.o evalue.o fft.o hholder.o jacobi.o newfft.o sort.o svd.o nm_misc.o newmatrm.o newmat9.o @@ -214,4 +214,3 @@ sl_ex.txx: sl_ex garch.txx: garch $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_ex1.cpp b/extern/newmat/nm_ex1.cpp index 05bb45c..28b7d66 100644 --- a/extern/newmat/nm_ex1.cpp +++ b/extern/newmat/nm_ex1.cpp @@ -11,7 +11,7 @@ // should not be required for this example // included because it seems to help MS VC6 // when you have namespace turned on - + #include "newmatio.h" // newmat headers including output functions #ifdef use_namespace @@ -25,7 +25,7 @@ int my_main() // called by main() // declare a matrix Matrix X(4,4); - + // load values row by row X.row(1) << 3.7 << -2.1 << 7.4 << -1.0; X.row(2) << 4.1 << 0.0 << 3.9 << 4.0; @@ -35,16 +35,16 @@ int my_main() // called by main() // print the matrix cout << "Matrix X" << endl; cout << setw(15) << setprecision(8) << X << endl; - + // calculate its inverse and print it Matrix Y = X.i(); cout << "Inverse of X" << endl; cout << setw(15) << setprecision(8) << Y << endl; - + // multiply X by its inverse and print the result (should be near identity) cout << "X * inverse of X" << endl; cout << setw(15) << setprecision(8) << (X * Y) << endl; - + return 0; } @@ -60,4 +60,3 @@ int main() } ///@} - diff --git a/extern/newmat/nm_ex1.txt b/extern/newmat/nm_ex1.txt index 53eab14..1ba448a 100644 --- a/extern/newmat/nm_ex1.txt +++ b/extern/newmat/nm_ex1.txt @@ -1,18 +1,17 @@ Matrix X - 3.70000000 -2.10000000 7.40000000 -1.00000000 - 4.10000000 0.00000000 3.90000000 4.00000000 - -2.50000000 1.90000000 -0.40000000 7.30000000 - 1.50000000 9.80000000 -2.10000000 1.10000000 + 3.70000000 -2.10000000 7.40000000 -1.00000000 + 4.10000000 0.00000000 3.90000000 4.00000000 + -2.50000000 1.90000000 -0.40000000 7.30000000 + 1.50000000 9.80000000 -2.10000000 1.10000000 Inverse of X - -0.15613535 0.27856000 -0.17406776 0.00029026 - 0.07956310 -0.08691703 0.04180094 0.11098579 - 0.22744144 -0.14910111 0.10868682 0.02766552 - -0.06171667 0.10984958 0.07244980 -0.02727139 + -0.15613535 0.27856000 -0.17406776 0.00029026 + 0.07956310 -0.08691703 0.04180094 0.11098579 + 0.22744144 -0.14910111 0.10868682 0.02766552 + -0.06171667 0.10984958 0.07244980 -0.02727139 X * inverse of X - 1.00000000 -0.00000000 0.00000000 0.00000000 - 0.00000000 1.00000000 0.00000000 0.00000000 - -0.00000000 -0.00000000 1.00000000 -0.00000000 - -0.00000000 0.00000000 0.00000000 1.00000000 - + 1.00000000 -0.00000000 0.00000000 0.00000000 + 0.00000000 1.00000000 0.00000000 0.00000000 + -0.00000000 -0.00000000 1.00000000 -0.00000000 + -0.00000000 0.00000000 0.00000000 1.00000000 diff --git a/extern/newmat/nm_ex2.cpp b/extern/newmat/nm_ex2.cpp index d0887a8..339e822 100644 --- a/extern/newmat/nm_ex2.cpp +++ b/extern/newmat/nm_ex2.cpp @@ -12,7 +12,7 @@ /// /// The dimensions of this matrix are not large enough for there to be numerical /// problems but we will be able to see that wide range of values of the -/// eigenvalues. +/// eigenvalues. #define WANT_STREAM // include iostream and iomanipulators @@ -27,13 +27,13 @@ using namespace RBD_LIBRARIES; int my_main() // called by main() { Tracer tr("my_main "); // for tracking exceptions - + int n = 7; // this is the order we will work with int i, j; // declare a matrix SymmetricMatrix H(n); - + // load values for Hilbert matrix for (i = 1; i <= n; ++i) for (j = 1; j <= i; ++j) H(i, j) = 1.0 / (i + j - 1); @@ -41,7 +41,7 @@ int my_main() // called by main() // print the matrix cout << "SymmetricMatrix H" << endl; cout << setw(10) << setprecision(7) << H << endl; - + // calculate its eigenvalues and eigenvectors and print them Matrix U; DiagonalMatrix D; eigenvalues(H, D, U); @@ -51,13 +51,13 @@ int my_main() // called by main() cout << setw(10) << setprecision(7) << U << endl; // check orthogonality - cout << "U * U.t() (should be near identity)" << endl; + cout << "U * U.t() (should be near identity)" << endl; cout << setw(10) << setprecision(7) << (U * U.t()) << endl; - + // check decomposition - cout << "U * D * U.t() (should be near H)" << endl; + cout << "U * D * U.t() (should be near H)" << endl; cout << setw(10) << setprecision(7) << (U * D * U.t()) << endl; - + return 0; } diff --git a/extern/newmat/nm_ex2.txt b/extern/newmat/nm_ex2.txt index fb98822..ed50a87 100644 --- a/extern/newmat/nm_ex2.txt +++ b/extern/newmat/nm_ex2.txt @@ -1,45 +1,44 @@ SymmetricMatrix H - 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 - 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 - 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 - 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 - 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 - 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 - 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 + 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 + 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 + 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 + 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 + 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 + 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 + 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 Eigenvalues of H - 0.00000000349390 - 0.00000048567634 - 0.00002938636815 - 0.00100858761077 - 0.02128975490833 - 0.27192019814935 - 1.66088533892693 + 0.00000000349390 + 0.00000048567634 + 0.00002938636815 + 0.00100858761077 + 0.02128975490833 + 0.27192019814935 + 1.66088533892693 Eigenvector matrix, U - 0.0002451 -0.0024687 0.0159939 -0.0751873 0.2608426 0.6232385 -0.7332256 --0.0098386 0.0617968 -0.2279023 0.5267775 -0.6705585 -0.1630715 -0.4363592 - 0.0951956 -0.3486749 0.6287534 -0.4256562 -0.2953295 -0.3215141 -0.3197791 --0.3713200 0.6446867 -0.2003656 -0.4616761 0.0230466 -0.3573674 -0.2548856 - 0.6825295 -0.1743885 -0.4970150 -0.1711955 0.2336876 -0.3570683 -0.2128441 --0.5910349 -0.5436283 -0.1848709 0.1826645 0.3678759 -0.3445700 -0.1831431 - 0.1944058 0.3647422 0.4807560 0.5097549 0.4523486 -0.3281347 -0.1609397 + 0.0002451 -0.0024687 0.0159939 -0.0751873 0.2608426 0.6232385 -0.7332256 +-0.0098386 0.0617968 -0.2279023 0.5267775 -0.6705585 -0.1630715 -0.4363592 + 0.0951956 -0.3486749 0.6287534 -0.4256562 -0.2953295 -0.3215141 -0.3197791 +-0.3713200 0.6446867 -0.2003656 -0.4616761 0.0230466 -0.3573674 -0.2548856 + 0.6825295 -0.1743885 -0.4970150 -0.1711955 0.2336876 -0.3570683 -0.2128441 +-0.5910349 -0.5436283 -0.1848709 0.1826645 0.3678759 -0.3445700 -0.1831431 + 0.1944058 0.3647422 0.4807560 0.5097549 0.4523486 -0.3281347 -0.1609397 U * U.t() (should be near identity) - 1.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 -0.0000000 0.0000000 --0.0000000 1.0000000 0.0000000 -0.0000000 -0.0000000 -0.0000000 0.0000000 --0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 -0.0000000 -0.0000000 - 0.0000000 -0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 --0.0000000 -0.0000000 0.0000000 0.0000000 1.0000000 -0.0000000 0.0000000 --0.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 1.0000000 0.0000000 - 0.0000000 0.0000000 -0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 + 1.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 -0.0000000 0.0000000 +-0.0000000 1.0000000 0.0000000 -0.0000000 -0.0000000 -0.0000000 0.0000000 +-0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 -0.0000000 -0.0000000 + 0.0000000 -0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 +-0.0000000 -0.0000000 0.0000000 0.0000000 1.0000000 -0.0000000 0.0000000 +-0.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 1.0000000 0.0000000 + 0.0000000 0.0000000 -0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 U * D * U.t() (should be near H) - 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 - 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 - 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 - 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 - 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 - 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 - 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 - + 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 + 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 + 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 + 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 + 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 + 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 + 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 diff --git a/extern/newmat/nm_ex3.cpp b/extern/newmat/nm_ex3.cpp index 8c3309f..a5fb9ed 100644 --- a/extern/newmat/nm_ex3.cpp +++ b/extern/newmat/nm_ex3.cpp @@ -28,24 +28,24 @@ int my_main() // called by main() cout << "Minimum " << FloatingPointPrecision::Minimum() << endl; cout << "LnMinimum " << FloatingPointPrecision::LnMinimum() << endl; cout << endl; - + ColumnVector values(5), sel_values(4); - + values(1) = sel_values(1) = FloatingPointPrecision::Epsilon(); values(2) = FloatingPointPrecision::Maximum(); values(3) = sel_values(2) = FloatingPointPrecision::LnMaximum(); values(4) = sel_values(3) = FloatingPointPrecision::Minimum(); values(5) = sel_values(4) = FloatingPointPrecision::LnMinimum(); - + cout << "Load values into a ColumnVector and print in scientific format" << endl << endl; cout << "Values in scientific format" << endl; cout << setw(15) << setprecision(5) << scientific << values << endl; - + cout << "Print in fixed format" << endl << endl; cout << "Selected values in fixed format (omit Maximum)" << endl; cout << setw(15) << setprecision(5) << fixed << sel_values << endl; - + cout << "Test Epsilon" << endl << endl; Real x = 1.0 + FloatingPointPrecision::Epsilon(); cout << "This value should be non-zero" << endl; @@ -56,7 +56,7 @@ int my_main() // called by main() cout << "(1.0 + Epsilon / 2) - 1.0" << setw(15) << setprecision(5) << scientific << (Real)(x - 1.0) << endl; cout << endl; - + cout << "Test Minimum" << endl << endl; cout << "This value should be non-zero" << endl; cout << "Minimum " << setw(15) << setprecision(5) << @@ -70,11 +70,11 @@ int my_main() // called by main() cout << "Minimum * Epsilon / 2.0 " << setw(15) << setprecision(5) << scientific << x << endl; cout << endl; - + cout << "Test LnMaximum and LnMinimum" << endl << endl; x = exp(FloatingPointPrecision::LnMaximum()); cout << "This should print a value close to Maximum" << endl; - cout << "Fails with some compilers - needs fixing" << endl; + cout << "Fails with some compilers - needs fixing" << endl; cout << "exp(LnMaximum) " << setw(15) << setprecision(5) << scientific << x << endl; x = exp(FloatingPointPrecision::LnMinimum()); @@ -82,9 +82,9 @@ int my_main() // called by main() cout << "exp(LnMinimum) " << setw(15) << setprecision(5) << scientific << x << endl; cout << endl; - - - + + + return 0; } @@ -100,4 +100,3 @@ int main() } ///@} - diff --git a/extern/newmat/nm_ex3.txt b/extern/newmat/nm_ex3.txt index 6bb79ff..73b95fe 100644 --- a/extern/newmat/nm_ex3.txt +++ b/extern/newmat/nm_ex3.txt @@ -10,19 +10,19 @@ LnMinimum -708.396 Load values into a ColumnVector and print in scientific format Values in scientific format - 2.22045e-016 - 1.79769e+308 - 7.09783e+002 - 2.22507e-308 - -7.08396e+002 + 2.22045e-016 + 1.79769e+308 + 7.09783e+002 + 2.22507e-308 + -7.08396e+002 Print in fixed format Selected values in fixed format (omit Maximum) - 0.00000 - 709.78271 - 0.00000 - -708.39642 + 0.00000 + 709.78271 + 0.00000 + -708.39642 Test Epsilon @@ -47,4 +47,3 @@ Fails with some compilers - needs fixing exp(LnMaximum) 1.79769e+308 This should print a value close to Minimum, not zero exp(LnMinimum) 2.22507e-308 - diff --git a/extern/newmat/nm_gnu.mak b/extern/newmat/nm_gnu.mak index aca0335..7441f0b 100644 --- a/extern/newmat/nm_gnu.mak +++ b/extern/newmat/nm_gnu.mak @@ -9,7 +9,7 @@ MINOR = 0 %.o: %.cpp $(CXX) $(CXXFLAGS) -c $*.cpp -everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch +everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch newmat_lobj = newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o newmat6.o newmat7.o newmat8.o newmatex.o bandmat.o submat.o myexcept.o cholesky.o evalue.o fft.o hholder.o jacobi.o newfft.o sort.o svd.o nm_misc.o newmatrm.o newmat9.o @@ -209,4 +209,3 @@ sl_ex.txx: sl_ex garch.txx: garch $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_i10.mak b/extern/newmat/nm_i10.mak index 6fcf660..08b476e 100644 --- a/extern/newmat/nm_i10.mak +++ b/extern/newmat/nm_i10.mak @@ -1,5 +1,5 @@ -conlibs = +conlibs = DIFF = sdiff PRE = @@ -9,7 +9,7 @@ PRE = .cpp.obj: icl -c -GX -GR -Ge -GS -Qprec -Qprec_div -nologo -Qlong_double $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,4 +208,3 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_i8.mak b/extern/newmat/nm_i8.mak index 30b36ba..f8a0602 100644 --- a/extern/newmat/nm_i8.mak +++ b/extern/newmat/nm_i8.mak @@ -9,7 +9,7 @@ PRE = .cpp.obj: icl -c -GX -GR -Ge -GS -Qprec -Qprec_div -nologo -Qlong_double $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,4 +208,3 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_il8.mak b/extern/newmat/nm_il8.mak index 4d17412..c5f49d5 100644 --- a/extern/newmat/nm_il8.mak +++ b/extern/newmat/nm_il8.mak @@ -9,7 +9,7 @@ MINOR = 0 %.o: %.cpp $(CXX) $(CXXFLAGS) -c $*.cpp -everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch +everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch newmat_lobj = newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o newmat6.o newmat7.o newmat8.o newmatex.o bandmat.o submat.o myexcept.o cholesky.o evalue.o fft.o hholder.o jacobi.o newfft.o sort.o svd.o nm_misc.o newmatrm.o newmat9.o @@ -209,4 +209,3 @@ sl_ex.txx: sl_ex garch.txx: garch $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_m6.mak b/extern/newmat/nm_m6.mak index 97931f3..036d432 100644 --- a/extern/newmat/nm_m6.mak +++ b/extern/newmat/nm_m6.mak @@ -9,7 +9,7 @@ PRE = .cpp.obj: cl -c -W3 -Ox -GX $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,4 +208,3 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_m8.mak b/extern/newmat/nm_m8.mak index 5b29da9..a56efa3 100644 --- a/extern/newmat/nm_m8.mak +++ b/extern/newmat/nm_m8.mak @@ -9,7 +9,7 @@ PRE = .cpp.obj: cl -c -W3 -Ox -EHsc $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,4 +208,3 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/nm_misc.cpp b/extern/newmat/nm_misc.cpp index 611aaad..10116d2 100644 --- a/extern/newmat/nm_misc.cpp +++ b/extern/newmat/nm_misc.cpp @@ -27,7 +27,7 @@ ReturnMatrix Helmert(int n, bool full) Tracer et("Helmert "); if (n <= 0) Throw(ProgramException("Dimension <= 0 ")); Matrix H; - + if (full) H.resize(n,n); else H.resize(n-1,n); H = 0.0; for (int i = 1; i < n; ++i) @@ -37,7 +37,7 @@ ReturnMatrix Helmert(int n, bool full) } if (full) { H.row(n) = 1.0 / sqrt((Real)n); } H.release(); return H.for_return(); -} +} @@ -55,7 +55,7 @@ ReturnMatrix Helmert(const ColumnVector& X, bool full) { sum += X(i); Y(i) = (i * X(i+1) - sum) / sqrt((Real)i * (i+1)); } if (full) { sum += X(n); Y(n) = sum / sqrt((Real)n); } Y.release(); return Y.for_return(); -} +} // same as above for X a ColumnVector, length n, element j = 1; otherwise 0 ReturnMatrix Helmert(int n, int j, bool full) @@ -71,7 +71,7 @@ ReturnMatrix Helmert(int n, int j, bool full) for (int i = j; i < n; ++i) Y(i) = - 1.0 / sqrt((Real)i * (i+1)); if (full) Y(n) = 1.0 / sqrt((Real)n); Y.release(); return Y.for_return(); -} +} ReturnMatrix Helmert_transpose(const ColumnVector& Y, bool full) { diff --git a/extern/newmat/nm_ow.mak b/extern/newmat/nm_ow.mak index 0e69d23..6c3af9a 100644 --- a/extern/newmat/nm_ow.mak +++ b/extern/newmat/nm_ow.mak @@ -8,7 +8,7 @@ PRE = -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -209,4 +209,3 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx - diff --git a/extern/newmat/precisio.h b/extern/newmat/precisio.h index 141e155..e22a1e3 100644 --- a/extern/newmat/precisio.h +++ b/extern/newmat/precisio.h @@ -25,7 +25,7 @@ namespace NEWMAT { #endif using namespace std; - + /// Floating point precision. class FloatingPointPrecision { @@ -52,7 +52,7 @@ class FloatingPointPrecision { return (Real)log(Maximum()); } static Real Minimum() // minimum positive value - { return numeric_limits::min(); } + { return numeric_limits::min(); } static int MinimumDecimalExponent() // minimum decimal exponent { return numeric_limits::min_exponent10; } diff --git a/extern/newmat/rbd.css b/extern/newmat/rbd.css index d512592..5aaf4fb 100644 --- a/extern/newmat/rbd.css +++ b/extern/newmat/rbd.css @@ -1,20 +1,80 @@ /* Style sheet - if you are saving my html files, please also save this file as rbd.css */ -h1 { font-family: Arial, Helvetica, sans-serif; font-size: 20pt; color: maroon } -h2 { font-family: Arial, Helvetica, sans-serif; font-size: 16pt; color: maroon } -h3 { font-family: Arial, Helvetica, sans-serif; font-size: 14pt; color: maroon } -h4 { font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: maroon } -body { font-family: "Times New Roman", Times, serif; background-color: white } -body.gray { font-family: "Times New Roman", Times, serif; background-color: #CCCCCC } -p { font-family: "Times New Roman", Times, serif; margin-top: 8; margin-bottom: 8 } -p.small { font-family: "Times New Roman", Times, serif; font-size: 10pt; margin-top: 8; margin-bottom: 8 } -ul { line-height: 100%; margin-top: 2; margin-bottom: 2 } -li { margin-top: 2; margin-bottom: 2; font-size: 10pt } -tt { font-family: "Courier New", Courier, monospaced; font-size: 10pt } -pre { font-family: "Courier New", Courier, monospaced; font-size: 10pt } -pre.small { font-family: "Courier New", Courier, monospaced; font-size: 8pt } -hr { color: maroon } -a:link { color: blue } -a:visited { color: green } -a:active { color: red } -table { font-size: 10pt } -.question { color: navy; } \ No newline at end of file +h1 { + font-family: Arial, Helvetica, sans-serif; + font-size: 20pt; + color: maroon; +} +h2 { + font-family: Arial, Helvetica, sans-serif; + font-size: 16pt; + color: maroon; +} +h3 { + font-family: Arial, Helvetica, sans-serif; + font-size: 14pt; + color: maroon; +} +h4 { + font-family: Arial, Helvetica, sans-serif; + font-size: 12pt; + color: maroon; +} +body { + font-family: "Times New Roman", Times, serif; + background-color: white; +} +body.gray { + font-family: "Times New Roman", Times, serif; + background-color: #cccccc; +} +p { + font-family: "Times New Roman", Times, serif; + margin-top: 8; + margin-bottom: 8; +} +p.small { + font-family: "Times New Roman", Times, serif; + font-size: 10pt; + margin-top: 8; + margin-bottom: 8; +} +ul { + line-height: 100%; + margin-top: 2; + margin-bottom: 2; +} +li { + margin-top: 2; + margin-bottom: 2; + font-size: 10pt; +} +tt { + font-family: "Courier New", Courier, monospaced; + font-size: 10pt; +} +pre { + font-family: "Courier New", Courier, monospaced; + font-size: 10pt; +} +pre.small { + font-family: "Courier New", Courier, monospaced; + font-size: 8pt; +} +hr { + color: maroon; +} +a:link { + color: blue; +} +a:visited { + color: green; +} +a:active { + color: red; +} +table { + font-size: 10pt; +} +.question { + color: navy; +} diff --git a/extern/newmat/readme.txt b/extern/newmat/readme.txt index 0293c78..f6aad1b 100644 --- a/extern/newmat/readme.txt +++ b/extern/newmat/readme.txt @@ -8,5 +8,3 @@ Documentation is in nm11.htm. This library is freeware. See the documentation for details. To contact the author please email robert@statsresearch.co.nz - - diff --git a/extern/newmat/sl_ex.cpp b/extern/newmat/sl_ex.cpp index 485b6e2..599f3a3 100644 --- a/extern/newmat/sl_ex.cpp +++ b/extern/newmat/sl_ex.cpp @@ -3,7 +3,7 @@ /// \file sl_ex.cpp /// Test one-dimensional solve function. -/// This is an example of the use of solution to find the cube root of +/// This is an example of the use of solution to find the cube root of /// the integers -10 to 10 /// /// you will need to compile and link solution.cpp and my_except.cpp @@ -50,7 +50,7 @@ int main() } CatchAll { - cout << "\nProgram fails - exception generated\n\n"; + cout << "\nProgram fails - exception generated\n\n"; } return 0; } diff --git a/extern/newmat/solution.h b/extern/newmat/solution.h index b752e18..cfcbb61 100644 --- a/extern/newmat/solution.h +++ b/extern/newmat/solution.h @@ -96,4 +96,3 @@ class OneDimSolve ///@} - diff --git a/extern/newmat/submat.cpp b/extern/newmat/submat.cpp index f3cc95d..2074f5c 100644 --- a/extern/newmat/submat.cpp +++ b/extern/newmat/submat.cpp @@ -256,7 +256,7 @@ void GetSubMatrix::operator+=(const BaseMatrix& bmx) SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate(); if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) Throw(IncompatibleDimensionsException()); - if (gm->type().is_symmetric() && + if (gm->type().is_symmetric() && ( ! gmx->type().is_symmetric() || row_skip != col_skip) ) Throw(ProgramException("Illegal operation on symmetric")); MatrixRow mrx(gmx, LoadOnEntry); @@ -289,7 +289,7 @@ void GetSubMatrix::SP_eq(const BaseMatrix& bmx) SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate(); if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) Throw(IncompatibleDimensionsException()); - if (gm->type().is_symmetric() && + if (gm->type().is_symmetric() && ( ! gmx->type().is_symmetric() || row_skip != col_skip) ) Throw(ProgramException("Illegal operation on symmetric")); MatrixRow mrx(gmx, LoadOnEntry); @@ -321,7 +321,7 @@ void GetSubMatrix::operator-=(const BaseMatrix& bmx) SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate(); if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) Throw(IncompatibleDimensionsException()); - if (gm->type().is_symmetric() && + if (gm->type().is_symmetric() && ( ! gmx->type().is_symmetric() || row_skip != col_skip) ) Throw(ProgramException("Illegal operation on symmetric")); MatrixRow mrx(gmx, LoadOnEntry); @@ -398,4 +398,3 @@ void GetSubMatrix::operator*=(Real r) #endif ///@} - diff --git a/extern/newmat/test_exc.txt b/extern/newmat/test_exc.txt index a0be211..a836b35 100644 --- a/extern/newmat/test_exc.txt +++ b/extern/newmat/test_exc.txt @@ -34,7 +34,7 @@ Illegal conversion An exception has been thrown Logic error:- detected by Newmat: Illegal Conversion -MatrixTypes = Rect ; UT +MatrixTypes = Rect ; UT Trace: Block C; Test. @@ -207,4 +207,3 @@ compilers - see documentation) Checking for lost memory (large block): 9191360 9191360 - ok Checking for lost memory (small block): 9191360 9191360 - ok - diff --git a/extern/newmat/tmt.cpp b/extern/newmat/tmt.cpp index 3b4af85..db25ce9 100644 --- a/extern/newmat/tmt.cpp +++ b/extern/newmat/tmt.cpp @@ -194,21 +194,21 @@ void FillWithValues(MultWithCarry&MWC, Matrix& M) for (int i = 1; i <= nr; ++i) for (int j = 1; j <= nc; ++ j) M(i, j) = MWC.Next(); } - + void FillWithValues(MultWithCarry&MWC, UpperTriangularMatrix& M) { int nr = M.nrows(); for (int i = 1; i <= nr; ++i) for (int j = i; j <= nr; ++ j) M(i, j) = MWC.Next(); } - + void FillWithValues(MultWithCarry&MWC, LowerTriangularMatrix& M) { int nr = M.nrows(); for (int i = 1; i <= nr; ++i) for (int j = 1; j <= i; ++ j) M(i, j) = MWC.Next(); } - + void FillWithValues(MultWithCarry&MWC, DiagonalMatrix& M) { int nr = M.nrows(); @@ -222,8 +222,8 @@ void FillWithValues(MultWithCarry&MWC, SymmetricMatrix& M) for (int i = 1; i <= nr; ++i) for (int j = 1; j <= i; ++ j) M(i, j) = MWC.Next(); } - - + + #ifdef use_namespace } @@ -271,8 +271,8 @@ int main() TestTypeAdd(); TestTypeMult(); TestTypeConcat(); TestTypeSP(); TestTypeKP(); TestTypeOrder(); - - Try { + + Try { trymat1(); trymat2(); trymat3(); @@ -554,6 +554,3 @@ time_lapse::~time_lapse() ///@} - - - diff --git a/extern/newmat/tmt.h b/extern/newmat/tmt.h index 4233d6d..d930545 100644 --- a/extern/newmat/tmt.h +++ b/extern/newmat/tmt.h @@ -38,11 +38,11 @@ class MultWithCarry }; // fill a matrix with values from the MultWithCarry random number generator -void FillWithValues(MultWithCarry& MWC, Matrix& M); -void FillWithValues(MultWithCarry& MWC, UpperTriangularMatrix& M); -void FillWithValues(MultWithCarry& MWC, LowerTriangularMatrix& M); -void FillWithValues(MultWithCarry& MWC, DiagonalMatrix& M); -void FillWithValues(MultWithCarry& MWC, SymmetricMatrix& M); +void FillWithValues(MultWithCarry& MWC, Matrix& M); +void FillWithValues(MultWithCarry& MWC, UpperTriangularMatrix& M); +void FillWithValues(MultWithCarry& MWC, LowerTriangularMatrix& M); +void FillWithValues(MultWithCarry& MWC, DiagonalMatrix& M); +void FillWithValues(MultWithCarry& MWC, SymmetricMatrix& M); void Print(const Matrix& X); diff --git a/extern/newmat/tmt.txt b/extern/newmat/tmt.txt index 76a79f7..5017be0 100644 --- a/extern/newmat/tmt.txt +++ b/extern/newmat/tmt.txt @@ -4,97 +4,97 @@ Now print a real number: 3.14159 Matrix type: Rect (1, 8) -0 0 0 0 0 0 0 1 - -+ UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ -LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Sym Squ Squ Rect Squ Sym Squ Sym Sym Squ Squ Squ Sym Squ -Skew Squ Squ Rect Squ Squ Skew Squ Squ Squ Squ Squ Squ Skew -Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band -Ident UT LT Rect Squ Sym Squ Diag Ident Band UpBnd LwBnd SmBnd Band -Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band -SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd - -* UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ -LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Sym Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Skew Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Diag UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band -Ident UT LT Rect Squ Squ Squ Diag Ident Band UpBnd LwBnd Band Band -Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -SmBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -SkBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band - -| UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -LT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Sym Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Skew Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Diag Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Ident Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Band Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -UpBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -LwBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -SmBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -SkBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect - -SP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Diag UT UT UT UT Diag Diag UpBnd UpBnd Diag UpBnd UpBnd -LT Diag LT LT LT LT LT Diag Diag LwBnd Diag LwBnd LwBnd LwBnd -Rect UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band -Squ UT LT Squ Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band -Sym UT LT Squ Squ Sym Skew Diag Diag Band UpBnd LwBnd SmBnd SkBnd -Skew UT LT Squ Squ Skew Sym ????? ????? Band UpBnd LwBnd SkBnd SmBnd -Diag Diag Diag Diag Diag Diag ????? Diag Diag Diag Diag Diag Diag ????? -Ident Diag Diag Diag Diag Diag ????? Diag Ident Diag Diag Diag Diag ????? -Band UpBnd LwBnd Band Band Band Band Diag Diag Band UpBnd LwBnd Band Band -UpBnd UpBnd Diag UpBnd UpBnd UpBnd UpBnd Diag Diag UpBnd UpBnd Diag UpBnd UpBnd -LwBnd Diag LwBnd LwBnd LwBnd LwBnd LwBnd Diag Diag LwBnd Diag LwBnd LwBnd LwBnd -SmBnd UpBnd LwBnd Band Band SmBnd SkBnd Diag Diag Band UpBnd LwBnd SmBnd SkBnd -SkBnd UpBnd LwBnd Band Band SkBnd SmBnd ????? ????? Band UpBnd LwBnd SkBnd SmBnd - -KP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LT Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -Sym Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band -Skew Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd -Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band -Ident UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band -Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band -SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd - ->= UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT Yes No Yes Yes No No No No No No No No No -LT No Yes Yes Yes No No No No No No No No No -Rect No No Yes Yes No No No No No No No No No -Squ No No Yes Yes No No No No No No No No No -Sym No No Yes Yes Yes No No No No No No No No -Skew No No Yes Yes No Yes No No No No No No No -Diag Yes Yes Yes Yes Yes No Yes No Yes Yes Yes Yes No -Ident Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes No -Band No No Yes Yes No No No No Yes No No No No -UpBnd Yes No Yes Yes No No No No Yes Yes No No No -LwBnd No Yes Yes Yes No No No No Yes No Yes No No -SmBnd No No Yes Yes Yes No No No Yes No No Yes No -SkBnd No No Yes Yes No Yes No No Yes No No No Yes +0 0 0 0 0 0 0 1 + ++ UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ +LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Sym Squ Squ Rect Squ Sym Squ Sym Sym Squ Squ Squ Sym Squ +Skew Squ Squ Rect Squ Squ Skew Squ Squ Squ Squ Squ Squ Skew +Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band +Ident UT LT Rect Squ Sym Squ Diag Ident Band UpBnd LwBnd SmBnd Band +Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band +SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd + +* UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ +LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Sym Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Skew Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Diag UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band +Ident UT LT Rect Squ Squ Squ Diag Ident Band UpBnd LwBnd Band Band +Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +SmBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +SkBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band + +| UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +LT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Sym Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Skew Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Diag Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Ident Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Band Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +UpBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +LwBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +SmBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +SkBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect + +SP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Diag UT UT UT UT Diag Diag UpBnd UpBnd Diag UpBnd UpBnd +LT Diag LT LT LT LT LT Diag Diag LwBnd Diag LwBnd LwBnd LwBnd +Rect UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band +Squ UT LT Squ Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band +Sym UT LT Squ Squ Sym Skew Diag Diag Band UpBnd LwBnd SmBnd SkBnd +Skew UT LT Squ Squ Skew Sym ????? ????? Band UpBnd LwBnd SkBnd SmBnd +Diag Diag Diag Diag Diag Diag ????? Diag Diag Diag Diag Diag Diag ????? +Ident Diag Diag Diag Diag Diag ????? Diag Ident Diag Diag Diag Diag ????? +Band UpBnd LwBnd Band Band Band Band Diag Diag Band UpBnd LwBnd Band Band +UpBnd UpBnd Diag UpBnd UpBnd UpBnd UpBnd Diag Diag UpBnd UpBnd Diag UpBnd UpBnd +LwBnd Diag LwBnd LwBnd LwBnd LwBnd LwBnd Diag Diag LwBnd Diag LwBnd LwBnd LwBnd +SmBnd UpBnd LwBnd Band Band SmBnd SkBnd Diag Diag Band UpBnd LwBnd SmBnd SkBnd +SkBnd UpBnd LwBnd Band Band SkBnd SmBnd ????? ????? Band UpBnd LwBnd SkBnd SmBnd + +KP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LT Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +Sym Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band +Skew Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd +Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band +Ident UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band +Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band +SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd + +>= UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT Yes No Yes Yes No No No No No No No No No +LT No Yes Yes Yes No No No No No No No No No +Rect No No Yes Yes No No No No No No No No No +Squ No No Yes Yes No No No No No No No No No +Sym No No Yes Yes Yes No No No No No No No No +Skew No No Yes Yes No Yes No No No No No No No +Diag Yes Yes Yes Yes Yes No Yes No Yes Yes Yes Yes No +Ident Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes No +Band No No Yes Yes No No No No Yes No No No No +UpBnd Yes No Yes Yes No No No No Yes Yes No No No +LwBnd No Yes Yes Yes No No No No Yes No Yes No No +SmBnd No No Yes Yes Yes No No No Yes No No Yes No +SkBnd No No Yes Yes No Yes No No Yes No No No Yes * First test of Matrix package @@ -6591,4 +6591,3 @@ Number of matrices tested = 1604 Number of non-zero matrices (should be 1) = 1 Elapsed (processor) time = 0.36 seconds - diff --git a/extern/newmat/tmt1.cpp b/extern/newmat/tmt1.cpp index 80d76de..054b5db 100644 --- a/extern/newmat/tmt1.cpp +++ b/extern/newmat/tmt1.cpp @@ -137,15 +137,15 @@ void trymat1() Matrix M1X = BM1; Matrix M2X = BM2; Matrix MX = BM; MX -= M1X + M2X; Print(MX); MX = BM1; MX += BM2; MX -= M1X; MX -= M2X; Print(MX); - SymmetricBandMatrix SM1; SM1 << BM1 * BM1.t(); + SymmetricBandMatrix SM1; SM1 << BM1 * BM1.t(); SymmetricBandMatrix SM2; SM2 << BM2 * BM2.t(); SM1 *= 5.5; M1X *= M1X.t(); M1X *= 5.5; M2X *= M2X.t(); SM1 -= SM2; M1 = SM1 - M1X + M2X; Print(M1); - M1 = BM1; BM1 *= SM1; M1 = M1 * SM1 - BM1; Print(M1); - M1 = BM1; BM1 -= SM1; M1 = M1 - SM1 - BM1; Print(M1); - M1 = BM1; BM1 += SM1; M1 = M1 + SM1 - BM1; Print(M1); - + M1 = BM1; BM1 *= SM1; M1 = M1 * SM1 - BM1; Print(M1); + M1 = BM1; BM1 -= SM1; M1 = M1 - SM1 - BM1; Print(M1); + M1 = BM1; BM1 += SM1; M1 = M1 + SM1 - BM1; Print(M1); + } { Tracer et1("Stage 6"); @@ -271,16 +271,16 @@ void trymat1() ColumnVector cv(10); for (int i = 1; i <= 10; ++i) cv(i) = mwc.Next(); cv *= 100.0; - cv(1) -= 6.27874; - cv(2) -= 42.1718; - cv(3) -= 80.2854; - cv(4) -= 12.961; - cv(5) -= 17.7499; - cv(6) -= 13.2657; - cv(7) -= 50.4923; - cv(8) -= 26.095; - cv(9) -= 57.9147; - cv(10) -= 30.1778; + cv(1) -= 6.27874; + cv(2) -= 42.1718; + cv(3) -= 80.2854; + cv(4) -= 12.961; + cv(5) -= 17.7499; + cv(6) -= 13.2657; + cv(7) -= 50.4923; + cv(8) -= 26.095; + cv(9) -= 57.9147; + cv(10) -= 30.1778; Clean(cv, 0.0001); Print(cv); } diff --git a/extern/newmat/tmt2.cpp b/extern/newmat/tmt2.cpp index 443aea7..c435e67 100644 --- a/extern/newmat/tmt2.cpp +++ b/extern/newmat/tmt2.cpp @@ -285,7 +285,7 @@ void trymat2() I.ReSize(3); J.ReSize(3); K = I * J; N = K - I; Print(N); K << D; N = K - D; Print(N); } - + // test add integer { Matrix X(2,3); @@ -296,15 +296,15 @@ void trymat2() X += (-10); X -= Y; Print(X); - + // also test f suffix X << 5.25f << 7.75f << 1.25f << 9.00f << 1.00f << 2.50f; X -= Y; Print(X); - + } - - + + // cout << "\nEnd of second test\n"; diff --git a/extern/newmat/tmt4.cpp b/extern/newmat/tmt4.cpp index d2ed96b..fed955b 100644 --- a/extern/newmat/tmt4.cpp +++ b/extern/newmat/tmt4.cpp @@ -157,7 +157,7 @@ void trymat4() D1(1) = 18; D1(2) = 23; D1(3) = 31; D1(4) = 17; D1 -= D; Print(D1); } - + { Tracer et1("Stage 8"); // test swap functions @@ -173,13 +173,13 @@ void trymat4() D = A - B1; Print(D); Print(A); // now should be zero D.ReSize(1,2); D(1,1) = a; D(1,2) = b; Print(D); - + A.ReSize(20,20); FillWithValues(MWC, A); - + UpperTriangularMatrix UA; UA << A; UpperTriangularMatrix UA1 = UA; UpperTriangularMatrix UB; swap(UA, UB); Print(UA); UB -= UA1; Print(UB); - + LowerTriangularMatrix LA; LA << A; LowerTriangularMatrix LA1 = LA; LowerTriangularMatrix LB; swap(LB, LA); Print(LA); LB -= LA1; Print(LB); @@ -187,63 +187,63 @@ void trymat4() SymmetricMatrix SA; SA << A; SymmetricMatrix SA1 = SA; SymmetricMatrix SB; swap(SA, SB); Print(SA); SB -= SA1; Print(SB); - + DiagonalMatrix DA; DA << A; DiagonalMatrix DA1 = DA; DiagonalMatrix DB; swap(DB, DA); Print(DA); DB -= DA1; Print(DB); - + RowVector RVA = A.Row(1); RowVector RVA1 = RVA; RowVector RVB; swap(RVB, RVA); Print(RVA); RVB -= RVA1; Print(RVB); - + ColumnVector CVA = A.Column(1); ColumnVector CVA1 = CVA; ColumnVector CVB; swap(CVA, CVB); Print(CVA); CVB -= CVA1; Print(CVB); - + BandMatrix BA(20, 7, 4); BA.Inject(A); BandMatrix BA1 = BA; BandMatrix BB; swap(BA, BB); D = BA; Print(D); BB -= BA1; D = BB; Print(D); - + LowerBandMatrix LBA(20, 6); LBA.Inject(A); LowerBandMatrix LBA1 = LBA; LowerBandMatrix LBB; swap(LBB, LBA); D = LBA; Print(D); LBB -= LBA1; D = LBB; Print(D); - + UpperBandMatrix UBA(20, 9); UBA.Inject(A); UpperBandMatrix UBA1 = UBA; UpperBandMatrix UBB; swap(UBA, UBB); D = UBA; Print(D); UBB -= UBA1; D = UBB; Print(D); - + SymmetricBandMatrix SBA(20, 4); SBA.Inject(A); SymmetricBandMatrix SBA1 = SBA; SymmetricBandMatrix SBB; - + swap(SBB, SBA); D = SBA; Print(D); SBB -= SBA1; D = SBB; Print(D); - + B.ReSize(10,10); FillWithValues(MWC, B); - + CroutMatrix CA = A; IdentityMatrix IA(20); CroutMatrix CB = B; IdentityMatrix IB(10); swap(CA, CB); swap(IA, IB); D = CA.i() * B - IA; Clean(D,0.00000001); Print(D); D = CB.i() * A - IB; Clean(D,0.00000001); Print(D); - + BA.ReSize(20, 5, 7); BA.Inject(A); BandLUMatrix BLUA = BA; BB.ReSize(10, 3, 4); BB.Inject(B); BandLUMatrix BLUB = BB; swap(BLUA, BLUB); D = BLUA.i() * BB - IA; Clean(D,0.00000001); Print(D); D = BLUB.i() * BA - IB; Clean(D,0.00000001); Print(D); - + SBA.ReSize(20, 5); SBA.Inject(A); BandLUMatrix SBLUA = SBA; SBB.ReSize(10, 3); SBB.Inject(B); BandLUMatrix SBLUB = SBB; swap(SBLUA, SBLUB); D = SBLUA.i() * SBB - IA; Clean(D,0.00000001); Print(D); D = SBLUB.i() * SBA - IB; Clean(D,0.00000001); Print(D); - + UA << A; GenericMatrix GUA = UA; GenericMatrix GB = B; swap(GUA, GB); D = GB - UA; Print(D); D = B - GUA; Print(D); - + } // cout << "\nEnd of fourth test\n"; diff --git a/extern/newmat/tmt6.cpp b/extern/newmat/tmt6.cpp index 8defa2a..f8423b7 100644 --- a/extern/newmat/tmt6.cpp +++ b/extern/newmat/tmt6.cpp @@ -79,7 +79,7 @@ void trymat6() for (i=1;i<=6;i++) for (j=i;j<=6;j++) S(i,j)=i*i+2.0+j; Matrix MD=D; Matrix ML=L; Matrix MU=U; Matrix MS=S; Matrix M(6,6); - for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; + for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; { Tracer et1("Stage 1"); Print(Matrix(MS+(-MS))); diff --git a/extern/newmat/tmt7.cpp b/extern/newmat/tmt7.cpp index c4e43fa..4ece58c 100644 --- a/extern/newmat/tmt7.cpp +++ b/extern/newmat/tmt7.cpp @@ -29,7 +29,7 @@ void c_matrix_multiply(int p, int q, int r, c[i][k] = sum; } } - + void trymat7() @@ -50,7 +50,7 @@ void trymat7() Matrix MD=D; Matrix ML=L; Matrix MU=U; Matrix MS=S; Matrix M(6,6); - for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; + for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; { Tracer et1("Stage 1"); Print(Matrix((S-M)-(MS-M))); @@ -99,7 +99,7 @@ void trymat7() CV << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75; D << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75; X = CV.AsDiagonal(); X = X-D; Print(X); - SymmetricBandMatrix SB1(11,7); SB1 = 5; + SymmetricBandMatrix SB1(11,7); SB1 = 5; SymmetricBandMatrix SB2 = SB1 + D; X.ReSize(11,11); X=0; for (i=1;i<=11;i++) for (j=1;j<=11;j++) @@ -145,12 +145,12 @@ void trymat7() for (i = 0; i < 5; i++) if (F[i] != 0) Test(9)=1; Print(Test); } - + { // testing RealStarStar Tracer et("Stage 6"); MultWithCarry MWC; - + Matrix A(10, 12), B(12, 15), C(10, 15); FillWithValues(MWC, A); FillWithValues(MWC, B); ConstRealStarStar a(A); @@ -165,13 +165,13 @@ void trymat7() ConstRealStarStar(A),ConstRealStarStar(B),RealStarStar(C)); X = C - A * B; Clean(X,0.00000001); Print(X); } - + { // testing resize_keep Tracer et("Stage 7"); Matrix X, Y; MultWithCarry MWC; - + X.resize(20,35); FillWithValues(MWC, X); Matrix M(20,35); M = X; X = M.submatrix(1,15,1,25); @@ -181,14 +181,14 @@ void trymat7() M.resize_keep(29,27); Y -= M; Print(Y); M.resize_keep(0,5); M.resize_keep(10,10); Print(M); M.resize_keep(15,0); M.resize_keep(10,10); Print(M); - + X.resize(20,35); FillWithValues(MWC, X); M = X; M.resize_keep(38,17); Y.resize(38,17); Y = 0; Y.submatrix(1,20,1,17) = X.submatrix(1,20,1,17); Y -= M; Print(Y); - + X.resize(40,12); FillWithValues(MWC, X); M = X; M.resize_keep(38,17); @@ -207,23 +207,23 @@ void trymat7() nM.resize_keep(29,27); Y -= nM; Print(Y); nM.resize_keep(0,5); nM.resize_keep(10,10); Print(nM); nM.resize_keep(15,0); nM.resize_keep(10,10); Print(nM); - + X.resize(20,35); FillWithValues(MWC, X); nM = X; nM.resize_keep(38,17); Y.resize(38,17); Y = 0; Y.submatrix(1,20,1,17) = X.submatrix(1,20,1,17); Y -= nM; Print(Y); - + X.resize(40,12); FillWithValues(MWC, X); nM = X; nM.resize_keep(38,17); Y.resize(38,17); Y = 0; Y.submatrix(1,38,1,12) = X.submatrix(1,38,1,12); - Y -= nM; Print(Y); + Y -= nM; Print(Y); + +#endif -#endif - X.resize(20,20); FillWithValues(MWC, X); SquareMatrix SQM(20); SQM << X; X = SQM.sym_submatrix(1,13); @@ -232,7 +232,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; SQM.resize_keep(23,23); Y -= SQM; Print(Y); SQM.resize_keep(0); SQM.resize_keep(50); Print(SQM); - + X.resize(20,20); FillWithValues(MWC, X); SymmetricMatrix SM(20); SM << X; X = SM.sym_submatrix(1,13); @@ -241,7 +241,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; SM.resize_keep(23); Y -= SM; Print(Y); SM.resize_keep(0); SM.resize_keep(50); Print(SM); - + X.resize(20,20); FillWithValues(MWC, X); LowerTriangularMatrix LT(20); LT << X; X = LT.sym_submatrix(1,13); @@ -250,7 +250,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; LT.resize_keep(23); Y -= LT; Print(Y); LT.resize_keep(0); LT.resize_keep(50); Print(LT); - + X.resize(20,20); FillWithValues(MWC, X); UpperTriangularMatrix UT(20); UT << X; X = UT.sym_submatrix(1,13); @@ -259,7 +259,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; UT.resize_keep(23); Y -= UT; Print(Y); UT.resize_keep(0); UT.resize_keep(50); Print(UT); - + X.resize(20,20); FillWithValues(MWC, X); DiagonalMatrix DM(20); DM << X; X = DM.sym_submatrix(1,13); @@ -268,7 +268,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; DM.resize_keep(23); Y -= DM; Print(Y); DM.resize_keep(0); DM.resize_keep(50); Print(DM); - + X.resize(1,20); FillWithValues(MWC, X); RowVector RV(20); RV << X; X = RV.columns(1,13); @@ -277,7 +277,7 @@ void trymat7() Y.resize(1,23); Y = 0; Y.columns(1,13) = X; RV.resize_keep(1,23); Y -= RV; Print(Y); RV.resize_keep(0); RV.resize_keep(50); Print(RV); - + X.resize(20,1); FillWithValues(MWC, X); ColumnVector CV(20); CV << X; X = CV.rows(1,13); @@ -286,9 +286,9 @@ void trymat7() Y.resize(23,1); Y = 0; Y.rows(1,13) = X; CV.resize_keep(23,1); Y -= CV; Print(Y); CV.resize_keep(0); CV.resize_keep(50); Print(CV); - - - } + + + } // cout << "\nEnd of seventh test\n"; diff --git a/extern/newmat/tmt8.cpp b/extern/newmat/tmt8.cpp index 60b5a16..f369e05 100644 --- a/extern/newmat/tmt8.cpp +++ b/extern/newmat/tmt8.cpp @@ -145,7 +145,7 @@ void trymat8() M.ReSize(MX); DCR( D.nric(), C.nric(), 5, R.nric(), 9, M.nric() ); M -= MX; Print(M); - + // test swap nricMatrix A(3,4); nricMatrix B(4,5); A.Row(1) << 2 << 7 << 3 << 6; @@ -164,7 +164,7 @@ void trymat8() for (int k = 1; k <= 4; ++k) X.nric()[i][j] += A1.nric()[i][k] * B1.nric()[k][j]; } - X1 -= X; Print(X1); + X1 -= X; Print(X1); } #endif { diff --git a/extern/newmat/tmt9.cpp b/extern/newmat/tmt9.cpp index bef4636..fc4fd4c 100644 --- a/extern/newmat/tmt9.cpp +++ b/extern/newmat/tmt9.cpp @@ -41,7 +41,7 @@ void trymat9() { Tracer et1("Stage 2"); Matrix DXE = D.i() * X * E; - DXE = E.i() * DXE.t() * D - X.t(); Clean(DXE, 0.00000001); Print(DXE); + DXE = E.i() * DXE.t() * D - X.t(); Clean(DXE, 0.00000001); Print(DXE); E=D; for (i=1;i<=7;i++) E(i,i)=i*3+1; } DiagonalMatrix F=D; @@ -216,7 +216,7 @@ void trymat9() { Tracer et1("Stage 8"); - // test copying CroutMatrix and BandLUMatrix - see also tmtd.cpp + // test copying CroutMatrix and BandLUMatrix - see also tmtd.cpp MultWithCarry MWC; SymmetricBandMatrix SBM(50, 10); for (int i = 1; i <= 50; ++i) for (int j = 1; j <= i; ++j) @@ -241,7 +241,7 @@ void trymat9() { Tracer et1("Stage 9"); - // do it again odd matrix size + // do it again odd matrix size MultWithCarry MWC; SymmetricBandMatrix SBM(51, 10); for (int i = 1; i <= 51; ++i) for (int j = 1; j <= i; ++j) @@ -263,7 +263,7 @@ void trymat9() D(4) = z.sign() - x.sign(); Clean(D,0.00000001); Print(D); } - + { Tracer et1("Stage 10"); // testing equal again @@ -280,12 +280,12 @@ void trymat9() B *= 3; A = B; X = A.i() * B - IdentityMatrix(10); Clean(X,0.00000001); Print(X); - } - - - - - + } + + + + + // cout << "\nEnd of ninth test\n"; } diff --git a/extern/newmat/tmtc.cpp b/extern/newmat/tmtc.cpp index a88f4f8..2d48595 100644 --- a/extern/newmat/tmtc.cpp +++ b/extern/newmat/tmtc.cpp @@ -184,7 +184,7 @@ void trymatc() { RowVector RV = 5 * M1.Row(i); M.Row(i) -= RV; } M += M1; Print(M); - + } { @@ -205,13 +205,13 @@ void trymatc() nricMatrix N2 = N; nricMatrix Y = N; Print(Y); Y = N1 - N2; Print(Y); - + N = M1 / 2; N1 = N * 2; N.Release(); N2 = N * 2; Y = N; Print(N); Y = (N1 - M1) | (N2 - M1); Print(Y); #endif } - + { Tracer et("Stage 13"); // test sum of squares of rows or columns @@ -272,9 +272,9 @@ void trymatc() A1.ReSize(10,0); X.ReSize(10,1); X = 0; X -= A1.sum_square_rows(); Clean(X, 0.00000000000001); Print(X); X.ReSize(1,0); X -= A1.sum_square_columns(); Clean(X, 0.00000000000001); Print(X); - + } - + { Tracer et("Stage 14"); // test extend orthonormal @@ -289,7 +289,7 @@ void trymatc() // Check orthogonality X = A.t() * A - IdentityMatrix(5); Clean(X, 0.000000001); Print(X); - // Try orthonality extend + // Try orthonality extend SquareMatrix A1(20); A1.Columns(1,5) = A; extend_orthonormal(A1,5); @@ -297,10 +297,10 @@ void trymatc() X = A - A1.Columns(1,5); Print(X); // Check orthogonality X = A1.t() * A1 - IdentityMatrix(20); - Clean(X, 0.000000001); Print(X); + Clean(X, 0.000000001); Print(X); X = A1 * A1.t() - IdentityMatrix(20); Clean(X, 0.000000001); Print(X); - // Test with smaller number of columns + // Test with smaller number of columns Matrix A2(20,15); A2.Columns(1,5) = A; extend_orthonormal(A2,5); @@ -333,7 +333,7 @@ void trymatc() B -= A; Clean(B, 0.000000001); Print(B); } - + { Tracer et("Stage 16"); // test sum of rows or columns @@ -396,9 +396,9 @@ void trymatc() A1.ReSize(10,0); X.ReSize(10,1); X = 0; X -= A1.sum_rows(); Print(X); X.ReSize(1,0); X -= A1.sum_columns(); Print(X); - + } - + { Tracer et("Stage 17"); // SP_eq on submatrices @@ -408,20 +408,20 @@ void trymatc() Matrix X = A; X.submatrix(5,21,3,13).SP_eq(B); Matrix Y = A; Y.submatrix(5,21,3,13) = SP(Y.submatrix(5,21,3,13),B); Y -= X; Print(Y); - + UpperTriangularMatrix UT(33); FillWithValues(mwc, UT); UpperTriangularMatrix UTX = UT; UTX.submatrix(5,21,3,13).SP_eq(B); Y = UT; Y.submatrix(5,21,3,13) = SP(Y.submatrix(5,21,3,13),B); Y -= UTX; Print(Y); - + UT.resize(10); FillWithValues(mwc, UT); X = A; X.submatrix(5,14,3,12).SP_eq(UT); Y = A; Y.submatrix(5,14,3,12) = SP(Y.submatrix(5,14,3,12),UT); Y -= X; Print(Y); - + SymmetricMatrix SM(30), SM1(10); FillWithValues(mwc, SM); FillWithValues(mwc, SM1); SymmetricMatrix SMX = SM; @@ -429,12 +429,12 @@ void trymatc() //SMX.sym_submatrix(5,14) += SM1; //Y = SM; Y.submatrix(5,14,5,14) = Y.submatrix(5,14,5,14) + SM1; //Y -= SMX; Print(Y); - + SMX = SM; SMX.submatrix(5,14,5,14).SP_eq(SM1); Y = SM; Y.submatrix(5,14,5,14) = SP(Y.submatrix(5,14,5,14),SM1); Y -= SMX; Print(Y); - + BandMatrix BM(50, 10, 12); X.resize(50,50); FillWithValues(mwc, X); BM.inject(X); X = BM; @@ -449,17 +449,17 @@ void trymatc() BM.submatrix(2,8,4,13).SP_eq(B); X.submatrix(2,8,4,13) = SP(X.submatrix(2,8,4,13), B); X -= BM; Print(X); - + X.resize(50,50); FillWithValues(mwc, X); BM.inject(X); X = BM; B.resize(21, 23); FillWithValues(mwc, B); BM.submatrix(2,22,4,26).SP_eq(B); X.submatrix(2,22,4,26) = SP(X.submatrix(2,22,4,26), B); X -= BM; Print(X); - + } - - { + + { Tracer et("Stage 18"); // += real on submatrices of symmetric matrices // these don't work either @@ -470,27 +470,27 @@ void trymatc() //SMX.sym_submatrix(7,11) += 5; //Matrix X = SM; X.sym_submatrix(7,11) += 5; //X -= SMX; Print(X); - + } - + { Tracer et("Stage 19"); // SQ_eq on matrices MultWithCarry mwc; - + Matrix X(10,13), Y(10,13); FillWithValues(mwc, X); FillWithValues(mwc, Y); Matrix Z = X; Z.SP_eq(Y); Z -= SP(X, Y); Print(Z); - + Z = X; Z.SP_eq(2 * Y); Z -= 2 * SP(X, Y); Print(Z); - + Z = X; Z.SP_eq(Z); Z -= SP(X, X); Print(Z); - + GenericMatrix GX = X, GY = Y; test_SP_eq(GX, GY); test_SP_eq(GX, GX); - + X.resize(17,17); Y.resize(17,17); FillWithValues(mwc, X); FillWithValues(mwc, Y); UpperTriangularMatrix UT; UT << Y; @@ -504,28 +504,28 @@ void trymatc() UpperTriangularMatrix UX(19), UY(19); FillWithValues(mwc, UX); FillWithValues(mwc, UY); - + GX = UX; GY = UY; test_SP_eq(GX, GY); test_SP_eq(GX, GY.t()); UpperTriangularMatrix UZ = UX; UZ.SP_eq(UY); UZ -= SP(UX, UY); Print(UZ); - + UZ = UX; UZ.SP_eq(2 * UY); UZ -= 2 * SP(UX, UY); Print(UZ); - + UT << UY; LT << UY; D << UY; UpperTriangularMatrix UZUT = UX; UZUT.SP_eq(UT); UpperTriangularMatrix UZLT = UX; UZLT.SP_eq(LT); UpperTriangularMatrix UZD = UX; UZD.SP_eq(D); Z = UZUT + UZLT - UZD - SP(UX, UY); Clean(Z, 0.000000001); Print(Z); - + SymmetricMatrix SM(13), SM1(13), SMX, SM2; FillWithValues(mwc, SM); FillWithValues(mwc, SM1); SMX = SP(SM, SM1); SM2 = SM; SM2.SP_eq(SM1); SM2 -= SMX; Print(SM2); GX = SM; GY = SM1; test_SP_eq(GX, GY); - + X.resize(13,13); FillWithValues(mwc, X); Z = SP(X,SM); SM2 = SM; X.SP_eq(SM); X -= Z; Print(X); @@ -533,7 +533,7 @@ void trymatc() FillWithValues(mwc, X); GX = X; GY = SM; test_SP_eq(GX, GY); GX = SM; GY = X; test_SP_eq(GX, GY); - + BandMatrix BMX(13, 5,9); BMX.inject(X); SymmetricBandMatrix SBM(13,6); SBM.inject(SM); GX = BMX; GY = SBM; test_SP_eq(GX, GY); @@ -542,11 +542,11 @@ void trymatc() BandMatrix BMX2 = SBM; GX = BMX; GY = BMX2; test_SP_eq(GX, GY); BMX1 = BMX; BMX1.SP_eq(BMX2); Z = BMX1 - SP(BMX,BMX2); Print(Z); - - + + } - - + + // cout << "\nEnd of twelfth test\n"; } diff --git a/extern/newmat/tmtd.cpp b/extern/newmat/tmtd.cpp index edf574e..6ff3cd7 100644 --- a/extern/newmat/tmtd.cpp +++ b/extern/newmat/tmtd.cpp @@ -137,9 +137,9 @@ void QRZ_checkT(Matrix& X, Matrix& Y, UpperTriangularMatrix& U, Matrix& M) Matrix XT = X.t(), YT = Y.t(), MT, BX; LowerTriangularMatrix L; QRZ(X, Y, U, M); QRZT(XT, YT, L, MT); - BX = U - L.t(); Clean(BX, 0.000000001); Print(BX); - BX = M - MT.t(); Clean(BX, 0.000000001); Print(BX); -} + BX = U - L.t(); Clean(BX, 0.000000001); Print(BX); + BX = M - MT.t(); Clean(BX, 0.000000001); Print(BX); +} @@ -289,7 +289,7 @@ void trymatd() M = A * Cholesky(B); M = M * M.t() - A * B * A; Clean(M, 0.000000001); Print(M); } - + { Tracer et1("Stage 6"); int N=49; @@ -334,8 +334,8 @@ void trymatd() D(6) = B1.nrows(); D(7) = B1.ncols(); D(8) = B1.size(); Clean(C, 0.000000001); Print(C); // see if we get an implicit invert - B1 = -A; - D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change + B1 = -A; + D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change C = -A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // check for_return @@ -368,7 +368,7 @@ void trymatd() const int* i2 = B2.const_data_indx(); D(25) = (d != d1 ? 0 : 1) + (d1 == d2 ? 0 : 1) + (i != i1 ? 0 : 1) + (i1 == i2 ? 0 : 1); - + Clean(D, 0.000000001); Print(D); } @@ -403,8 +403,8 @@ void trymatd() D(6) = B1.nrows(); D(7) = B1.ncols(); D(8) = B1.size(); Clean(C, 0.000000001); Print(C); // see if we get an implicit invert - B1 = -A; - D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change + B1 = -A; + D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change C = -A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // check for_return @@ -471,7 +471,7 @@ void trymatd() QRZ(X, U2); Matrix Diff = U1 - U2; Clean(Diff, 0.000000001); Print(Diff); - // Try adding new row to X and updating triangular matrix + // Try adding new row to X and updating triangular matrix RowVector NewRow(10); for (j = 1; j <= 10; ++j) NewRow(j) = 2.0 * (mwc.Next() - 0.5); UpdateCholesky(U2, NewRow); @@ -492,7 +492,7 @@ void trymatd() CircularShift(X, 1,6); CircularShift(X, 6,10); } - + { Tracer et1("Stage 10"); // Try updating QRZ, QRZT decomposition @@ -507,9 +507,9 @@ void trymatd() tuqrz2.Reset(); tuqrz2.ClearRow(5); tuqrz2.ClearRow(6); tuqrz2.DoTest(); tuqrz2.Reset(); tuqrz2.ClearRow(15); tuqrz2.DoTest(); TestUpdateQRZ tuqrz3(5, 0, 10, 0); tuqrz3.DoTest(); - + } - + { Tracer et1("Stage 11"); // combining three decompositions @@ -537,14 +537,14 @@ void trymatd() fix_signs(U3); BX = U - U3; Clean(BX, 0.000000001); Print(BX); - + // same again with some columns set to zero FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(1,8) = 0; X2.columns(5,13) = 0; - X3.columns(10,20) = 0; + X3.columns(10,20) = 0; X = X1 & X2 & X3; Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); QRZ(X2, Y2, U2, M2); @@ -560,14 +560,14 @@ void trymatd() fix_signs(U3); BX = U - U3; Clean(BX, 0.000000001); Print(BX); - + // same again with some duplicate columns FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(4,5) = X1.columns(1,2); X2.columns(7,12) = X2.columns(1,6); - X3.columns(11,20) = X3.columns(1,10); + X3.columns(11,20) = X3.columns(1,10); X = X1 & X2 & X3; Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); QRZ(X2, Y2, U2, M2); @@ -583,9 +583,9 @@ void trymatd() fix_signs(U3); BX = U - U3; Clean(BX, 0.000000001); Print(BX); - - - + + + // Try with incremental update FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); @@ -608,7 +608,7 @@ void trymatd() FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(1,8) = 0; X2.columns(5,13) = 0; - X3.columns(10,20) = 0; + X3.columns(10,20) = 0; X = X1 & X2 & X3, Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); UpdateQRZ(X2, U1); UpdateQRZ(X2, Y2, M1); @@ -620,15 +620,15 @@ void trymatd() fix_signs(U1); BX = U - U1; Clean(BX, 0.000000001); Print(BX); - - + + // same again with some duplicate columns FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(4,5) = X1.columns(1,2); X2.columns(7,12) = X2.columns(1,6); - X3.columns(11,20) = X3.columns(1,10); + X3.columns(11,20) = X3.columns(1,10); X = X1 & X2 & X3, Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); UpdateQRZ(X2, U1); UpdateQRZ(X2, Y2, M1); @@ -640,7 +640,7 @@ void trymatd() fix_signs(U1); BX = U - U1; Clean(BX, 0.000000001); Print(BX); - + // Try with incremental update using QRZT LowerTriangularMatrix L, L1; X1.resize(21, 90); X2.resize(21, 250); X3.resize(21, 113); @@ -662,7 +662,7 @@ void trymatd() FillWithValues(MWC, X3); X1.rows(1,8) = 0; X2.rows(5,13) = 0; - X3.rows(10,21) = 0; + X3.rows(10,21) = 0; X = X1 | X2 | X3; QRZT(X1, L1); UpdateQRZT(X2, L1); @@ -671,15 +671,15 @@ void trymatd() fix_signs(L1); BX = L - L1; Clean(BX, 0.000000001); Print(BX); - - + + // same again with some duplicate columns FillWithValues(MWC, X1); FillWithValues(MWC, X2); FillWithValues(MWC, X3); X1.columns(4,5) = X1.columns(1,2); X2.columns(7,12) = X2.columns(1,6); - X3.columns(12,21) = X3.columns(1,10); + X3.columns(12,21) = X3.columns(1,10); X = X1 | X2 | X3; QRZT(X1, L1); UpdateQRZT(X2, L1); @@ -688,9 +688,9 @@ void trymatd() fix_signs(L1); BX = L - L1; Clean(BX, 0.000000001); Print(BX); - } - - + } + + // cout << "\nEnd of Thirteenth test\n"; } @@ -764,6 +764,6 @@ void fix_signs(LowerTriangularMatrix& L) L.column(i) = -L.column(i); } } - + ///@} diff --git a/extern/newmat/tmte.cpp b/extern/newmat/tmte.cpp index c3e46ad..215e50a 100644 --- a/extern/newmat/tmte.cpp +++ b/extern/newmat/tmte.cpp @@ -502,7 +502,7 @@ void trymate() Clean(X, 0.000000001); Print(X); Y = V * V.t() - IdentityMatrix(2); Clean(Y, 0.000000001); Print(Y); - + } diff --git a/extern/newmat/tmtf.cpp b/extern/newmat/tmtf.cpp index 57d21c2..8ddd640 100644 --- a/extern/newmat/tmtf.cpp +++ b/extern/newmat/tmtf.cpp @@ -303,7 +303,7 @@ static void test9(int m, int n) Clean(X,0.000000001); Clean(Y,0.000000001); Print(X); Print(Y); FFT2I(X1, Y1, X1, Y1); X1 -= A; Y1 -= B; - Clean(X1,0.000000001); Clean(Y1,0.000000001); Print(X1); Print(Y1); + Clean(X1,0.000000001); Clean(Y1,0.000000001); Print(X1); Print(Y1); } @@ -367,7 +367,7 @@ void trymatf() test9(1,16); test9(16,1); test9(4,3); test9(4,4); test9(4,5); test9(5,3); - + // now do the same thing all over again forcing use of old FFT FFT_Controller::OnlyOldFFT = true; @@ -417,7 +417,7 @@ void trymatf() // compare DCT, DST and slow versions test8(2); test8(26); test8(32); test8(18); - + // compare FFT2 with slow version // don't redo these diff --git a/extern/newmat/tmth.cpp b/extern/newmat/tmth.cpp index 0d3100e..ef77cbd 100644 --- a/extern/newmat/tmth.cpp +++ b/extern/newmat/tmth.cpp @@ -766,7 +766,7 @@ void trymath() RV(2) = BM.BandWidth().Upper(); Print(RV); } - + { // Helmert multiplies Tracer et1("Stage 9"); @@ -779,22 +779,22 @@ void trymath() Matrix H = Helmert(9); H -= Y.t(); Clean(H,0.000000001); Print(H); Matrix Z = Helmert(Y) - I; Clean(Z,0.000000001); Print(Z); - + Matrix A(9, 8); for (i = 1; i <= 9; ++i) for (j = 1; j <= 8; ++j) A(i, j) = Helmert_transpose(X.column(j), i); - A -= Y; Clean(A,0.000000001); Print(A); - + A -= Y; Clean(A,0.000000001); Print(A); + X = I; Y = Helmert_transpose(X, true); H = Helmert(8, true); H -= Y.t(); Clean(H,0.000000001); Print(H); Z = Helmert(Y, true) - I; Clean(Z,0.000000001); Print(Z); - + A.resize(8, 8); for (i = 1; i <= 8; ++i) for (j = 1; j <= 8; ++j) A(i, j) = Helmert_transpose(X.column(j), i, true); - A -= Y; Clean(A,0.000000001); Print(A); + A -= Y; Clean(A,0.000000001); Print(A); @@ -804,7 +804,7 @@ void trymath() H = Helmert(9, true); H -= Y; Clean(H,0.000000001); Print(H); Z = Helmert_transpose(Y, true) - I; Clean(Z,0.000000001); Print(Z); - + A.ReSize(9, 9); for (i = 1; i <= 9; ++i) A.Column(i) = Helmert(9, i, true); A -= Y; Clean(A,0.000000001); Print(A); @@ -813,10 +813,10 @@ void trymath() A.ReSize(8, 9); for (i = 1; i <= 9; ++i) A.Column(i) = Helmert(9, i); A -= Y; Clean(A,0.000000001); Print(A); - + ColumnVector Twos(100); Twos = 2; ColumnVector CV = Helmert(Twos); Clean(CV,0.000000001); Print(CV); - + X.resize(25,30); FillWithValues(MCW, X); Y = Helmert(X); @@ -824,7 +824,7 @@ void trymath() Clean(Z,0.000000001); Print(Z); Z = Helmert(X,true).row(25) - X.sum_columns() / 5.0; Clean(Z,0.000000001); Print(Z); - + I.resize(15); X = I; Z = Helmert_transpose(X, true) - Helmert(X, true).t(); @@ -832,15 +832,15 @@ void trymath() I.resize(14); Y = I; Z = Helmert(X) - Helmert_transpose(Y).t(); Clean(Z,0.000000001); Print(Z); - - - + + + } - - - - - + + + + + // cout << "\nEnd of Seventeenth test\n"; } diff --git a/extern/newmat/tmti.cpp b/extern/newmat/tmti.cpp index c74057e..577e3e1 100644 --- a/extern/newmat/tmti.cpp +++ b/extern/newmat/tmti.cpp @@ -237,4 +237,3 @@ void trymati() ///@} - diff --git a/extern/newmat/tmtj.cpp b/extern/newmat/tmtj.cpp index 9463f0e..8e5a997 100644 --- a/extern/newmat/tmtj.cpp +++ b/extern/newmat/tmtj.cpp @@ -142,7 +142,7 @@ void trymatj() SymmetricBandMatrix SB(7,3); SymmetricMatrix S; S << (B+B.t()); SB.Inject(S); A = BA; S = SB; - Matrix X; + Matrix X; X = SP(BA,SB); X=X-SP(A,S); Print(X); X = SP(BA*2,SB); X=X-SP(A,S*2); Print(X); X = SP(BA,SB/4); X=X-SP(A/4,S); Print(X); diff --git a/extern/newmat/tmtk.cpp b/extern/newmat/tmtk.cpp index 4a57bc2..f1db617 100644 --- a/extern/newmat/tmtk.cpp +++ b/extern/newmat/tmtk.cpp @@ -61,7 +61,7 @@ void trymatk() A1.CleanUp(); B1.CleanUp(); cout << "LowerTriangularMatrix\n"; - LowerTriangularMatrix A2(35), B2(35); + LowerTriangularMatrix A2(35), B2(35); for (i=0; i<35; i++) for (j=0; j<=i; j++) { A2[i][j] = i+100*j; B2(i+1,j+1) = i+100*j; } X = A2 - B2; Print(X); Y = X; @@ -176,7 +176,7 @@ void trymatk() } Print(X); Print(Y); Aa.CleanUp(); Ba.CleanUp(); - + // test special constructors used in Numerical Recipes for C++ Real a[] = {1.2, 5.6, 7.9, 3.8, 4.5, 1.3, 5.2, 9.9, 2.1, 4.7, 0.0, 1.6 }; diff --git a/extern/newmat/tmtm.cpp b/extern/newmat/tmtm.cpp index 057a28c..9e103d6 100644 --- a/extern/newmat/tmtm.cpp +++ b/extern/newmat/tmtm.cpp @@ -264,7 +264,7 @@ void trymatm() M = AB; C -= M; Print(C); C << M; C += -M; Print(C); - + } @@ -272,8 +272,3 @@ void trymatm() ///@} - - - - - diff --git a/nanobind_migration_notes.md b/nanobind_migration_notes.md index ac2c1f0..7d34a76 100644 --- a/nanobind_migration_notes.md +++ b/nanobind_migration_notes.md @@ -6,6 +6,7 @@ gaps listed below — it is not "fully done" in the sense of zero open items.** What's done and verified: + - The C++ binding layer is fully ported from Boost.Python + SCons to nanobind + CMake + scikit-build-core. `src/pyobjcryst/*.py` (the pure-Python layer) and `tests/*.py` are untouched — nothing there is Boost.Python-specific. @@ -21,6 +22,7 @@ What's done and verified: - **161/161 tests pass** (`pytest tests/ -q`). Known, accepted gaps — real, not oversights, but still open: + - **Python-side method override does not work across the `RefinableObj` virtual-inheritance seam.** A Python subclass of `Atom`, `Molecule`, `ScatteringPowerAtom`, `DiffractionDataSingleCrystal`, `PowderPatternBackground`, etc. that overrides an inherited @@ -28,7 +30,7 @@ Known, accepted gaps — real, not oversights, but still open: C++-internal virtual dispatch — only plain forwarding calls were restored, not overridability. This was an explicit scope decision (general override support was confirmed not needed), not an oversight, but it is a real regression vs. Boost.Python's `bases`, which handled - this transparently. Override support that *does* still work: `RefinableObj`'s own ~15 virtuals + this transparently. Override support that _does_ still work: `RefinableObj`'s own ~15 virtuals when subclassing `RefinableObj` directly; `Scatterer`/`ScatteringPower`/`Restraint`'s own (non-inherited) virtuals; and `UpdateDisplay` specifically on `Crystal`, `PowderPattern`, and `MonteCarloObj` (all three reach `RefinableObj` through a non-virtual chain, so no seam exists @@ -153,18 +155,19 @@ after every test run — pre-existing, tracked in [Status](#status-2026-08-12) a ### Build troubleshooting -| Symptom | Cause | Fix | -|---|---|---| -| `nanobind not found` | not installed | `conda install nanobind` | -| `ObjCryst submodule empty` | not initialized | `git submodule update --init --recursive` | -| `version.h: No such file` | CMake config not run | `pip install -e . --no-build-isolation` | -| Segfault / bus error in a test | pointer-offset bug (virtual inheritance) | check whether the crashing class's C++ header declares `virtual` inheritance anywhere in its ancestry; see [Virtual Inheritance](#virtual-inheritance) | -| `RuntimeError: std::bad_cast`, no useful location | usually `nb::cast` on a `bytes` object | check every `.attr("read")()` call site — see [Python file-like input](#python-file-like-input-str-vs-bytes) | -| Binary needs a newer glibc than the host ships (`GLIBC_ABI_GNU2_TLS`) | conda-forge GCC's `gnu2` TLS dialect | build with the system compiler: `CC=/usr/bin/gcc CXX=/usr/bin/g++ pip install -e . --no-build-isolation` | -| gdb: `(no debugging symbols found)` | scikit-build-core strips symbols on install | `pip install -e . --no-build-isolation -Ccmake.define.CMAKE_BUILD_TYPE=RelWithDebInfo`, then copy the unstripped `.so` over the installed one | -| Values off in the last few digits | `REAL` (`ObjCryst/ObjCryst/General.h`) defaults to `float`; must be forced to `double` | confirm `CMakeLists.txt` sets `target_compile_definitions(ObjCryst PUBLIC REAL=double ...)`, and that any helper uses the `CrystVector_REAL`/`CrystMatrix_REAL` macros rather than a hardcoded ``/`` | +| Symptom | Cause | Fix | +| --------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `nanobind not found` | not installed | `conda install nanobind` | +| `ObjCryst submodule empty` | not initialized | `git submodule update --init --recursive` | +| `version.h: No such file` | CMake config not run | `pip install -e . --no-build-isolation` | +| Segfault / bus error in a test | pointer-offset bug (virtual inheritance) | check whether the crashing class's C++ header declares `virtual` inheritance anywhere in its ancestry; see [Virtual Inheritance](#virtual-inheritance) | +| `RuntimeError: std::bad_cast`, no useful location | usually `nb::cast` on a `bytes` object | check every `.attr("read")()` call site — see [Python file-like input](#python-file-like-input-str-vs-bytes) | +| Binary needs a newer glibc than the host ships (`GLIBC_ABI_GNU2_TLS`) | conda-forge GCC's `gnu2` TLS dialect | build with the system compiler: `CC=/usr/bin/gcc CXX=/usr/bin/g++ pip install -e . --no-build-isolation` | +| gdb: `(no debugging symbols found)` | scikit-build-core strips symbols on install | `pip install -e . --no-build-isolation -Ccmake.define.CMAKE_BUILD_TYPE=RelWithDebInfo`, then copy the unstripped `.so` over the installed one | +| Values off in the last few digits | `REAL` (`ObjCryst/ObjCryst/General.h`) defaults to `float`; must be forced to `double` | confirm `CMakeLists.txt` sets `target_compile_definitions(ObjCryst PUBLIC REAL=double ...)`, and that any helper uses the `CrystVector_REAL`/`CrystMatrix_REAL` macros rather than a hardcoded ``/`` | Useful gdb recipe for a segfault/bad_cast inside the extension: + ```bash gdb -q --args python -m pytest tests/test_whatever.py -k test_name (gdb) catch throw # for std::bad_cast / C++ exceptions @@ -182,7 +185,7 @@ or extending any class near `RefinableObj`, `Scatterer`, `ScatteringPower`, `Sca ### The core problem -ObjCryst++ uses *virtual* inheritance in several places: `Scatterer : virtual public +ObjCryst++ uses _virtual_ inheritance in several places: `Scatterer : virtual public RefinableObj`, `ScatteringPower : virtual public RefinableObj`, `ScatteringData : virtual public RefinableObj`, `PowderPatternComponent : virtual public RefinableObj`, and a second hop for `ScatteringPowerAtom : virtual public ScatteringPower` and `GlobalScatteringPower : virtual public @@ -190,8 +193,8 @@ ScatteringPower`. nanobind's automatic base↔derived pointer adjustment (used by `nb::class_(...)`) assumes a **fixed, statically computable** offset between `Derived*` and `Base*`. That's only -valid for *non-virtual* inheritance. Declaring the nanobind base across a virtual link does **not** -raise an error — it silently computes a *wrong* offset, which can look fine for fields at offset 0 +valid for _non-virtual_ inheritance. Declaring the nanobind base across a virtual link does **not** +raise an error — it silently computes a _wrong_ offset, which can look fine for fields at offset 0 and then segfault or return garbage the moment a method touching state further into the object is called. @@ -203,7 +206,7 @@ is fine and should still use nanobind's automatic base declaration (e.g. `Scatte public ScatteringPower`, no `virtual`, is safely `nb::class_`). -The same applies to *non-virtual multiple inheritance* where the base is not the first one, e.g. +The same applies to _non-virtual multiple inheritance_ where the base is not the first one, e.g. `TextureMarchDollase : public ScatteringCorr, public RefinableObj`: `RefinableObj` sits at a non-zero offset, and `nb::class_` silently returns garbage (`GetNbPar()` was 0). Register it standalone, call `bind_refinableobj_forwarding()`, and add it to @@ -224,14 +227,15 @@ nb::object wrapScatteringPowerReturn(const ScatteringPower* sp, nb::handle paren return nb::cast(const_cast(sp), nb::rv_policy::reference_internal, parent); } ``` -Applies even when the returned type is an *intermediate* base, not the ultimate leaf (e.g. + +Applies even when the returned type is an _intermediate_ base, not the ultimate leaf (e.g. `PowderPattern::GetPowderPatternComponent(i)` returns `PowderPatternComponent&`, whose dynamic type is `PowderPatternDiffraction`) — every function returning a shared ancestor type anywhere in a virtual hierarchy needs this, not just the one function returning the immediate leaf type. -**2. Argument direction** — a virtually-derived leaf is registered *without* a declared nanobind +**2. Argument direction** — a virtually-derived leaf is registered _without_ a declared nanobind base (per the rule above), so nanobind refuses it wherever a C++ function's parameter type is the -*base* (`void AddAtom(..., const ScatteringPower* pow, ...)` rejects a Python `ScatteringPowerAtom` +_base_ (`void AddAtom(..., const ScatteringPower* pow, ...)` rejects a Python `ScatteringPowerAtom` with `TypeError: incompatible function arguments`). Fix: accept `nb::object` and resolve manually, trying the concrete leaf type first: @@ -244,13 +248,13 @@ const ScatteringPower* extractScatteringPowerArg(nb::object obj) { ``` **3. Generic "any `RefinableObj`" argument functions** — the same argument-direction problem, but -for functions generic over *any* `RefinableObj` (`MonteCarloObj::AddRefinableObj`, +for functions generic over _any_ `RefinableObj` (`MonteCarloObj::AddRefinableObj`, `LSQNumObj::SetRefinedObj`, `RefinableObj::AddPar`): nanobind has no conversion path from a Python `DiffractionDataSingleCrystal`/`Atom`/`Molecule`/etc. to `RefinableObj&`, since none of those concrete classes declare that base. Fix: a shared helper (`extractRefinableObjArg`, in `helpers_nb.hpp`/`nb_refinableobj.cpp`) trying the safe cast first, then falling back through every known virtually-linked type with `static_cast` (always well-defined at compile time — the problem -is only ever nanobind's own *runtime* offset table, never a real `static_cast`): +is only ever nanobind's own _runtime_ offset table, never a real `static_cast`): ```cpp RefinableObj& extractRefinableObjArg(nb::object obj) { @@ -264,11 +268,12 @@ RefinableObj& extractRefinableObjArg(nb::object obj) { } ``` -**4. Under-declaring a *safe* base** — the mirror-image mistake: forgetting to declare a nanobind +**4. Under-declaring a _safe_ base** — the mirror-image mistake: forgetting to declare a nanobind base across a link that's perfectly safe (plain, non-virtual). Symptom looks identical -(`TypeError: incompatible function arguments`) but the cause is a *missing* declaration, not a +(`TypeError: incompatible function arguments`) but the cause is a _missing_ declaration, not a dangerous one. Fix: register the base type too (it needs no bindings of its own, just an internal name), then declare the relationship normally: + ```cpp nb::class_(m, "_PeakListBase"); // internal-only nb::class_(m, "PeakList"); // now declared @@ -287,28 +292,29 @@ Fix: two reusable template helpers in `helpers_nb.hpp`, `bind_refinableobj_forwa `bind_scatteringpower_forwarding()`, each binding one method-set's full surface via plain forwarding `.def()` calls (`&T::Method`, or a lambda for anything needing a helper/numpy conversion). This is safe despite the virtual base because `T` is fully known at compile time at -the call site, so the *compiler* resolves the pointer adjustment — exactly the mechanism +the call site, so the _compiler_ resolves the pointer adjustment — exactly the mechanism Boost.Python relied on, nothing to do with nanobind's own (virtual-base-unsafe) casting. Called once each in `nb_scatterer.cpp`, `nb_scatteringpower.cpp`, `nb_scatteringdata.cpp`, and `nb_powderpatterncomponent.cpp` (cascades automatically to every non-virtually-inherited child — `Atom`, `Molecule`, `ZScatterer`, `PowderPatternBackground`, `PowderPatternDiffraction`, etc. — via ordinary Python MRO); `ScatteringPowerAtom` and `GlobalScatteringPower` need both helpers called -directly on them, since they have a *second* virtual-inheritance hop of their own. +directly on them, since they have a _second_ virtual-inheritance hop of their own. **This restores callability, not overridability** — see [Status](#status-2026-08-12) for why that distinction matters and is a deliberate, accepted scope limit (nanobind's `NB_TRAMPOLINE` macro -requires its argument to be a *direct* base, a hard C++ rule that blocks chained/templated +requires its argument to be a _direct_ base, a hard C++ rule that blocks chained/templated trampolines the way pybind11 supports them — confirmed by compiler error in a standalone repro, not a nanobind design choice that could be worked around). Two real bugs turned up while adding test coverage for this fix, both worth remembering as general lessons: + - A binding that reaches a protected member via a trampoline/alias helper class (here, `PyScatterer::GetClockScattCompList()`, added to reach `Scatterer`'s protected `mClockScattCompList`) must take the **real base type** (`Scatterer&`) as its bound parameter, not the trampoline/alias type (`PyScatterer&`) — a plain `Atom`/`Molecule` instance is never actually constructed as the trampoline, so binding against the alias type raises `TypeError` for - every ordinary instance. Cast through the alias *inside* the lambda instead: + every ordinary instance. Cast through the alias _inside_ the lambda instead: ```cpp .def("GetClockScattCompList", [](Scatterer& s) -> const RefinableObjClock& { @@ -316,7 +322,7 @@ lessons: }, nb::rv_policy::reference_internal) ``` - `bind_scatteringpower_forwarding()` forwarded `GetBij`/`SetBij` but missed the `B11`/`B12`/ - `B13`/`B22`/`B23`/`B33`/`Biso` *properties* that `nb_scatteringpower.cpp` defines separately via + `B13`/`B22`/`B23`/`B33`/`Biso` _properties_ that `nb_scatteringpower.cpp` defines separately via file-local templates — a reminder that a forwarding helper needs to be checked against the full `dir()` of the canonical class, not just its method list, when a class also exposes properties. @@ -327,9 +333,11 @@ lessons: ### `None` argument handling nanobind rejects `None` by default for any typed `nb::arg`. Allow it explicitly: + ```cpp .def("AddScatterer", &Crystal::AddScatterer, nb::arg("pScatt").none(), nb::arg("ownsScatt") = true) ``` + `.none()` is required even for generic `nb::object` parameters — it isn't automatic just because the C++ parameter type is generic. @@ -338,6 +346,7 @@ the C++ parameter type is generic. `REAL* derivpar` in `RecUnitCell::hkl2d`) — nanobind's arithmetic `type_caster` rejects `None` outright before `.none()` on the outer `nb::arg` ever gets a chance to matter. Fix: wrap in a helper taking `nb::object` and bridge manually: + ```cpp float _hkl2d(const RecUnitCell& r, float h, float k, float l, nb::object derivpar, unsigned int derivhkl) { if (derivpar.is_none()) return r.hkl2d(h, k, l, nullptr, derivhkl); @@ -357,8 +366,8 @@ produce wrong-precision code. ### Lambda return type silently deduced by value A `.def(...)` that wraps a reference-returning helper in a lambda **without an explicit trailing -return type** deduces `auto`, which strips the reference and returns *by value* — silently -*copying* the object, even with `nb::rv_policy::reference_internal` set (that policy only controls +return type** deduces `auto`, which strips the reference and returns _by value_ — silently +_copying_ the object, even with `nb::rv_policy::reference_internal` set (that policy only controls how nanobind wraps whatever the lambda actually returns; it can't recover a reference from an already-copied value). This caused a real bug: `Molecule.AddRigidGroup`'s lambda copied the `RigidGroup` it had just added, so `Molecule.RemoveRigidGroup` (which finds the group to remove by @@ -377,18 +386,18 @@ confirmed by a plain, non-pytest script that creates a `Molecule`, calls `AddBon all references, and calls `gc.collect()` twice: still leaks 6 instances at exit. Root cause: nanobind types don't participate in Python's cyclic GC by default (no `tp_traverse`/`tp_clear`), so a bidirectional `keep_alive` between two live objects — parent keeps child alive (a `.def()` -declares `keep_alive<1,N>()`) *and* child keeps parent alive (a `.def()` returns via +declares `keep_alive<1,N>()`) _and_ child keeps parent alive (a `.def()` returns via `rv_policy::reference_internal`, nanobind's shorthand for `keep_alive<0,1>()`) — forms a cycle nothing can ever collect. Fixed for `Molecule`↔`MolAtom`: removed the redundant Molecule-keeps-atom direction from `AddBond`/`AddBondAngle`/`AddDihedralAngle` (safe because `MolAtom` has no standalone Python-owned existence — its only constructor is a copy constructor, so it's always reached via -`GetAtom()`/`AddAtom()`, which already protects it via the *other* direction). +`GetAtom()`/`AddAtom()`, which already protects it via the _other_ direction). **Not safe to fix the same way**, and still open: `Crystal`↔`Scatterer`/`Molecule`/ `ScatteringPower` (and possibly `RefinableObj`↔`RefinablePar`). Unlike `MolAtom`, these classes -*do* have real standalone Python-owned constructors (`sp = ScatteringPowerAtom("C", "C")` with no +_do_ have real standalone Python-owned constructors (`sp = ScatteringPowerAtom("C", "C")` with no parent) — the forward direction is protecting a real gap (between construction and being added to a `Crystal`, nothing else keeps the child's wrapper alive), so removing it would trade a leak for a use-after-free. The real fix is nanobind's `tp_traverse`/`tp_clear` mechanism, which likely requires @@ -402,6 +411,7 @@ the parent — that combination is the signature to look for. Any binding calling `.attr("read")()` on a caller-supplied Python object and casting straight to `std::string` breaks the moment the file was opened in binary mode (`.read()` returns `bytes`, `nb::cast` throws `std::bad_cast`). Use a shared helper: + ```cpp inline std::string read_pyfile_to_string(nb::object input) { nb::object data = input.attr("read")(); @@ -443,6 +453,7 @@ this fix unless it's re-applied or merged upstream. ## Binding Patterns Quick Reference **Simple class, no virtuals:** + ```cpp nb::class_(m, "MyClass") .def(nb::init<>()) @@ -451,8 +462,9 @@ nb::class_(m, "MyClass") ; ``` -**Class with overridable virtuals (trampoline) — only where `Base` is a *direct*, non-virtual +**Class with overridable virtuals (trampoline) — only where `Base` is a _direct_, non-virtual base of the trampoline, per [Virtual Inheritance](#virtual-inheritance):** + ```cpp struct PyMyClass : MyClass { NB_TRAMPOLINE(MyClass, 2); // 2 virtual methods @@ -463,6 +475,7 @@ nb::class_(m, "MyClass").def(nb::init<>()); ``` **String representation** (many ObjCryst objects have a useful `operator<<`): + ```cpp .def("__str__", [](const T& obj){ return obj_str(obj); }) // obj_str() in helpers_nb.hpp, mutes debug spam .def("__repr__", [](const T& obj){ return obj_str(obj); }) @@ -470,6 +483,7 @@ nb::class_(m, "MyClass").def(nb::init<>()); **Method overload resolution** — nanobind can't distinguish C++ overloads at binding time; use a lambda or a pointer-to-member-function cast: + ```cpp .def("SetX", nb::overload_cast(&T::SetX)) ``` @@ -482,13 +496,13 @@ handling, container conversion, lambda return types, `keep_alive`, and file-like ## Architecture Decisions -| Decision | Rationale | -|---|---| -| Single `_pyobjcryst` extension | simpler than per-class extensions; nanobind modules can be large | -| Static linking (newmat, cctbx, ObjCryst) | avoids runtime library conflicts on Windows/macOS wheels | -| scikit-build-core + CMake | modern standard for C++ Python extensions, replaces SCons | -| ObjCryst++ as a submodule | tracks upstream, simpler than a fork | -| Vendored newmat/cctbx (not conda-forge `cctbx-base`) | see below | +| Decision | Rationale | +| ---------------------------------------------------- | ---------------------------------------------------------------- | +| Single `_pyobjcryst` extension | simpler than per-class extensions; nanobind modules can be large | +| Static linking (newmat, cctbx, ObjCryst) | avoids runtime library conflicts on Windows/macOS wheels | +| scikit-build-core + CMake | modern standard for C++ Python extensions, replaces SCons | +| ObjCryst++ as a submodule | tracks upstream, simpler than a fork | +| Vendored newmat/cctbx (not conda-forge `cctbx-base`) | see below | **Vendored `cctbx` vs. conda-forge's `cctbx-base`** (investigated, not adopted): `cctbx-base` does contain the right modules, compiled and working, but isn't structured for third-party C++ @@ -505,17 +519,19 @@ depending on `cctbx-base` as it currently ships. ## Pitfalls Checklist **Before writing/extending a binding for class `X`:** + - [ ] Grep `X`'s header and its whole ancestry (not just the direct parent) for `: *virtual - public` — if found, do **not** declare that base in `nb::class_`; use the manual + public` — if found, do **not** declare that base in `nb::class_`; use the manual `dynamic_cast`/`nb::cast` patterns instead **While writing:** + - [ ] Every optional pointer/object argument needs `.none()` on its `nb::arg(...)`, including plain `nb::object` params — except pointers to a plain arithmetic type, where `.none()` has no effect; wrap those in an `nb::object`-taking helper instead - [ ] Every function returning a base-typed reference/pointer whose dynamic type is commonly a virtually-derived leaf needs the `dynamic_cast`-and-recast treatment -- [ ] Every function generically *accepting* a base type as an argument needs its argument routed +- [ ] Every function generically _accepting_ a base type as an argument needs its argument routed through a helper like `extractRefinableObjArg()` - [ ] Any `.def(...)` combining a lambda with `nb::rv_policy::reference`/`reference_internal` needs an explicit `-> T&`/`-> T*` trailing return type on the lambda @@ -524,10 +540,11 @@ depending on `cctbx-base` as it currently ships. - [ ] Any container type (`CrystVector`, `CrystMatrix`) crossing the boundary should use the `CrystVector_REAL`/`CrystMatrix_REAL` macros, never a hardcoded ``/`` - [ ] A binding reaching a protected/private member via a trampoline/alias helper class must take - the *real* base type as its bound parameter, not the trampoline/alias type — otherwise it + the _real_ base type as its bound parameter, not the trampoline/alias type — otherwise it raises `TypeError` on every instance not literally constructed as that alias **After writing, before declaring done:** + - [ ] Rebuilt and re-ran the specific test file, then the full suite, and confirmed no new failures - [ ] If the class exposes properties as well as methods, checked the forwarding/coverage against the full `dir()` of the canonical class, not just its method list diff --git a/tests/test_lsq.py b/tests/test_lsq.py index 0618d83..687ab2d 100644 --- a/tests/test_lsq.py +++ b/tests/test_lsq.py @@ -94,7 +94,8 @@ def test_lsq_refine(self): lsq.Refine(10, False, True) def test_lsq_compiled_refined_obj_erase_all_param_set(self): - """Check parameter sets can be erased on compiled refined objects.""" + """Check parameter sets can be erased on compiled refined + objects.""" lsq = LSQ() lsq.SetRefinedObj(self.d, 0, True, True) lsq.PrepareRefParList() @@ -104,7 +105,8 @@ def test_lsq_compiled_refined_obj_erase_all_param_set(self): self.assertRaises(ObjCrystException, refobj.SaveParamSet, save) def test_lsq_get_variance_covariance_map(self): - """GetVarianceCovarianceMap returns a dict keyed by (name, name) tuples.""" + """GetVarianceCovarianceMap returns a dict keyed by (name, name) + tuples.""" lsq = LSQ() lsq.SetRefinedObj(self.d, 0, True, True) lsq.PrepareRefParList() @@ -137,7 +139,7 @@ def test_lsq_get_rw_history(self): self.assertGreaterEqual(v, 0.0) def test_lsq_refine_minrwpvar(self): - """minRwpVar argument is accepted by Refine without error.""" + """MinRwpVar argument is accepted by Refine without error.""" lsq = LSQ() lsq.SetRefinedObj(self.d, 0, True, True) lsq.PrepareRefParList() @@ -155,4 +157,3 @@ def test_lsq_prepare_ref_par_list_verbose(self): if __name__ == "__main__": unittest.main() - diff --git a/tests/test_powderpattern.py b/tests/test_powderpattern.py index 44531d6..84fd164 100644 --- a/tests/test_powderpattern.py +++ b/tests/test_powderpattern.py @@ -369,16 +369,18 @@ def test_update_nbrefl(self): class _PowderPatternComponentFixtureMixin: - """Shared setUp for the three test classes below: a PowderPattern with - one real PowderPatternBackground and one real PowderPatternDiffraction - attached, mirroring TestPowderPattern.test_GetClassName's setup. Both - PowderPatternComponent and ScatteringData inherit RefinableObj virtually - in C++ (and PowderPatternDiffraction inherits PowderPatternComponent - virtually *again*, on top of ScatteringData non-virtually) -- see - nanobind_migration_notes.md's "Follow-up" section -- so neither class is - directly instantiable from Python; these fixtures exercise the - forwarding fix through real, concrete PowderPatternComponent-family - objects instead. + """Shared setUp for the three test classes below: a PowderPattern + with one real PowderPatternBackground and one real + PowderPatternDiffraction attached, mirroring + TestPowderPattern.test_GetClassName's setup. + + Both PowderPatternComponent and ScatteringData inherit RefinableObj + virtually in C++ (and PowderPatternDiffraction inherits + PowderPatternComponent virtually *again*, on top of ScatteringData + non-virtually) -- see nanobind_migration_notes.md's "Follow-up" + section -- so neither class is directly instantiable from Python; + these fixtures exercise the forwarding fix through real, concrete + PowderPatternComponent-family objects instead. """ @pytest.fixture(autouse=True) @@ -396,7 +398,9 @@ def setUp(self): self.diff = self.pp.AddPowderPatternDiffraction(c) -class TestPowderPatternComponent(_PowderPatternComponentFixtureMixin, unittest.TestCase): +class TestPowderPatternComponent( + _PowderPatternComponentFixtureMixin, unittest.TestCase +): def test_GetParentPowderPattern(self): self.assertIs(self.pp, self.bg.GetParentPowderPattern()) @@ -404,9 +408,10 @@ def test_GetParentPowderPattern(self): def test_refinableobj_forwarding(self): """PowderPatternComponent inherits RefinableObj virtually; only - GetName/SetName/GetClassName/FixAllPar/UnFixAllPar were reachable - before the forwarding fix (see test_GetClassName above, which - covers GetClassName specifically) -- exercise the rest here.""" + GetName/SetName/GetClassName/FixAllPar/UnFixAllPar were + reachable before the forwarding fix (see test_GetClassName + above, which covers GetClassName specifically) -- exercise the + rest here.""" self.bg.SetName("mybg") self.assertEqual("mybg", self.bg.GetName()) self.bg.FixAllPar() @@ -422,7 +427,9 @@ def test_refinableobj_forwarding(self): # ---------------------------------------------------------------------------- -class TestPowderPatternBackground(_PowderPatternComponentFixtureMixin, unittest.TestCase): +class TestPowderPatternBackground( + _PowderPatternComponentFixtureMixin, unittest.TestCase +): # def test___init__(self): assert False # def test_FixParametersBeyondMaxresolution(self): assert False # def test_GetPowderPatternCalc(self): assert False @@ -444,7 +451,9 @@ def test_refinableobj_forwarding(self): # ---------------------------------------------------------------------------- -class TestPowderPatternDiffraction(_PowderPatternComponentFixtureMixin, unittest.TestCase): +class TestPowderPatternDiffraction( + _PowderPatternComponentFixtureMixin, unittest.TestCase +): # def test___init__(self): assert False # def test_ExtractLeBail(self): assert False # def test_GetExtractionMode(self): assert False @@ -456,10 +465,10 @@ class TestPowderPatternDiffraction(_PowderPatternComponentFixtureMixin, unittest # def test_SetReflectionProfilePar(self): assert False def test_refinableobj_forwarding(self): - """PowderPatternDiffraction reaches RefinableObj via ScatteringData - (non-virtual, already a correct nanobind base) -- confirm the - forwarding applied to ScatteringData actually cascades here rather - than assuming it does.""" + """PowderPatternDiffraction reaches RefinableObj via + ScatteringData (non-virtual, already a correct nanobind base) -- + confirm the forwarding applied to ScatteringData actually + cascades here rather than assuming it does.""" self.diff.FixAllPar() self.diff.UnFixAllPar() self.assertEqual(0.0, self.diff.GetLogLikelihood()) diff --git a/tests/test_refinableobj.py b/tests/test_refinableobj.py index e5b71e5..087b3fe 100644 --- a/tests/test_refinableobj.py +++ b/tests/test_refinableobj.py @@ -425,7 +425,9 @@ def test_xml(self): def test_xml_output_input_reachable(self): """XMLOutput/XMLInput were dropped from the nanobind port's - method-forwarding audit alongside the LSQ methods below. Note + method-forwarding audit alongside the LSQ methods below. + + Note RefinableObj's own C++ base implementation is a documented no-op ("Does nothing! Should be purely virtual...", see RefinableObj/IO.cpp) -- real content only appears once a concrete @@ -434,7 +436,8 @@ def test_xml_output_input_reachable(self): file-like object, exercised on concrete subclasses that do override XMLOutput/XMLInput with real behaviour, live in test_scatterer.py (Atom), test_powderpattern.py (PowderPatternBackground) and - test_single_crystal_data.py (DiffractionDataSingleCrystal).""" + test_single_crystal_data.py (DiffractionDataSingleCrystal). + """ import io buf = io.StringIO() diff --git a/tests/test_reflectionprofile.py b/tests/test_reflectionprofile.py index 067e165..a3b1eeb 100644 --- a/tests/test_reflectionprofile.py +++ b/tests/test_reflectionprofile.py @@ -130,8 +130,8 @@ def test_is_anisotropic(self): self.assertFalse(self.profile.IsAnisotropic()) def test_concrete_pseudo_voigt_profiles(self): - """ReflectionProfilePseudoVoigt and Anisotropic can be constructed - and installed on a PowderPatternDiffraction.""" + """ReflectionProfilePseudoVoigt and Anisotropic can be + constructed and installed on a PowderPatternDiffraction.""" iso = ReflectionProfilePseudoVoigt() self.assertFalse(iso.IsAnisotropic()) self.assertTrue( @@ -152,7 +152,9 @@ def test_concrete_pseudo_voigt_profiles(self): aniso.SetProfilePar(fwhmCagliotiW=1e-4) self.ppd.SetProfile(aniso) installed_aniso = self.ppd.GetProfile() - self.assertIsInstance(installed_aniso, ReflectionProfilePseudoVoigtAnisotropic) + self.assertIsInstance( + installed_aniso, ReflectionProfilePseudoVoigtAnisotropic + ) def test_tch_profile_width_and_limits(self): """TCH derives one common FWHM and reaches both pure limits.""" diff --git a/tests/test_scatterer.py b/tests/test_scatterer.py index c68c89c..d2abece 100644 --- a/tests/test_scatterer.py +++ b/tests/test_scatterer.py @@ -1,10 +1,11 @@ #!/usr/bin/env python """Functional tests for the RefinableObj/ScatteringPower method surface restored on Scatterer/ScatteringPowerAtom (see -nanobind_migration_notes.md's "Follow-up: restoring RefinableObj's method -surface on virtually-inherited classes"; presence-only coverage across every -affected class lives in test_virtualbase_forwarding.py). These exercise the -actual behaviour, not just that the method exists. +nanobind_migration_notes.md's "Follow-up: restoring RefinableObj's +method surface on virtually-inherited classes"; presence-only coverage +across every affected class lives in test_virtualbase_forwarding.py). + +These exercise the actual behaviour, not just that the method exists. """ import io @@ -17,7 +18,8 @@ class TestScattererForwarding(unittest.TestCase): - """Atom reaches RefinableObj only through Scatterer's C++ virtual base.""" + """Atom reaches RefinableObj only through Scatterer's C++ virtual + base.""" def setUp(self): self.sp, self.atom = makeScatterer() @@ -62,9 +64,10 @@ def test_update_display(self): self.atom.UpdateDisplay() def test_get_clock_scatt_comp_list(self): - """Forwards a *protected* Scatterer member (mClockScattCompList); - unrelated to the virtual-inheritance issue (it's a plain omission) - but fixed in the same pass -- see PyScatterer in nb_scatterer.cpp.""" + """Forwards a *protected* Scatterer member + (mClockScattCompList); unrelated to the virtual-inheritance + issue (it's a plain omission) but fixed in the same pass -- see + PyScatterer in nb_scatterer.cpp.""" clock = self.atom.GetClockScattCompList() self.assertIsInstance(clock, RefinableObjClock) @@ -86,9 +89,10 @@ def test_create_param_set_roundtrip(self): class TestScatteringPowerAtomForwarding(unittest.TestCase): """ScatteringPowerAtom inherits ScatteringPower virtually, and - ScatteringPower inherits RefinableObj virtually too -- a second hop, so - both bind_refinableobj_forwarding() and - bind_scatteringpower_forwarding() had to be applied directly to it.""" + ScatteringPower inherits RefinableObj virtually too -- a second hop, + so both bind_refinableobj_forwarding() and + bind_scatteringpower_forwarding() had to be applied directly to + it.""" def setUp(self): self.sp, self.atom = makeScatterer() @@ -105,8 +109,9 @@ def test_log_likelihood(self): self.assertEqual(0.0, self.sp.GetLogLikelihood()) def test_scatteringpower_own_methods_forwarded(self): - """These are ScatteringPower's *own* methods (not RefinableObj's), - forwarded via bind_scatteringpower_forwarding().""" + """These are ScatteringPower's *own* methods (not + RefinableObj's), forwarded via + bind_scatteringpower_forwarding().""" self.assertGreaterEqual(self.sp.GetDynPopCorrIndex(), 0) self.assertIsNotNone(self.sp.GetLastChangeClock()) r, g, b = self.sp.GetColourRGB() @@ -114,8 +119,9 @@ def test_scatteringpower_own_methods_forwarded(self): def test_lsq_methods_reachable_and_raise_when_unset(self): """Ported forward alongside the forwarding fix: GetLSQCalc/Obs/ - Weight/Deriv exist on RefinableObj and are therefore forwarded here - too, even though nothing has configured a custom LSQ target.""" + Weight/Deriv exist on RefinableObj and are therefore forwarded + here too, even though nothing has configured a custom LSQ + target.""" with self.assertRaises(ObjCrystException): self.sp.GetLSQCalc(0) diff --git a/tests/test_virtualbase_forwarding.py b/tests/test_virtualbase_forwarding.py index c497f29..be32f2b 100644 --- a/tests/test_virtualbase_forwarding.py +++ b/tests/test_virtualbase_forwarding.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -"""Coverage guard for the RefinableObj/ScatteringPower method-forwarding fix. +"""Coverage guard for the RefinableObj/ScatteringPower method-forwarding +fix. Scatterer, ScatteringPower, ScatteringData, and PowderPatternComponent all inherit RefinableObj *virtually* in C++, so nanobind cannot declare @@ -46,8 +47,8 @@ def _public_methods(cls): class TestRefinableObjSurfaceForwarding(unittest.TestCase): - """Every RefinableObj method must be reachable on the four classes that - only reach RefinableObj through a C++ virtual base.""" + """Every RefinableObj method must be reachable on the four classes + that only reach RefinableObj through a C++ virtual base.""" def _assert_full_coverage(self, cls): missing = [m for m in REFINABLEOBJ_METHODS if not hasattr(cls, m)] @@ -108,9 +109,10 @@ def test_globalscatteringpower(self): class TestScatteringPowerSurfaceForwarding(unittest.TestCase): - """ScatteringPowerAtom and GlobalScatteringPower need ScatteringPower's - own method surface (GetScatteringFactor, GetBij/SetBij, GetColour, ...) - forwarded too, on top of RefinableObj's.""" + """ScatteringPowerAtom and GlobalScatteringPower need + ScatteringPower's own method surface (GetScatteringFactor, + GetBij/SetBij, GetColour, ...) forwarded too, on top of + RefinableObj's.""" def _assert_full_coverage(self, cls): missing = [m for m in SCATTERINGPOWER_METHODS if not hasattr(cls, m)] From cccdabe1656cb285539d122998e8286b95ecd984 Mon Sep 17 00:00:00 2001 From: Vincent Favre-Nicolin Date: Tue, 3 Nov 2026 12:09:17 +0100 Subject: [PATCH 3/7] ci: check out submodules and exclude vendored extern/ from pre-commit - Pass submodules: 'true' to the scikit-package reusable workflows, so that extern/objcryst is available when building. - Exclude extern/ (objcryst submodule, vendored cctbx and newmat) from pre-commit hooks. - Remove duplicated test_lsq_compiled_refined_obj_erase_all_param_set (F811) and fix a typo flagged by codespell. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../workflows/build-and-publish-docs-on-dispatch.yml | 1 + .github/workflows/build-wheel-release-upload.yml | 1 + .github/workflows/matrix-and-codecov.yml | 1 + .github/workflows/tests-on-pr.yml | 1 + .pre-commit-config.yaml | 2 ++ src/extensions/nb_indexing.cpp | 2 +- tests/test_lsq.py | 11 ----------- 7 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-and-publish-docs-on-dispatch.yml b/.github/workflows/build-and-publish-docs-on-dispatch.yml index a60668b..b71edd5 100644 --- a/.github/workflows/build-and-publish-docs-on-dispatch.yml +++ b/.github/workflows/build-and-publish-docs-on-dispatch.yml @@ -13,6 +13,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_release-docs.yml@v0 with: project: pyobjcryst + submodules: 'true' c_extension: true headless: false python_version: ${{ fromJSON(needs.get-python-version.outputs.latest_python_version) }} diff --git a/.github/workflows/build-wheel-release-upload.yml b/.github/workflows/build-wheel-release-upload.yml index 396b9ec..b93cbf3 100644 --- a/.github/workflows/build-wheel-release-upload.yml +++ b/.github/workflows/build-wheel-release-upload.yml @@ -27,6 +27,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_build-wheel-release-upload.yml@v0 with: project: pyobjcryst + submodules: 'true' c_extension: true maintainer_github_username: sbillinge secrets: diff --git a/.github/workflows/matrix-and-codecov.yml b/.github/workflows/matrix-and-codecov.yml index 9a3b8e2..867695f 100644 --- a/.github/workflows/matrix-and-codecov.yml +++ b/.github/workflows/matrix-and-codecov.yml @@ -15,6 +15,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0 with: project: pyobjcryst + submodules: 'true' c_extension: true headless: false secrets: diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml index 6293743..a369e9f 100644 --- a/.github/workflows/tests-on-pr.yml +++ b/.github/workflows/tests-on-pr.yml @@ -9,6 +9,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_tests-on-pr.yml@v0 with: project: pyobjcryst + submodules: 'true' c_extension: true headless: false secrets: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b60917a..928eb99 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,5 @@ +# Vendored third-party sources (objcryst submodule, cctbx, newmat) +exclude: '^extern/' default_language_version: python: python3 ci: diff --git a/src/extensions/nb_indexing.cpp b/src/extensions/nb_indexing.cpp index e06ace5..44bf2a3 100644 --- a/src/extensions/nb_indexing.cpp +++ b/src/extensions/nb_indexing.cpp @@ -30,7 +30,7 @@ namespace { // with "incompatible function arguments", even though None is exactly what a // Python caller must pass (a Python float is immutable, so there is no way for // the derivative to be written back to it regardless of binding technology -- -// this matches the pre-existing Boost.Python behavor, where derivpar was only +// this matches the pre-existing Boost.Python behavior, where derivpar was only // ever meaningfully used from within C++ itself, e.g. LSQ fitting internals). // Fixed by taking derivpar as nb::object and manually bridging None -> nullptr. float _hkl2d(const RecUnitCell& r, const float h, const float k, const float l, diff --git a/tests/test_lsq.py b/tests/test_lsq.py index 687ab2d..99730d2 100644 --- a/tests/test_lsq.py +++ b/tests/test_lsq.py @@ -93,17 +93,6 @@ def test_lsq_refine(self): self.c.RandomizeConfiguration() lsq.Refine(10, False, True) - def test_lsq_compiled_refined_obj_erase_all_param_set(self): - """Check parameter sets can be erased on compiled refined - objects.""" - lsq = LSQ() - lsq.SetRefinedObj(self.d, 0, True, True) - lsq.PrepareRefParList() - refobj = lsq.GetCompiledRefinedObj() - save = refobj.CreateParamSet("save") - refobj.EraseAllParamSet() - self.assertRaises(ObjCrystException, refobj.SaveParamSet, save) - def test_lsq_get_variance_covariance_map(self): """GetVarianceCovarianceMap returns a dict keyed by (name, name) tuples.""" From fae5def85f497147fa2182a433916b1e53c5bffc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:09:34 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit hooks --- .github/workflows/build-and-publish-docs-on-dispatch.yml | 2 +- .github/workflows/build-wheel-release-upload.yml | 2 +- .github/workflows/matrix-and-codecov.yml | 2 +- .github/workflows/tests-on-pr.yml | 2 +- .pre-commit-config.yaml | 2 +- nanobind_migration_notes.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-publish-docs-on-dispatch.yml b/.github/workflows/build-and-publish-docs-on-dispatch.yml index b71edd5..1be1b4f 100644 --- a/.github/workflows/build-and-publish-docs-on-dispatch.yml +++ b/.github/workflows/build-and-publish-docs-on-dispatch.yml @@ -13,7 +13,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_release-docs.yml@v0 with: project: pyobjcryst - submodules: 'true' + submodules: "true" c_extension: true headless: false python_version: ${{ fromJSON(needs.get-python-version.outputs.latest_python_version) }} diff --git a/.github/workflows/build-wheel-release-upload.yml b/.github/workflows/build-wheel-release-upload.yml index b93cbf3..42b91f7 100644 --- a/.github/workflows/build-wheel-release-upload.yml +++ b/.github/workflows/build-wheel-release-upload.yml @@ -27,7 +27,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_build-wheel-release-upload.yml@v0 with: project: pyobjcryst - submodules: 'true' + submodules: "true" c_extension: true maintainer_github_username: sbillinge secrets: diff --git a/.github/workflows/matrix-and-codecov.yml b/.github/workflows/matrix-and-codecov.yml index 867695f..f02cc91 100644 --- a/.github/workflows/matrix-and-codecov.yml +++ b/.github/workflows/matrix-and-codecov.yml @@ -15,7 +15,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0 with: project: pyobjcryst - submodules: 'true' + submodules: "true" c_extension: true headless: false secrets: diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml index a369e9f..2480080 100644 --- a/.github/workflows/tests-on-pr.yml +++ b/.github/workflows/tests-on-pr.yml @@ -9,7 +9,7 @@ jobs: uses: scikit-package/release-scripts/.github/workflows/_tests-on-pr.yml@v0 with: project: pyobjcryst - submodules: 'true' + submodules: "true" c_extension: true headless: false secrets: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 928eb99..beb8815 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ # Vendored third-party sources (objcryst submodule, cctbx, newmat) -exclude: '^extern/' +exclude: "^extern/" default_language_version: python: python3 ci: diff --git a/nanobind_migration_notes.md b/nanobind_migration_notes.md index 7d34a76..8f085d3 100644 --- a/nanobind_migration_notes.md +++ b/nanobind_migration_notes.md @@ -521,7 +521,7 @@ depending on `cctbx-base` as it currently ships. **Before writing/extending a binding for class `X`:** - [ ] Grep `X`'s header and its whole ancestry (not just the direct parent) for `: *virtual - public` — if found, do **not** declare that base in `nb::class_`; use the manual + public` — if found, do **not** declare that base in `nb::class_`; use the manual `dynamic_cast`/`nb::cast` patterns instead **While writing:** From d21cd1dc3aa2f8add07748e360d94a451c873cbe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:16:21 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit hooks --- nanobind_migration_notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nanobind_migration_notes.md b/nanobind_migration_notes.md index 8f085d3..1d0f939 100644 --- a/nanobind_migration_notes.md +++ b/nanobind_migration_notes.md @@ -521,7 +521,7 @@ depending on `cctbx-base` as it currently ships. **Before writing/extending a binding for class `X`:** - [ ] Grep `X`'s header and its whole ancestry (not just the direct parent) for `: *virtual - public` — if found, do **not** declare that base in `nb::class_`; use the manual +public` — if found, do **not** declare that base in `nb::class_`; use the manual `dynamic_cast`/`nb::cast` patterns instead **While writing:** From d3b57d9dbd10e5f3a4ca979aae63b16af3279f02 Mon Sep 17 00:00:00 2001 From: Vincent Favre-Nicolin Date: Tue, 3 Nov 2026 12:17:31 +0100 Subject: [PATCH 6/7] docs: keep inline code on one line so prettier output is stable Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- nanobind_migration_notes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nanobind_migration_notes.md b/nanobind_migration_notes.md index 1d0f939..57eb662 100644 --- a/nanobind_migration_notes.md +++ b/nanobind_migration_notes.md @@ -520,9 +520,9 @@ depending on `cctbx-base` as it currently ships. **Before writing/extending a binding for class `X`:** -- [ ] Grep `X`'s header and its whole ancestry (not just the direct parent) for `: *virtual -public` — if found, do **not** declare that base in `nb::class_`; use the manual - `dynamic_cast`/`nb::cast` patterns instead +- [ ] Grep `X`'s header and its whole ancestry (not just the direct parent) for + `: *virtual public` — if found, do **not** declare that base in + `nb::class_`; use the manual `dynamic_cast`/`nb::cast` patterns instead **While writing:** From 12c52a4895fc9d47bcf48eaee3a429c453915eee Mon Sep 17 00:00:00 2001 From: Vincent Favre-Nicolin Date: Tue, 3 Nov 2026 12:35:31 +0100 Subject: [PATCH 7/7] revert: restore vendored extern/ sources modified by pre-commit.ci autofix Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../scitbx/array_family/small_reductions.h | 1 + .../scitbx/array_family/tiny_reductions.h | 1 + extern/newmat/Makefile.in | 1 + extern/newmat/_newmat.dox | 5 + extern/newmat/_rbd_com.dox | 5 + extern/newmat/bandmat.cpp | 8 +- extern/newmat/cholesky.cpp | 12 +- extern/newmat/controlw.h | 1 + extern/newmat/evalue.cpp | 7 +- extern/newmat/example.cpp | 8 +- extern/newmat/example.txt | 116 +- extern/newmat/garch.cpp | 2 +- extern/newmat/garch.dat | 1001 +- extern/newmat/garch.txt | 26 +- extern/newmat/hholder.cpp | 36 +- extern/newmat/include.h | 3 +- extern/newmat/myexcept.cpp | 3 +- extern/newmat/myexcept.h | 1 + extern/newmat/newfft.cpp | 1 + extern/newmat/newmat.h | 14 +- extern/newmat/newmat1.cpp | 8 +- extern/newmat/newmat4.cpp | 30 +- extern/newmat/newmat5.cpp | 18 +- extern/newmat/newmat6.cpp | 4 +- extern/newmat/newmat7.cpp | 3 +- extern/newmat/newmat8.cpp | 4 +- extern/newmat/newmatap.h | 16 +- extern/newmat/newmatex.cpp | 1 + extern/newmat/newmatnl.cpp | 4 +- extern/newmat/newmatnl.h | 3 +- extern/newmat/newmatrm.cpp | 2 +- extern/newmat/newmatrm.h | 4 +- extern/newmat/nl_ex.cpp | 7 +- extern/newmat/nl_ex.txt | 31 +- extern/newmat/nm11.htm | 11478 +++++++--------- extern/newmat/nm_b55.mak | 3 +- extern/newmat/nm_b56.mak | 3 +- extern/newmat/nm_cc.mak | 7 +- extern/newmat/nm_ex1.cpp | 11 +- extern/newmat/nm_ex1.txt | 25 +- extern/newmat/nm_ex2.cpp | 16 +- extern/newmat/nm_ex2.txt | 71 +- extern/newmat/nm_ex3.cpp | 23 +- extern/newmat/nm_ex3.txt | 19 +- extern/newmat/nm_gnu.mak | 3 +- extern/newmat/nm_i10.mak | 5 +- extern/newmat/nm_i8.mak | 3 +- extern/newmat/nm_il8.mak | 3 +- extern/newmat/nm_m6.mak | 3 +- extern/newmat/nm_m8.mak | 3 +- extern/newmat/nm_misc.cpp | 8 +- extern/newmat/nm_ow.mak | 3 +- extern/newmat/precisio.h | 4 +- extern/newmat/rbd.css | 98 +- extern/newmat/readme.txt | 2 + extern/newmat/sl_ex.cpp | 4 +- extern/newmat/solution.h | 1 + extern/newmat/submat.cpp | 7 +- extern/newmat/test_exc.txt | 3 +- extern/newmat/tmt.cpp | 17 +- extern/newmat/tmt.h | 10 +- extern/newmat/tmt.txt | 183 +- extern/newmat/tmt1.cpp | 30 +- extern/newmat/tmt2.cpp | 10 +- extern/newmat/tmt4.cpp | 36 +- extern/newmat/tmt6.cpp | 2 +- extern/newmat/tmt7.cpp | 46 +- extern/newmat/tmt8.cpp | 4 +- extern/newmat/tmt9.cpp | 20 +- extern/newmat/tmtc.cpp | 74 +- extern/newmat/tmtd.cpp | 66 +- extern/newmat/tmte.cpp | 2 +- extern/newmat/tmtf.cpp | 6 +- extern/newmat/tmth.cpp | 36 +- extern/newmat/tmti.cpp | 1 + extern/newmat/tmtj.cpp | 2 +- extern/newmat/tmtk.cpp | 4 +- extern/newmat/tmtm.cpp | 7 +- 78 files changed, 5907 insertions(+), 7842 deletions(-) diff --git a/extern/cctbx/include/scitbx/array_family/small_reductions.h b/extern/cctbx/include/scitbx/array_family/small_reductions.h index 8cb297e..740ce39 100644 --- a/extern/cctbx/include/scitbx/array_family/small_reductions.h +++ b/extern/cctbx/include/scitbx/array_family/small_reductions.h @@ -152,3 +152,4 @@ namespace scitbx { namespace af { #endif // DOXYGEN_SHOULD_SKIP_THIS #endif // SCITBX_ARRAY_FAMILY_SMALL_REDUCTIONS_H + diff --git a/extern/cctbx/include/scitbx/array_family/tiny_reductions.h b/extern/cctbx/include/scitbx/array_family/tiny_reductions.h index 87f372a..f221b13 100644 --- a/extern/cctbx/include/scitbx/array_family/tiny_reductions.h +++ b/extern/cctbx/include/scitbx/array_family/tiny_reductions.h @@ -152,3 +152,4 @@ namespace scitbx { namespace af { #endif // DOXYGEN_SHOULD_SKIP_THIS #endif // SCITBX_ARRAY_FAMILY_TINY_REDUCTIONS_H + diff --git a/extern/newmat/Makefile.in b/extern/newmat/Makefile.in index 746fa24..23f623c 100644 --- a/extern/newmat/Makefile.in +++ b/extern/newmat/Makefile.in @@ -113,3 +113,4 @@ submat.o: $(newmatxx) $(srcdir)/newmatrc.h $(srcdir)/controlw.h $(srcdir)/su svd.o: $(newmatxx) $(srcdir)/newmatrm.h $(srcdir)/precisio.h $(srcdir)/svd.cpp $(CXX) $(CXXFLAGS) $(OPT++DEFINES) $(OPT++INCLUDES) $(srcdir)/svd.cpp + diff --git a/extern/newmat/_newmat.dox b/extern/newmat/_newmat.dox index 094eaa5..9318ab1 100644 --- a/extern/newmat/_newmat.dox +++ b/extern/newmat/_newmat.dox @@ -22,3 +22,8 @@ ///rather inefficient. ///@} + + + + + diff --git a/extern/newmat/_rbd_com.dox b/extern/newmat/_rbd_com.dox index b904c7d..4ddf908 100644 --- a/extern/newmat/_rbd_com.dox +++ b/extern/newmat/_rbd_com.dox @@ -19,3 +19,8 @@ ///@} + + + + + diff --git a/extern/newmat/bandmat.cpp b/extern/newmat/bandmat.cpp index db325f8..8d91526 100644 --- a/extern/newmat/bandmat.cpp +++ b/extern/newmat/bandmat.cpp @@ -284,8 +284,8 @@ GeneralMatrix* BandLUMatrix::Evaluate(MatrixType mt) // could we use SetParameters instead of this void BandLUMatrix::get_aux(BandLUMatrix& X) { - X.d = d; X.sing = sing; X.storage2 = storage2; X.m1 = m1; X.m2 = m2; - if (tag_val == 0 || tag_val == 1) // reuse the array + X.d = d; X.sing = sing; X.storage2 = storage2; X.m1 = m1; X.m2 = m2; + if (tag_val == 0 || tag_val == 1) // reuse the array { REPORT X.indx = indx; indx = 0; @@ -333,7 +333,7 @@ void BandLUMatrix::operator=(const BandLUMatrix& gm) ((BandLUMatrix&)gm).get_aux(*this); Eq(gm); } - + @@ -714,3 +714,5 @@ Real SymmetricBandMatrix::sum() const #endif ///@} + + diff --git a/extern/newmat/cholesky.cpp b/extern/newmat/cholesky.cpp index d8c4eaf..e0df0fa 100644 --- a/extern/newmat/cholesky.cpp +++ b/extern/newmat/cholesky.cpp @@ -104,7 +104,7 @@ void update_Cholesky(UpperTriangularMatrix &chol, RowVector x) int nc = chol.Nrows(); ColumnVector cGivens(nc); cGivens = 0.0; ColumnVector sGivens(nc); sGivens = 0.0; - + for(int j = 1; j <= nc; ++j) // process the jth column of chol { // apply the previous Givens rotations k = 1,...,j-1 to column j @@ -129,12 +129,12 @@ void update_Cholesky(UpperTriangularMatrix &chol, RowVector x) void downdate_Cholesky(UpperTriangularMatrix &chol, RowVector x) { int nRC = chol.Nrows(); - + // solve R^T a = x LowerTriangularMatrix L = chol.t(); ColumnVector a(nRC); a = 0.0; int i, j; - + for (i = 1; i <= nRC; ++i) { // accumulate subtr sum @@ -177,7 +177,7 @@ void right_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l) { int nRC = chol.Nrows(); int i, j; - + // I. compute shift of column l to the kth position Matrix cholCopy = chol; // a. grab column l @@ -202,7 +202,7 @@ void right_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l) } // the kth entry of columnL is the new diagonal element in column k of cholCopy cholCopy(k,k) = columnL(k); - + // III. apply these Given's rotations to subsequent columns // for columns k+1,...,l-1 we only need to apply the last nGivens-(j-k) rotations for(j = k+1; j <= nRC; ++j) @@ -276,7 +276,7 @@ void left_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l) } chol << cholCopy; - + } diff --git a/extern/newmat/controlw.h b/extern/newmat/controlw.h index 899bc07..416bd65 100644 --- a/extern/newmat/controlw.h +++ b/extern/newmat/controlw.h @@ -53,3 +53,4 @@ class ControlWord #endif ///@} + diff --git a/extern/newmat/evalue.cpp b/extern/newmat/evalue.cpp index 98904ce..f3c7e34 100644 --- a/extern/newmat/evalue.cpp +++ b/extern/newmat/evalue.cpp @@ -66,7 +66,7 @@ static void tred2(const SymmetricMatrix& A, DiagonalMatrix& D, f = *zij++; g = *ej - hh * f; *ej++ = g; Real* zjk = z + j*n; Real* zik = z + i*n; Real* ek = E.Store(); k = j+1; - while (k--) *zjk++ -= ( f*(*ek++) + g*(*zik++) ); + while (k--) *zjk++ -= ( f*(*ek++) + g*(*zik++) ); } } D.element(i) = h; @@ -206,10 +206,10 @@ static void tred3(const SymmetricMatrix& X, DiagonalMatrix& D, Real* dk = D.Store(); Real* ak = A.Store()+(j*(j+1))/2; Real g = 0.0; k = j; while (k--) g += *ak++ * *dk++; - k = i-j; int l = j; + k = i-j; int l = j; if (k) for (;;) { g += *ak * *dk++; if (!(--k)) break; ak += ++l; } g /= h; *ej++ = g; f += g * *dj++; - } + } Real hh = f / (2 * h); Real* ak = A.Store(); dj = D.Store(); ej = E.Store(); for (j = 0; j < i; j++) @@ -300,3 +300,4 @@ void eigenvalues(const SymmetricMatrix& X, DiagonalMatrix& D, #endif ///@} + diff --git a/extern/newmat/example.cpp b/extern/newmat/example.cpp index 3182a36..e671d0a 100644 --- a/extern/newmat/example.cpp +++ b/extern/newmat/example.cpp @@ -223,7 +223,7 @@ void test4(Real* y, Real* x1, Real* x2, int nobs, int npred) cout << "\n\nTest 4 - QR triangularisation\n"; // QR triangularisation method - + // load data - 1s into col 1 of matrix int npred1 = npred+1; Matrix X(nobs,npred1); ColumnVector Y(nobs); @@ -251,7 +251,7 @@ void test4(Real* y, Real* x1, Real* x2, int nobs, int npred) for (int i=1; i<=npred1; i++) SE(i) = sqrt(D(i)*ResVar); cout << setw(11) << setprecision(5) << (A | SE) << endl; cout << "\nObservations, fitted value, residual value, hat value\n"; - cout << setw(9) << setprecision(3) << + cout << setw(9) << setprecision(3) << (X.columns(2,3) | Y | Fitted | Y1 | Hat.as_column()); cout << "\n\n"; } @@ -261,7 +261,7 @@ void test5(Real* y, Real* x1, Real* x2, int nobs, int npred) cout << "\n\nTest 5 - singular value\n"; // Singular value decomposition method - + // load data - 1s into col 1 of matrix int npred1 = npred+1; Matrix X(nobs,npred1); ColumnVector Y(nobs); @@ -288,7 +288,7 @@ void test5(Real* y, Real* x1, Real* x2, int nobs, int npred) for (int i=1; i<=npred1; i++) SE(i) = sqrt(D(i)*ResVar); cout << setw(11) << setprecision(5) << (A | SE) << endl; cout << "\nObservations, fitted value, residual value, hat value\n"; - cout << setw(9) << setprecision(3) << + cout << setw(9) << setprecision(3) << (X.columns(2,3) | Y | Fitted | Residual | Hat.as_column()); cout << "\n\n"; } diff --git a/extern/newmat/example.txt b/extern/newmat/example.txt index afcb787..e2b1fcb 100644 --- a/extern/newmat/example.txt +++ b/extern/newmat/example.txt @@ -8,21 +8,21 @@ Test 1 - traditional, bad Estimates and their standard errors - 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.39166 0.53188 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -32,20 +32,20 @@ Test 2 - traditional, OK Estimates and their standard errors 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -55,20 +55,20 @@ Test 3 - Cholesky Estimates and their standard errors 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -77,21 +77,21 @@ Test 4 - QR triangularisation Estimates and their standard errors - 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.39166 0.53188 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 @@ -100,21 +100,21 @@ Test 5 - singular value Estimates and their standard errors - 1.39166 0.53188 - 1.98310 0.20932 - 0.95221 0.27731 + 1.39166 0.53188 + 1.98310 0.20932 + 0.95221 0.27731 Observations, fitted value, residual value, hat value - 2.400 1.700 8.300 7.770 0.530 0.280 - 1.800 0.900 5.500 5.818 -0.318 0.190 - 2.400 1.600 8.000 7.675 0.325 0.229 - 3.000 1.900 8.500 9.150 -0.650 0.446 - 2.000 0.500 5.700 5.834 -0.134 0.271 - 1.200 0.600 4.400 4.343 0.057 0.480 - 2.000 1.100 6.300 6.405 -0.105 0.143 - 2.700 1.000 7.900 7.698 0.202 0.153 - 3.600 0.500 9.100 9.007 0.093 0.808 + 2.400 1.700 8.300 7.770 0.530 0.280 + 1.800 0.900 5.500 5.818 -0.318 0.190 + 2.400 1.600 8.000 7.675 0.325 0.229 + 3.000 1.900 8.500 9.150 -0.650 0.446 + 2.000 0.500 5.700 5.834 -0.134 0.271 + 1.200 0.600 4.400 4.343 0.057 0.480 + 2.000 1.100 6.300 6.405 -0.105 0.143 + 2.700 1.000 7.900 7.698 0.202 0.153 + 3.600 0.500 9.100 9.007 0.093 0.808 diff --git a/extern/newmat/garch.cpp b/extern/newmat/garch.cpp index 6f97b22..4643e6f 100644 --- a/extern/newmat/garch.cpp +++ b/extern/newmat/garch.cpp @@ -189,7 +189,7 @@ int main() } CatchAll { - cout << "\nProgram fails - exception generated\n\n"; + cout << "\nProgram fails - exception generated\n\n"; } return 0; } diff --git a/extern/newmat/garch.dat b/extern/newmat/garch.dat index 5c39412..81f55b0 100644 --- a/extern/newmat/garch.dat +++ b/extern/newmat/garch.dat @@ -1,501 +1,502 @@ 500 - 3.44443 -0.49800 - 1.43549 -0.49600 - 3.70477 -0.49400 - -3.82558 -0.49200 - 1.20130 -0.49000 - -2.62383 -0.48800 - -1.34321 -0.48600 - -0.35801 -0.48400 - -2.18813 -0.48200 - -1.98628 -0.48000 - -1.53262 -0.47800 - -1.45007 -0.47600 - -1.18593 -0.47400 - -0.55274 -0.47200 - -1.55943 -0.47000 - -3.10084 -0.46800 - 0.44254 -0.46600 - -0.63936 -0.46400 - 2.44989 -0.46200 - -2.14392 -0.46000 - 0.47310 -0.45800 - -1.64464 -0.45600 - 0.56628 -0.45400 - -0.80925 -0.45200 - -0.78961 -0.45000 - -1.12984 -0.44800 - -0.50715 -0.44600 - -1.75134 -0.44400 - -1.04231 -0.44200 - 0.94435 -0.44000 - 1.16306 -0.43800 - -2.87888 -0.43600 - -3.31084 -0.43400 - -3.06191 -0.43200 - 1.06977 -0.43000 - 3.50462 -0.42800 - 3.94848 -0.42600 - 1.56565 -0.42400 - -5.21742 -0.42200 - 1.94652 -0.42000 - -3.01182 -0.41800 - -3.88963 -0.41600 - -0.31319 -0.41400 - -5.71752 -0.41200 - -6.72218 -0.41000 - 3.23482 -0.40800 - 2.12675 -0.40600 - -0.10975 -0.40400 - -1.73790 -0.40200 - -0.86870 -0.40000 - -1.46022 -0.39800 - -0.22960 -0.39600 - 0.01596 -0.39400 - 0.00568 -0.39200 - -3.41221 -0.39000 - -0.47401 -0.38800 - -1.76305 -0.38600 - -0.49640 -0.38400 - -2.36184 -0.38200 - -0.09625 -0.38000 - -2.81448 -0.37800 - 3.14301 -0.37600 - 1.88025 -0.37400 - -2.61618 -0.37200 - -1.56239 -0.37000 - 0.95722 -0.36800 - 1.29773 -0.36600 - -1.45155 -0.36400 - -0.63342 -0.36200 - -0.78925 -0.36000 - 0.42473 -0.35800 - 1.39599 -0.35600 - 1.03934 -0.35400 - -0.11042 -0.35200 - 0.89123 -0.35000 - 0.93411 -0.34800 - 2.78027 -0.34600 - 3.37402 -0.34400 - -0.07986 -0.34200 - 0.79142 -0.34000 - -4.17148 -0.33800 - -1.26717 -0.33600 - -4.36262 -0.33400 - 1.17431 -0.33200 - -1.75656 -0.33000 - 0.40495 -0.32800 - 0.17572 -0.32600 - -0.27991 -0.32400 - -0.85524 -0.32200 - -1.23380 -0.32000 - -1.01889 -0.31800 - 1.08393 -0.31600 - -0.55989 -0.31400 - -1.91643 -0.31200 - -1.23897 -0.31000 - -0.85407 -0.30800 - 0.35218 -0.30600 - -1.57057 -0.30400 - 0.20665 -0.30200 - 0.19680 -0.30000 - 0.03116 -0.29800 - 0.09100 -0.29600 - 1.03416 -0.29400 - -0.16048 -0.29200 - -0.27530 -0.29000 - -0.11056 -0.28800 - -2.11332 -0.28600 - -0.51348 -0.28400 - -0.16360 -0.28200 - 1.30712 -0.28000 - -0.94392 -0.27800 - -0.06838 -0.27600 - -0.04095 -0.27400 - -2.00364 -0.27200 - 0.63950 -0.27000 - -1.02895 -0.26800 - -0.17454 -0.26600 - -0.86659 -0.26400 - 0.81698 -0.26200 - 0.51579 -0.26000 - -0.74525 -0.25800 - 2.43378 -0.25600 - 0.89364 -0.25400 - 1.81727 -0.25200 - -0.29667 -0.25000 - -0.99628 -0.24800 - 0.09452 -0.24600 - 1.73730 -0.24400 - 0.36819 -0.24200 - -1.56521 -0.24000 - 0.74916 -0.23800 - 0.56802 -0.23600 - -1.34157 -0.23400 - -0.65638 -0.23200 - -2.12183 -0.23000 - -2.35486 -0.22800 - -2.09369 -0.22600 - -3.30745 -0.22400 - -4.14763 -0.22200 - -3.56306 -0.22000 - 0.78907 -0.21800 - -3.74014 -0.21600 - -2.73770 -0.21400 - -4.43153 -0.21200 - -0.80243 -0.21000 - -0.17474 -0.20800 - -0.38250 -0.20600 - -0.98962 -0.20400 - -1.41965 -0.20200 - 0.90585 -0.20000 - 0.66850 -0.19800 - -0.81629 -0.19600 - -3.04422 -0.19400 - -0.94514 -0.19200 - 0.05209 -0.19000 - 0.21315 -0.18800 - -0.86960 -0.18600 - -1.72978 -0.18400 - -2.85623 -0.18200 - -3.15650 -0.18000 - -0.09176 -0.17800 - -1.27376 -0.17600 - -1.06533 -0.17400 - 1.21766 -0.17200 - 0.41706 -0.17000 - -0.30885 -0.16800 - 0.78344 -0.16600 - -1.76348 -0.16400 - 2.46496 -0.16200 - -0.32712 -0.16000 - 1.38586 -0.15800 - 0.33513 -0.15600 - 0.66116 -0.15400 - 0.92420 -0.15200 - -0.67200 -0.15000 - -0.90707 -0.14800 - -0.41053 -0.14600 - 0.62288 -0.14400 - 0.78497 -0.14200 - 0.99670 -0.14000 - -2.19972 -0.13800 - 0.21922 -0.13600 - -0.15003 -0.13400 - -0.72706 -0.13200 - 0.13596 -0.13000 - -0.00235 -0.12800 - 0.50025 -0.12600 - 0.80875 -0.12400 - -0.71010 -0.12200 - -3.85477 -0.12000 - 2.45549 -0.11800 - -2.87772 -0.11600 - 1.03987 -0.11400 - -1.41914 -0.11200 - -1.87414 -0.11000 - 1.32656 -0.10800 - 2.15281 -0.10600 - 3.25624 -0.10400 - -3.72420 -0.10200 - -4.01675 -0.10000 - 1.19241 -0.09800 - 0.35189 -0.09600 - -0.40223 -0.09400 - 0.84146 -0.09200 - 1.08746 -0.09000 - 2.20874 -0.08800 - -0.18822 -0.08600 - -1.29757 -0.08400 - -1.36022 -0.08200 - 0.54575 -0.08000 - -0.23008 -0.07800 - 0.00750 -0.07600 - 1.81600 -0.07400 - -0.07319 -0.07200 - 0.70587 -0.07000 - -2.67033 -0.06800 - 0.67446 -0.06600 - -0.21002 -0.06400 - 2.11396 -0.06200 - -0.94189 -0.06000 - 0.27803 -0.05800 - -0.92172 -0.05600 - 1.37776 -0.05400 - 2.72565 -0.05200 - 0.47208 -0.05000 - -3.33845 -0.04800 - -0.20695 -0.04600 - -2.18905 -0.04400 - -4.33413 -0.04200 - 0.17860 -0.04000 - -5.57817 -0.03800 - -0.32771 -0.03600 - 1.47321 -0.03400 - 2.33767 -0.03200 - 1.22282 -0.03000 - -1.48593 -0.02800 - 0.79435 -0.02600 - 0.54491 -0.02400 - 1.31706 -0.02200 - -1.26472 -0.02000 - -1.72634 -0.01800 - -3.85299 -0.01600 - 0.43717 -0.01400 - -3.39362 -0.01200 - -3.60823 -0.01000 - 0.18868 -0.00800 - 1.23035 -0.00600 - 1.70454 -0.00400 - -1.44766 -0.00200 - 0.99808 0.00000 - 0.24554 0.00200 - 1.44446 0.00400 - 0.96697 0.00600 - -3.30396 0.00800 - -5.97223 0.01000 - 1.22379 0.01200 - 6.00662 0.01400 - 4.43380 0.01600 - 2.01081 0.01800 - -2.74552 0.02000 - 1.19452 0.02200 - 3.81020 0.02400 - 2.04597 0.02600 - 0.66764 0.02800 - 2.68350 0.03000 - -2.85514 0.03200 - 0.21727 0.03400 - 1.88780 0.03600 - 2.23549 0.03800 - 1.57589 0.04000 - 1.92344 0.04200 - -1.78414 0.04400 - -0.67367 0.04600 - 0.19357 0.04800 - 1.00246 0.05000 - 2.13782 0.05200 - 1.90734 0.05400 - 0.43943 0.05600 - -0.55699 0.05800 - 1.76985 0.06000 - -0.77310 0.06200 - -0.33812 0.06400 - -0.85572 0.06600 - -2.49390 0.06800 - -3.17954 0.07000 - 2.86688 0.07200 - 2.03589 0.07400 - -1.34393 0.07600 - 1.01839 0.07800 - -0.15220 0.08000 - 1.17978 0.08200 - 1.96847 0.08400 - 1.90596 0.08600 - 3.72675 0.08800 - -0.65513 0.09000 - -1.45672 0.09200 - -0.08779 0.09400 - -0.39105 0.09600 - 1.88645 0.09800 - 2.34710 0.10000 - -2.65900 0.10200 - -0.47996 0.10400 - -2.51512 0.10600 - -3.59097 0.10800 - -1.62117 0.11000 - -2.43947 0.11200 - 3.50339 0.11400 - 3.05144 0.11600 - -2.73565 0.11800 - -1.31556 0.12000 - 1.85250 0.12200 - -1.03864 0.12400 - 0.79097 0.12600 - -0.12426 0.12800 - 0.48964 0.13000 - 1.42419 0.13200 - 0.55098 0.13400 - -0.78121 0.13600 - -0.01716 0.13800 - -1.27952 0.14000 - 1.91981 0.14200 - 0.25822 0.14400 - 0.68516 0.14600 - 1.25616 0.14800 - -1.40178 0.15000 - -0.99551 0.15200 - 1.45728 0.15400 - -1.66513 0.15600 - -1.20284 0.15800 - 1.84775 0.16000 - -1.91535 0.16200 - 0.34142 0.16400 - 1.90641 0.16600 - 1.55524 0.16800 - 1.77263 0.17000 - 1.25731 0.17200 - -0.66331 0.17400 - 0.93506 0.17600 - 0.87120 0.17800 - 0.73840 0.18000 - -1.48181 0.18200 - -1.76043 0.18400 - 0.96176 0.18600 - 1.29128 0.18800 - 1.20889 0.19000 - 0.78386 0.19200 - 1.54668 0.19400 - -0.25996 0.19600 - 0.93201 0.19800 - 1.30374 0.20000 - 2.23175 0.20200 - -0.42525 0.20400 - 1.12784 0.20600 - -0.42014 0.20800 - -0.00577 0.21000 - -1.14837 0.21200 - 2.48454 0.21400 - -0.51466 0.21600 - -0.06257 0.21800 - -1.25993 0.22000 - 1.26623 0.22200 - 3.05099 0.22400 - -1.84077 0.22600 - -0.36058 0.22800 - 2.65788 0.23000 - -0.17717 0.23200 - 1.68915 0.23400 - -1.53406 0.23600 - 1.78097 0.23800 - -1.24217 0.24000 - -4.17466 0.24200 - 0.80433 0.24400 - 0.70856 0.24600 - -0.96881 0.24800 - 0.87322 0.25000 - -2.45936 0.25200 - 2.95677 0.25400 - 1.81628 0.25600 - -0.85793 0.25800 - 1.02089 0.26000 - -1.05425 0.26200 - -0.29861 0.26400 - 1.69682 0.26600 - 1.07389 0.26800 - 0.22183 0.27000 - 1.72766 0.27200 - -0.99746 0.27400 - -2.14178 0.27600 - -1.67924 0.27800 - 1.56520 0.28000 - -0.86864 0.28200 - 2.65155 0.28400 - -2.27166 0.28600 - 0.68310 0.28800 - 0.84102 0.29000 - 0.64604 0.29200 - 0.68712 0.29400 - 1.56297 0.29600 - -0.68136 0.29800 - 1.25519 0.30000 - -1.38612 0.30200 - 2.36320 0.30400 - 5.40128 0.30600 - -1.14776 0.30800 - -1.36081 0.31000 - 0.07679 0.31200 - -0.17231 0.31400 - 1.19094 0.31600 - 0.09285 0.31800 - -0.85191 0.32000 - -0.43739 0.32200 - -0.22950 0.32400 - 2.21298 0.32600 - 0.75045 0.32800 - 0.97489 0.33000 - -0.62158 0.33200 - 1.10503 0.33400 - 0.36977 0.33600 - -0.32894 0.33800 - 2.13729 0.34000 - 4.42019 0.34200 - -2.80916 0.34400 - 2.28181 0.34600 - 2.59053 0.34800 - -1.52891 0.35000 - -1.35202 0.35200 - 1.27639 0.35400 - 0.28782 0.35600 - 0.83540 0.35800 - -0.32867 0.36000 - 1.16891 0.36200 - 0.02511 0.36400 - -0.71878 0.36600 - 0.69811 0.36800 - 1.29399 0.37000 - 0.86300 0.37200 - -0.12139 0.37400 - -0.28069 0.37600 - 3.07623 0.37800 - -2.91737 0.38000 - 0.16709 0.38200 - -1.60815 0.38400 - 0.02795 0.38600 - 1.19657 0.38800 - 0.04390 0.39000 - 0.95983 0.39200 - -1.83683 0.39400 - -1.69167 0.39600 - 3.15836 0.39800 - 2.24002 0.40000 - 0.45225 0.40200 - 1.35014 0.40400 - -1.67177 0.40600 - -0.97317 0.40800 - 4.20922 0.41000 - -0.03983 0.41200 - -0.35933 0.41400 - -1.49772 0.41600 - 2.72900 0.41800 - -2.61061 0.42000 - -0.26581 0.42200 - -4.30162 0.42400 - -3.55225 0.42600 - -5.60739 0.42800 - 2.26730 0.43000 - -0.05568 0.43200 - -0.14348 0.43400 - -1.73015 0.43600 - -1.01649 0.43800 - -2.39568 0.44000 - 3.41626 0.44200 - 2.23817 0.44400 - -1.02668 0.44600 - 3.18086 0.44800 - 0.71908 0.45000 - -0.37826 0.45200 - -0.39837 0.45400 - 0.50378 0.45600 - 0.38287 0.45800 - 2.95404 0.46000 - -1.16143 0.46200 - 0.89913 0.46400 - -0.82190 0.46600 - 1.30638 0.46800 - 0.89138 0.47000 - 0.85038 0.47200 - -1.38925 0.47400 - 3.74026 0.47600 - 4.60999 0.47800 - 1.31364 0.48000 - 5.17183 0.48200 - 1.82162 0.48400 - 1.09830 0.48600 - 1.36666 0.48800 - -0.09676 0.49000 - 0.74155 0.49200 - 1.21910 0.49400 - 1.20746 0.49600 - 0.82236 0.49800 - 1.54856 0.50000 + 3.44443 -0.49800 + 1.43549 -0.49600 + 3.70477 -0.49400 + -3.82558 -0.49200 + 1.20130 -0.49000 + -2.62383 -0.48800 + -1.34321 -0.48600 + -0.35801 -0.48400 + -2.18813 -0.48200 + -1.98628 -0.48000 + -1.53262 -0.47800 + -1.45007 -0.47600 + -1.18593 -0.47400 + -0.55274 -0.47200 + -1.55943 -0.47000 + -3.10084 -0.46800 + 0.44254 -0.46600 + -0.63936 -0.46400 + 2.44989 -0.46200 + -2.14392 -0.46000 + 0.47310 -0.45800 + -1.64464 -0.45600 + 0.56628 -0.45400 + -0.80925 -0.45200 + -0.78961 -0.45000 + -1.12984 -0.44800 + -0.50715 -0.44600 + -1.75134 -0.44400 + -1.04231 -0.44200 + 0.94435 -0.44000 + 1.16306 -0.43800 + -2.87888 -0.43600 + -3.31084 -0.43400 + -3.06191 -0.43200 + 1.06977 -0.43000 + 3.50462 -0.42800 + 3.94848 -0.42600 + 1.56565 -0.42400 + -5.21742 -0.42200 + 1.94652 -0.42000 + -3.01182 -0.41800 + -3.88963 -0.41600 + -0.31319 -0.41400 + -5.71752 -0.41200 + -6.72218 -0.41000 + 3.23482 -0.40800 + 2.12675 -0.40600 + -0.10975 -0.40400 + -1.73790 -0.40200 + -0.86870 -0.40000 + -1.46022 -0.39800 + -0.22960 -0.39600 + 0.01596 -0.39400 + 0.00568 -0.39200 + -3.41221 -0.39000 + -0.47401 -0.38800 + -1.76305 -0.38600 + -0.49640 -0.38400 + -2.36184 -0.38200 + -0.09625 -0.38000 + -2.81448 -0.37800 + 3.14301 -0.37600 + 1.88025 -0.37400 + -2.61618 -0.37200 + -1.56239 -0.37000 + 0.95722 -0.36800 + 1.29773 -0.36600 + -1.45155 -0.36400 + -0.63342 -0.36200 + -0.78925 -0.36000 + 0.42473 -0.35800 + 1.39599 -0.35600 + 1.03934 -0.35400 + -0.11042 -0.35200 + 0.89123 -0.35000 + 0.93411 -0.34800 + 2.78027 -0.34600 + 3.37402 -0.34400 + -0.07986 -0.34200 + 0.79142 -0.34000 + -4.17148 -0.33800 + -1.26717 -0.33600 + -4.36262 -0.33400 + 1.17431 -0.33200 + -1.75656 -0.33000 + 0.40495 -0.32800 + 0.17572 -0.32600 + -0.27991 -0.32400 + -0.85524 -0.32200 + -1.23380 -0.32000 + -1.01889 -0.31800 + 1.08393 -0.31600 + -0.55989 -0.31400 + -1.91643 -0.31200 + -1.23897 -0.31000 + -0.85407 -0.30800 + 0.35218 -0.30600 + -1.57057 -0.30400 + 0.20665 -0.30200 + 0.19680 -0.30000 + 0.03116 -0.29800 + 0.09100 -0.29600 + 1.03416 -0.29400 + -0.16048 -0.29200 + -0.27530 -0.29000 + -0.11056 -0.28800 + -2.11332 -0.28600 + -0.51348 -0.28400 + -0.16360 -0.28200 + 1.30712 -0.28000 + -0.94392 -0.27800 + -0.06838 -0.27600 + -0.04095 -0.27400 + -2.00364 -0.27200 + 0.63950 -0.27000 + -1.02895 -0.26800 + -0.17454 -0.26600 + -0.86659 -0.26400 + 0.81698 -0.26200 + 0.51579 -0.26000 + -0.74525 -0.25800 + 2.43378 -0.25600 + 0.89364 -0.25400 + 1.81727 -0.25200 + -0.29667 -0.25000 + -0.99628 -0.24800 + 0.09452 -0.24600 + 1.73730 -0.24400 + 0.36819 -0.24200 + -1.56521 -0.24000 + 0.74916 -0.23800 + 0.56802 -0.23600 + -1.34157 -0.23400 + -0.65638 -0.23200 + -2.12183 -0.23000 + -2.35486 -0.22800 + -2.09369 -0.22600 + -3.30745 -0.22400 + -4.14763 -0.22200 + -3.56306 -0.22000 + 0.78907 -0.21800 + -3.74014 -0.21600 + -2.73770 -0.21400 + -4.43153 -0.21200 + -0.80243 -0.21000 + -0.17474 -0.20800 + -0.38250 -0.20600 + -0.98962 -0.20400 + -1.41965 -0.20200 + 0.90585 -0.20000 + 0.66850 -0.19800 + -0.81629 -0.19600 + -3.04422 -0.19400 + -0.94514 -0.19200 + 0.05209 -0.19000 + 0.21315 -0.18800 + -0.86960 -0.18600 + -1.72978 -0.18400 + -2.85623 -0.18200 + -3.15650 -0.18000 + -0.09176 -0.17800 + -1.27376 -0.17600 + -1.06533 -0.17400 + 1.21766 -0.17200 + 0.41706 -0.17000 + -0.30885 -0.16800 + 0.78344 -0.16600 + -1.76348 -0.16400 + 2.46496 -0.16200 + -0.32712 -0.16000 + 1.38586 -0.15800 + 0.33513 -0.15600 + 0.66116 -0.15400 + 0.92420 -0.15200 + -0.67200 -0.15000 + -0.90707 -0.14800 + -0.41053 -0.14600 + 0.62288 -0.14400 + 0.78497 -0.14200 + 0.99670 -0.14000 + -2.19972 -0.13800 + 0.21922 -0.13600 + -0.15003 -0.13400 + -0.72706 -0.13200 + 0.13596 -0.13000 + -0.00235 -0.12800 + 0.50025 -0.12600 + 0.80875 -0.12400 + -0.71010 -0.12200 + -3.85477 -0.12000 + 2.45549 -0.11800 + -2.87772 -0.11600 + 1.03987 -0.11400 + -1.41914 -0.11200 + -1.87414 -0.11000 + 1.32656 -0.10800 + 2.15281 -0.10600 + 3.25624 -0.10400 + -3.72420 -0.10200 + -4.01675 -0.10000 + 1.19241 -0.09800 + 0.35189 -0.09600 + -0.40223 -0.09400 + 0.84146 -0.09200 + 1.08746 -0.09000 + 2.20874 -0.08800 + -0.18822 -0.08600 + -1.29757 -0.08400 + -1.36022 -0.08200 + 0.54575 -0.08000 + -0.23008 -0.07800 + 0.00750 -0.07600 + 1.81600 -0.07400 + -0.07319 -0.07200 + 0.70587 -0.07000 + -2.67033 -0.06800 + 0.67446 -0.06600 + -0.21002 -0.06400 + 2.11396 -0.06200 + -0.94189 -0.06000 + 0.27803 -0.05800 + -0.92172 -0.05600 + 1.37776 -0.05400 + 2.72565 -0.05200 + 0.47208 -0.05000 + -3.33845 -0.04800 + -0.20695 -0.04600 + -2.18905 -0.04400 + -4.33413 -0.04200 + 0.17860 -0.04000 + -5.57817 -0.03800 + -0.32771 -0.03600 + 1.47321 -0.03400 + 2.33767 -0.03200 + 1.22282 -0.03000 + -1.48593 -0.02800 + 0.79435 -0.02600 + 0.54491 -0.02400 + 1.31706 -0.02200 + -1.26472 -0.02000 + -1.72634 -0.01800 + -3.85299 -0.01600 + 0.43717 -0.01400 + -3.39362 -0.01200 + -3.60823 -0.01000 + 0.18868 -0.00800 + 1.23035 -0.00600 + 1.70454 -0.00400 + -1.44766 -0.00200 + 0.99808 0.00000 + 0.24554 0.00200 + 1.44446 0.00400 + 0.96697 0.00600 + -3.30396 0.00800 + -5.97223 0.01000 + 1.22379 0.01200 + 6.00662 0.01400 + 4.43380 0.01600 + 2.01081 0.01800 + -2.74552 0.02000 + 1.19452 0.02200 + 3.81020 0.02400 + 2.04597 0.02600 + 0.66764 0.02800 + 2.68350 0.03000 + -2.85514 0.03200 + 0.21727 0.03400 + 1.88780 0.03600 + 2.23549 0.03800 + 1.57589 0.04000 + 1.92344 0.04200 + -1.78414 0.04400 + -0.67367 0.04600 + 0.19357 0.04800 + 1.00246 0.05000 + 2.13782 0.05200 + 1.90734 0.05400 + 0.43943 0.05600 + -0.55699 0.05800 + 1.76985 0.06000 + -0.77310 0.06200 + -0.33812 0.06400 + -0.85572 0.06600 + -2.49390 0.06800 + -3.17954 0.07000 + 2.86688 0.07200 + 2.03589 0.07400 + -1.34393 0.07600 + 1.01839 0.07800 + -0.15220 0.08000 + 1.17978 0.08200 + 1.96847 0.08400 + 1.90596 0.08600 + 3.72675 0.08800 + -0.65513 0.09000 + -1.45672 0.09200 + -0.08779 0.09400 + -0.39105 0.09600 + 1.88645 0.09800 + 2.34710 0.10000 + -2.65900 0.10200 + -0.47996 0.10400 + -2.51512 0.10600 + -3.59097 0.10800 + -1.62117 0.11000 + -2.43947 0.11200 + 3.50339 0.11400 + 3.05144 0.11600 + -2.73565 0.11800 + -1.31556 0.12000 + 1.85250 0.12200 + -1.03864 0.12400 + 0.79097 0.12600 + -0.12426 0.12800 + 0.48964 0.13000 + 1.42419 0.13200 + 0.55098 0.13400 + -0.78121 0.13600 + -0.01716 0.13800 + -1.27952 0.14000 + 1.91981 0.14200 + 0.25822 0.14400 + 0.68516 0.14600 + 1.25616 0.14800 + -1.40178 0.15000 + -0.99551 0.15200 + 1.45728 0.15400 + -1.66513 0.15600 + -1.20284 0.15800 + 1.84775 0.16000 + -1.91535 0.16200 + 0.34142 0.16400 + 1.90641 0.16600 + 1.55524 0.16800 + 1.77263 0.17000 + 1.25731 0.17200 + -0.66331 0.17400 + 0.93506 0.17600 + 0.87120 0.17800 + 0.73840 0.18000 + -1.48181 0.18200 + -1.76043 0.18400 + 0.96176 0.18600 + 1.29128 0.18800 + 1.20889 0.19000 + 0.78386 0.19200 + 1.54668 0.19400 + -0.25996 0.19600 + 0.93201 0.19800 + 1.30374 0.20000 + 2.23175 0.20200 + -0.42525 0.20400 + 1.12784 0.20600 + -0.42014 0.20800 + -0.00577 0.21000 + -1.14837 0.21200 + 2.48454 0.21400 + -0.51466 0.21600 + -0.06257 0.21800 + -1.25993 0.22000 + 1.26623 0.22200 + 3.05099 0.22400 + -1.84077 0.22600 + -0.36058 0.22800 + 2.65788 0.23000 + -0.17717 0.23200 + 1.68915 0.23400 + -1.53406 0.23600 + 1.78097 0.23800 + -1.24217 0.24000 + -4.17466 0.24200 + 0.80433 0.24400 + 0.70856 0.24600 + -0.96881 0.24800 + 0.87322 0.25000 + -2.45936 0.25200 + 2.95677 0.25400 + 1.81628 0.25600 + -0.85793 0.25800 + 1.02089 0.26000 + -1.05425 0.26200 + -0.29861 0.26400 + 1.69682 0.26600 + 1.07389 0.26800 + 0.22183 0.27000 + 1.72766 0.27200 + -0.99746 0.27400 + -2.14178 0.27600 + -1.67924 0.27800 + 1.56520 0.28000 + -0.86864 0.28200 + 2.65155 0.28400 + -2.27166 0.28600 + 0.68310 0.28800 + 0.84102 0.29000 + 0.64604 0.29200 + 0.68712 0.29400 + 1.56297 0.29600 + -0.68136 0.29800 + 1.25519 0.30000 + -1.38612 0.30200 + 2.36320 0.30400 + 5.40128 0.30600 + -1.14776 0.30800 + -1.36081 0.31000 + 0.07679 0.31200 + -0.17231 0.31400 + 1.19094 0.31600 + 0.09285 0.31800 + -0.85191 0.32000 + -0.43739 0.32200 + -0.22950 0.32400 + 2.21298 0.32600 + 0.75045 0.32800 + 0.97489 0.33000 + -0.62158 0.33200 + 1.10503 0.33400 + 0.36977 0.33600 + -0.32894 0.33800 + 2.13729 0.34000 + 4.42019 0.34200 + -2.80916 0.34400 + 2.28181 0.34600 + 2.59053 0.34800 + -1.52891 0.35000 + -1.35202 0.35200 + 1.27639 0.35400 + 0.28782 0.35600 + 0.83540 0.35800 + -0.32867 0.36000 + 1.16891 0.36200 + 0.02511 0.36400 + -0.71878 0.36600 + 0.69811 0.36800 + 1.29399 0.37000 + 0.86300 0.37200 + -0.12139 0.37400 + -0.28069 0.37600 + 3.07623 0.37800 + -2.91737 0.38000 + 0.16709 0.38200 + -1.60815 0.38400 + 0.02795 0.38600 + 1.19657 0.38800 + 0.04390 0.39000 + 0.95983 0.39200 + -1.83683 0.39400 + -1.69167 0.39600 + 3.15836 0.39800 + 2.24002 0.40000 + 0.45225 0.40200 + 1.35014 0.40400 + -1.67177 0.40600 + -0.97317 0.40800 + 4.20922 0.41000 + -0.03983 0.41200 + -0.35933 0.41400 + -1.49772 0.41600 + 2.72900 0.41800 + -2.61061 0.42000 + -0.26581 0.42200 + -4.30162 0.42400 + -3.55225 0.42600 + -5.60739 0.42800 + 2.26730 0.43000 + -0.05568 0.43200 + -0.14348 0.43400 + -1.73015 0.43600 + -1.01649 0.43800 + -2.39568 0.44000 + 3.41626 0.44200 + 2.23817 0.44400 + -1.02668 0.44600 + 3.18086 0.44800 + 0.71908 0.45000 + -0.37826 0.45200 + -0.39837 0.45400 + 0.50378 0.45600 + 0.38287 0.45800 + 2.95404 0.46000 + -1.16143 0.46200 + 0.89913 0.46400 + -0.82190 0.46600 + 1.30638 0.46800 + 0.89138 0.47000 + 0.85038 0.47200 + -1.38925 0.47400 + 3.74026 0.47600 + 4.60999 0.47800 + 1.31364 0.48000 + 5.17183 0.48200 + 1.82162 0.48400 + 1.09830 0.48600 + 1.36666 0.48800 + -0.09676 0.49000 + 0.74155 0.49200 + 1.21910 0.49400 + 1.20746 0.49600 + 0.82236 0.49800 + 1.54856 0.50000 + diff --git a/extern/newmat/garch.txt b/extern/newmat/garch.txt index f7ef7c1..328cccc 100644 --- a/extern/newmat/garch.txt +++ b/extern/newmat/garch.txt @@ -23,21 +23,23 @@ Converged estimates and standard errors - 1.56690 0.22311 - 0.80046 0.20274 - 0.45307 0.08428 - 0.34655 0.09081 + 1.56690 0.22311 + 0.80046 0.20274 + 0.45307 0.08428 + 0.34655 0.09081 correlation matrix - 1.00 0.00 -0.02 0.01 - 0.00 1.00 0.21 -0.81 - -0.02 0.21 1.00 -0.63 - 0.01 -0.81 -0.63 1.00 + 1.00 0.00 -0.02 0.01 + 0.00 1.00 0.21 -0.81 + -0.02 0.21 1.00 -0.63 + 0.01 -0.81 -0.63 1.00 inverse of correlation matrix - 1.00 0.03 0.04 0.04 - 0.03 4.77 2.28 5.28 - 0.04 2.28 2.73 3.55 - 0.04 5.28 3.55 7.48 + 1.00 0.03 0.04 0.04 + 0.03 4.77 2.28 5.28 + 0.04 2.28 2.73 3.55 + 0.04 5.28 3.55 7.48 + + diff --git a/extern/newmat/hholder.cpp b/extern/newmat/hholder.cpp index 04fba3a..a1e10b8 100644 --- a/extern/newmat/hholder.cpp +++ b/extern/newmat/hholder.cpp @@ -232,12 +232,12 @@ void updateQRZT(Matrix& X, LowerTriangularMatrix& L) Tracer et("updateQRZT"); int n = X.Ncols(); int s = X.Nrows(); if (s != L.Nrows()) - Throw(ProgramException("Incompatible dimensions",X,L)); + Throw(ProgramException("Incompatible dimensions",X,L)); if (n == 0 || s == 0) return; Real* xi = X.Store(); int k; for (int i=0; iProtect(); return gm; } diff --git a/extern/newmat/newmat4.cpp b/extern/newmat/newmat4.cpp index 34f6aca..5c5cc41 100644 --- a/extern/newmat/newmat4.cpp +++ b/extern/newmat/newmat4.cpp @@ -200,12 +200,12 @@ CroutMatrix::CroutMatrix(const BaseMatrix& m) void CroutMatrix::get_aux(CroutMatrix& X) { X.d = d; X.sing = sing; - if (tag_val == 0 || tag_val == 1) // reuse the array + if (tag_val == 0 || tag_val == 1) // reuse the array { REPORT X.indx = indx; indx = 0; d = true; sing = true; return; } else if (nrows_val == 0) { REPORT indx = 0; d = true; sing = true; return; } else // copy the array - { + { REPORT Tracer tr("CroutMatrix::get_aux"); int *ix = new int [nrows_val]; MatrixErrorNoSpace(ix); @@ -259,7 +259,7 @@ ReturnMatrix GeneralMatrix::for_return() const Matrix::Matrix(Real a, int m, int n) : GeneralMatrix(m * n) { REPORT nrows_val=m; ncols_val=n; operator=(a); } - + Matrix::Matrix(const Real* a, int m, int n) : GeneralMatrix(m * n) { REPORT nrows_val=m; ncols_val=n; *this << a; } @@ -433,7 +433,7 @@ void Matrix::resize_keep(int nr, int nc) { Tracer tr("Matrix::resize_keep"); if (nr == nrows_val && nc == ncols_val) { REPORT return; } - + if (nr <= nrows_val && nc <= ncols_val) { REPORT @@ -456,7 +456,7 @@ void Matrix::resize_keep(int nr, int nc) X.submatrix(1,nr,1,nc) = submatrix(1,nr,1,nc); swap(X); } -} +} void SquareMatrix::resize_keep(int nr) { @@ -483,7 +483,7 @@ void SquareMatrix::resize_keep(int nr, int nc) if (nr != nc) Throw(NotSquareException(*this)); resize_keep(nr); } - + void SymmetricMatrix::resize_keep(int nr) { @@ -501,7 +501,7 @@ void SymmetricMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void UpperTriangularMatrix::resize_keep(int nr) { @@ -519,7 +519,7 @@ void UpperTriangularMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void LowerTriangularMatrix::resize_keep(int nr) { @@ -537,7 +537,7 @@ void LowerTriangularMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void DiagonalMatrix::resize_keep(int nr) { @@ -555,7 +555,7 @@ void DiagonalMatrix::resize_keep(int nr) X.sym_submatrix(1,nrows_val) = *this; swap(X); } -} +} void RowVector::resize_keep(int nc) { @@ -599,7 +599,7 @@ void ColumnVector::resize_keep(int nr) X.rows(1,nrows_val) = *this; swap(X); } -} +} void ColumnVector::resize_keep(int nr, int nc) { @@ -683,7 +683,7 @@ MatrixBandWidth BandMatrix::bandwidth() const MatrixBandWidth BandLUMatrix::bandwidth() const { REPORT return MatrixBandWidth(m1,m2); } - + MatrixBandWidth GenericMatrix::bandwidth()const { REPORT return gm->bandwidth(); } @@ -1271,7 +1271,7 @@ void GeneralMatrix::swap(GeneralMatrix& gm) t = storage; storage = gm.storage; gm.storage = t; Real* s = store; store = gm.store; gm.store = s; } - + void nricMatrix::swap(nricMatrix& gm) { REPORT @@ -1339,7 +1339,7 @@ RealStarStar::RealStarStar(Matrix& A) MatrixErrorNoSpace(a); Real* d = A.data(); for (int i = 0; i < m; ++i) a[i] = d + i * n; -} +} ConstRealStarStar::ConstRealStarStar(const Matrix& A) { @@ -1351,7 +1351,7 @@ ConstRealStarStar::ConstRealStarStar(const Matrix& A) MatrixErrorNoSpace(a); const Real* d = A.data(); for (int i = 0; i < m; ++i) a[i] = d + i * n; -} +} diff --git a/extern/newmat/newmat5.cpp b/extern/newmat/newmat5.cpp index 83b495b..703fb00 100644 --- a/extern/newmat/newmat5.cpp +++ b/extern/newmat/newmat5.cpp @@ -303,7 +303,7 @@ GeneralMatrix* GetSubMatrix::Evaluate(MatrixType mt) else Compare(gm->Type().sub(), mt); GeneralMatrix* gmx = mt.New(row_number, col_number, this); int i = row_number; - MatrixRow mr(gm, LoadOnEntry, row_skip); + MatrixRow mr(gm, LoadOnEntry, row_skip); MatrixRow mrx(gmx, StoreOnExit+DirectPart); MatrixRowCol sub; while (i--) @@ -330,7 +330,7 @@ void GeneralMatrix::Add(GeneralMatrix* gm1, Real f) { *s++ = *s1++ + f; *s++ = *s1++ + f; *s++ = *s1++ + f; *s++ = *s1++ + f; } i = storage & 3; while (i--) *s++ = *s1++ + f; } - + void GeneralMatrix::Add(Real f) { REPORT @@ -338,7 +338,7 @@ void GeneralMatrix::Add(Real f) while (i--) { *s++ += f; *s++ += f; *s++ += f; *s++ += f; } i = storage & 3; while (i--) *s++ += f; } - + void GeneralMatrix::NegAdd(GeneralMatrix* gm1, Real f) { REPORT @@ -347,7 +347,7 @@ void GeneralMatrix::NegAdd(GeneralMatrix* gm1, Real f) { *s++ = f - *s1++; *s++ = f - *s1++; *s++ = f - *s1++; *s++ = f - *s1++; } i = storage & 3; while (i--) *s++ = f - *s1++; } - + void GeneralMatrix::NegAdd(Real f) { REPORT @@ -359,7 +359,7 @@ void GeneralMatrix::NegAdd(Real f) } i = storage & 3; while (i--) { *s = f - *s; s++; } } - + void GeneralMatrix::Negate(GeneralMatrix* gm1) { // change sign of elements @@ -369,7 +369,7 @@ void GeneralMatrix::Negate(GeneralMatrix* gm1) { *s++ = -(*s1++); *s++ = -(*s1++); *s++ = -(*s1++); *s++ = -(*s1++); } i = storage & 3; while(i--) *s++ = -(*s1++); } - + void GeneralMatrix::Negate() { REPORT @@ -378,7 +378,7 @@ void GeneralMatrix::Negate() { *s = -(*s); s++; *s = -(*s); s++; *s = -(*s); s++; *s = -(*s); s++; } i = storage & 3; while(i--) { *s = -(*s); s++; } } - + void GeneralMatrix::Multiply(GeneralMatrix* gm1, Real f) { REPORT @@ -387,7 +387,7 @@ void GeneralMatrix::Multiply(GeneralMatrix* gm1, Real f) { *s++ = *s1++ * f; *s++ = *s1++ * f; *s++ = *s1++ * f; *s++ = *s1++ * f; } i = storage & 3; while (i--) *s++ = *s1++ * f; } - + void GeneralMatrix::Multiply(Real f) { REPORT @@ -395,7 +395,7 @@ void GeneralMatrix::Multiply(Real f) while (i--) { *s++ *= f; *s++ *= f; *s++ *= f; *s++ *= f; } i = storage & 3; while (i--) *s++ *= f; } - + /************************ MatrixInput routines ****************************/ diff --git a/extern/newmat/newmat6.cpp b/extern/newmat/newmat6.cpp index 575ff08..eda3909 100644 --- a/extern/newmat/newmat6.cpp +++ b/extern/newmat/newmat6.cpp @@ -351,7 +351,7 @@ void Matrix::operator=(const BaseMatrix& X) REPORT //CheckConversion(X); // MatrixConversionCheck mcc; Eq(X,MatrixType::Rt); -} +} void SquareMatrix::operator=(const BaseMatrix& X) { @@ -432,7 +432,7 @@ void CroutMatrix::operator=(const CroutMatrix& gm) ((CroutMatrix&)gm).get_aux(*this); Eq(gm); } - + diff --git a/extern/newmat/newmat7.cpp b/extern/newmat/newmat7.cpp index 17bd778..5befa5d 100644 --- a/extern/newmat/newmat7.cpp +++ b/extern/newmat/newmat7.cpp @@ -1033,7 +1033,7 @@ ReturnMatrix crossproduct_columns(const Matrix& A, const Matrix& B) Real* bn = b+n; Real* bn2 = bn+n; Real* cn = c+n; Real* cn2 = cn+n; - int i = n; + int i = n; while (i--) { *c++ = *an * *bn2 - *an2 * *bn; @@ -1050,3 +1050,4 @@ ReturnMatrix crossproduct_columns(const Matrix& A, const Matrix& B) #endif ///@} + diff --git a/extern/newmat/newmat8.cpp b/extern/newmat/newmat8.cpp index d3796a0..f48edc6 100644 --- a/extern/newmat/newmat8.cpp +++ b/extern/newmat/newmat8.cpp @@ -750,7 +750,7 @@ ReturnMatrix BaseMatrix::sum_square_rows() const int s = mr.Storage(); Real* in = mr.Data(); while (s--) sum += square(*in++); - ssq(i) = sum; + ssq(i) = sum; mr.Next(); } } @@ -795,7 +795,7 @@ ReturnMatrix BaseMatrix::sum_rows() const int s = mr.Storage(); Real* in = mr.Data(); while (s--) sum += *in++; - sum_vec(i) = sum; + sum_vec(i) = sum; mr.Next(); } } diff --git a/extern/newmat/newmatap.h b/extern/newmat/newmatap.h index e6884d8..dc88ac1 100644 --- a/extern/newmat/newmatap.h +++ b/extern/newmat/newmatap.h @@ -25,13 +25,13 @@ void QRZT(const Matrix&, Matrix&, Matrix&); void QRZ(Matrix&, UpperTriangularMatrix&); -void QRZ(const Matrix&, Matrix&, Matrix&); +void QRZ(const Matrix&, Matrix&, Matrix&); inline void QRZT(Matrix& X, Matrix& Y, LowerTriangularMatrix& L, Matrix& M) - { QRZT(X, L); QRZT(X, Y, M); } + { QRZT(X, L); QRZT(X, Y, M); } inline void QRZ(Matrix& X, Matrix& Y, UpperTriangularMatrix& U, Matrix& M) - { QRZ(X, U); QRZ(X, Y, M); } + { QRZ(X, U); QRZ(X, Y, M); } inline void HHDecompose(Matrix& X, LowerTriangularMatrix& L) { QRZT(X,L); } @@ -60,7 +60,7 @@ inline void UpdateQRZ(UpperTriangularMatrix& X, UpperTriangularMatrix& U) inline void UpdateQRZ(const UpperTriangularMatrix& X, Matrix& MX, Matrix& MU) { updateQRZ(X, MX, MU); } - + inline void UpdateQRZ(const Matrix& X, Matrix& MX, Matrix& MU) { updateQRZ(X, MX, MU); } @@ -68,7 +68,7 @@ inline void UpdateQRZ(const Matrix& X, Matrix& MX, Matrix& MU) // Matrix A's first n columns are orthonormal // so A.Columns(1,n).t() * A.Columns(1,n) is the identity matrix. // Fill out the remaining columns of A to make them orthonormal -// so A.t() * A is the identity matrix +// so A.t() * A is the identity matrix void extend_orthonormal(Matrix& A, int n); @@ -99,9 +99,9 @@ inline void RightCircularUpdateCholesky(UpperTriangularMatrix &chol, // a LEFT circular shift of the rows and columns from // 1,...,k-1,k,k+1,...l,l+1,...,p to // 1,...,k-1,k+1,...l,k,l+1,...,p to -void left_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l); +void left_circular_update_Cholesky(UpperTriangularMatrix &chol, int k, int l); inline void LeftCircularUpdateCholesky(UpperTriangularMatrix &chol, - int k, int l) { left_circular_update_Cholesky(chol, k, l); } + int k, int l) { left_circular_update_Cholesky(chol, k, l); } void SVD(const Matrix&, DiagonalMatrix&, Matrix&, Matrix&, @@ -268,3 +268,5 @@ ReturnMatrix Helmert_transpose(const Matrix& Y, bool full=false); ///@} + + diff --git a/extern/newmat/newmatex.cpp b/extern/newmat/newmatex.cpp index 0df2657..d00496e 100644 --- a/extern/newmat/newmatex.cpp +++ b/extern/newmat/newmatex.cpp @@ -322,3 +322,4 @@ void BaseMatrix::IEQND() const #ifdef use_namespace } #endif + diff --git a/extern/newmat/newmatnl.cpp b/extern/newmat/newmatnl.cpp index 35c4b46..56c52ea 100644 --- a/extern/newmat/newmatnl.cpp +++ b/extern/newmat/newmatnl.cpp @@ -237,7 +237,7 @@ void MLE_D_FI::Fit(ColumnVector& Parameters) FindMaximum2::Fit(Parameters,Lim); cout << "\nConverged" << endl; } - + void MLE_D_FI::MakeCovariance() { if (Covariance.Nrows()==0) @@ -252,7 +252,7 @@ void MLE_D_FI::MakeCovariance() void MLE_D_FI::GetStandardErrors(ColumnVector& SEX) { MakeCovariance(); SEX = SE.AsColumn(); } - + void MLE_D_FI::GetCorrelations(SymmetricMatrix& Corr) { MakeCovariance(); Corr << SE.i() * Covariance * SE.i(); } diff --git a/extern/newmat/newmatnl.h b/extern/newmat/newmatnl.h index 7477d01..0a41584 100644 --- a/extern/newmat/newmatnl.h +++ b/extern/newmat/newmatnl.h @@ -249,7 +249,7 @@ class NonLinearLeastSquares : public FindMaximum2 // The next class is the prototype class for calculating the // log-likelihood. -// I assume first derivatives are available and something like the +// I assume first derivatives are available and something like the // Fisher Information or variance/covariance matrix of the first // derivatives or minus the matrix of second derivatives is // available. This matrix must be positive definite. @@ -324,3 +324,4 @@ class MLE_D_FI : public FindMaximum2 ///@} + diff --git a/extern/newmat/newmatrm.cpp b/extern/newmat/newmatrm.cpp index 66e5e27..726d10f 100644 --- a/extern/newmat/newmatrm.cpp +++ b/extern/newmat/newmatrm.cpp @@ -141,7 +141,7 @@ void ComplexScale(RectMatrixCol& U, RectMatrixCol& V, Real x, Real y) Tracer tr("newmatrm"); Throw(InternalException("Dimensions differ in ComplexScale")); } - Real* u = U.store; Real* v = V.store; + Real* u = U.store; Real* v = V.store; int su = U.spacing; int sv = V.spacing; //while (n--) //{ diff --git a/extern/newmat/newmatrm.h b/extern/newmat/newmatrm.h index ad64e18..d8494d7 100644 --- a/extern/newmat/newmatrm.h +++ b/extern/newmat/newmatrm.h @@ -130,7 +130,7 @@ inline void GivensRotation(Real cGivens, Real sGivens, Real& x, Real& y) Real tmp1 = -sGivens * x + cGivens * y; x = tmp0; y = tmp1; } - + inline void GivensRotationR(Real cGivens, Real sGivens, Real& x, Real& y) { // also change sign of y @@ -138,7 +138,7 @@ inline void GivensRotationR(Real cGivens, Real sGivens, Real& x, Real& y) Real tmp0 = cGivens * x + sGivens * y; Real tmp1 = sGivens * x - cGivens * y; x = tmp0; y = tmp1; -} +} diff --git a/extern/newmat/nl_ex.cpp b/extern/newmat/nl_ex.cpp index 66cf73b..25c9a01 100644 --- a/extern/newmat/nl_ex.cpp +++ b/extern/newmat/nl_ex.cpp @@ -95,7 +95,7 @@ int my_main() #ifdef DO_FREE_CHECK FreeCheck::Status(); #endif - + return 0; } @@ -113,10 +113,13 @@ int main() } CatchAll { - cout << "\nProgram fails - exception generated\n\n"; + cout << "\nProgram fails - exception generated\n\n"; } return 0; } ///@} + + + diff --git a/extern/newmat/nl_ex.txt b/extern/newmat/nl_ex.txt index 5ca98e7..46dcbf4 100644 --- a/extern/newmat/nl_ex.txt +++ b/extern/newmat/nl_ex.txt @@ -13,29 +13,30 @@ Converged Estimates and standard errors - 19.77 0.73 - -23.63 0.82 - 0.35 0.04 + 19.77 0.73 + -23.63 0.82 + 0.35 0.04 Residual s.d. = 0.42 CorrelationMatrix - 1.00 -0.05 -0.91 - -0.05 1.00 -0.31 - -0.91 -0.31 1.00 + 1.00 -0.05 -0.91 + -0.05 1.00 -0.31 + -0.91 -0.31 1.00 X, Y, Residual, Hat - 1.00 3.20 0.10 0.89 - 2.00 7.90 -0.11 0.33 - 3.00 11.10 -0.38 0.39 - 4.00 14.50 0.58 0.35 - 6.00 16.70 -0.16 0.32 - 8.00 18.30 -0.02 0.73 + 1.00 3.20 0.10 0.89 + 2.00 7.90 -0.11 0.33 + 3.00 11.10 -0.38 0.39 + 4.00 14.50 0.58 0.35 + 6.00 16.70 -0.16 0.32 + 8.00 18.30 -0.02 0.73 Var/cov - 0.5295 -0.0324 -0.0250 - -0.0324 0.6668 -0.0096 - -0.0250 -0.0096 0.0014 + 0.5295 -0.0324 -0.0250 + -0.0324 0.6668 -0.0096 + -0.0250 -0.0096 0.0014 + diff --git a/extern/newmat/nm11.htm b/extern/newmat/nm11.htm index 495eef3..f34829a 100644 --- a/extern/newmat/nm11.htm +++ b/extern/newmat/nm11.htm @@ -1,1046 +1,743 @@ - - - - - - - - - Newmat11 documentation - - - - - -

    - Documentation for newmat11, a matrix library in C++ -

    -

    - next - skip - - up - start
    - return to online documentation page -

    -

    Copyright (C) 2008: R B Davies

    -

    20 November, 2008.

    - - - - - -
    - 1. Introduction
    - 2. Getting started
    - 3. Reference manual
    - 4. Error messages -
    - 5. Design of the library
    - 6. Function summary
    - 7. Change History
    - 8. Problem report form -
    -

     

    -

    - This is the how to use documentation for newmat plus some - background information on its design. -

    -

    - There is additional support material on my web site. -

    -

    - Navigation:  This page is arranged in sections, sub-sections and - sub-sub-sections; four cross-references are given at the top of these. - Next takes you through the sections, sub-sections and - sub-sub-sections in order. Skip goes to the next section, - sub-section or sub-sub-section at the same level in the hierarchy as the - section, sub-section or sub-sub-section that you are currently reading. - Up takes you up one level in the hierarchy and start gets - you back here. -

    -

    - Please read the sections on customising and - compilers before attempting to compile - newmat. -

    -

    1. Introduction

    -

    - next - skip - - up - start -

    - - - - - -
    - 1.1 Conditions of use
    - 1.2 Description
    - 1.3 Is this the library for you?
    - 1.4 Other matrix libraries -
    - 1.5 Where to find this library
    - 1.6 How to contact the author
    - 1.7 References -
    -

    1.1 Conditions of use

    -

    - next - skip - - up - start -

    -
    -

    - I place no restrictions on the use of newmat except that I take no - liability for any problems that may arise from its use, distribution or - other dealings with it. -

    -

    -

    - You can use it in your commercial projects (as well as your non-commercial - projects). -

    - -

    -

    - You can make and distribute modified or merged versions. You can include - parts of it in your own software. -

    - -

    -

    - If you distribute modified or merged versions, please make it clear which - parts are mine and which parts are modified. -

    - -

    -

    - For a substantially modified version, simply note that it is, in part, - derived from my software. A comment in the code will be sufficient. -

    - -

    -

    The software is provided as is, without warranty of any kind.

    -

    -

    - Please understand that there may still be bugs and errors. Use at your own - risk. I (Robert Davies) take no responsibility for any errors or omissions - in this package or for any misfortune that may befall you or others as a - result of your use, distribution or other dealings with it. -

    - -
    -

    - Please report bugs to me at - robert at statsresearch.co.nz   [replace at by - you-know-what-character in the email address]. -

    -

    - When reporting a bug please tell me which C++ compiler you are using, and - what version. Also give me details of your computer. And tell me which - version of newmat (e.g. newmat03 or newmat04) you are using and its - date. Note any changes you have made to my code. If at all possible give - me a piece of code illustrating the bug. See the - problem report form. -

    -

    Please do report bugs to me.

    -

    1.2 General description

    -

    - next - skip - - up - start -

    -

    - The package is intended for scientists and engineers who need to - manipulate a variety of types of matrices using standard matrix - operations. Emphasis is on the kind of operations needed in statistical - calculations such as least squares, linear equation solve and eigenvalues. -

    -

    It supports matrix types

    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Matrixrectangular matrix
    SquareMatrixsquare matrix
    nricMatrixfor use with Numerical Recipes in C programs
    UpperTriangularMatrix 
    LowerTriangularMatrix 
    DiagonalMatrix 
    SymmetricMatrix 
    BandMatrix 
    UpperBandMatrixupper triangular band matrix
    LowerBandMatrixlower triangular band matrix
    SymmetricBandMatrix 
    RowVectorderived from Matrix
    ColumnVectorderived from Matrix
    IdentityMatrixdiagonal matrix, elements have same value
    -
    -

    Only one element type (float or double) is supported.

    -

    - The package includes the operations *, +, -, - Kronecker product, Schur product, concatenation, inverse, transpose, - conversion between types, submatrix, determinant, Cholesky decomposition, - QR decomposition, singular value decomposition, eigenvalues of a symmetric - matrix, sorting, fast Fourier transform, printing and an interface with - Numerical Recipes in C. -

    -

    - It is intended for matrices in the range 10 x 10 to the maximum size your - machine will accommodate in a single array. The number of elements in an - array cannot exceed the maximum size of an int. The package will - work for very small matrices but becomes rather inefficient. Some of the - factorisation functions are not (yet) optimised for paged memory and so - become inefficient when used with very large matrices. -

    -

    - A lazy evaluation approach to evaluating matrix expressions is used - to improve efficiency and reduce the use of temporary storage. -

    -

    - I have tested versions of the package on variety of compilers and - platforms including Borland, Gnu, Microsoft and Sun. For more details see - the section on compilers. -

    -

    1.3 Is this the library for you?

    -

    - next - skip - - up - start -

    -

    Do you

    -
      -
    • - understand * to mean matrix multiply and not element by element - multiply -
    • -
    • - need matrix operators such as * and + defined as - operators so you can write things like X = A * (B + C); -
    • -
    • need a variety of types of matrices (but not sparse)
    • -
    • need only one element type (float or double)
    • -
    • - work with matrices in the range 10 x 10 up to what can be stored in - memory -
    • -
    • tolerate a moderately large but not huge package
    • -
    • - need high quality but not necessarily the latest numerical methods. -
    • -
    -

    Then newmat may be the right matrix library for you.

    -

    1.4 Other matrix libraries

    -

    - next - skip - - up - start -

    -

    - For details of other C++ matrix libraries look at - http://www.robertnz.net/cpp_site.html. Look at the section lists of libraries which gives the locations - of several very comprehensive lists of matrix and other C++ libraries and - at the section source code. Or just search on - Google. -

    -

    1.5 Where to find this library

    -

    - next - skip - - up - start -

    - -

    1.6 How to contact the author

    -

    - next - skip - - up - start -

    -
    -   Robert Davies
    +
    + 
    +
    + 
    +
    +
    +
    +
    +
    +Newmat11 documentation
    +
    +
    +
    +
    +
    +

    Documentation for newmat11, a matrix library in C++

    +

    next - skip - +up - start
    +return to online documentation page

    +

    Copyright (C) 2008: R B Davies

    +

    20 November, 2008.

    + + + + + +
    1. +Introduction
    +2. Getting started
    +3. Reference manual
    +4. +Error messages
    +5. Design of the library
    +6. Function summary
    +7. Change History
    +8. Problem report form
    +

     

    +

    This is the how to use documentation for newmat plus some +background information on its design.

    +

    There is additional support material on my web site. +

    +

    Navigation:  This page is arranged in sections, +sub-sections and sub-sub-sections; four cross-references are given at the top +of these. Next takes you through the sections, sub-sections and +sub-sub-sections in order. Skip goes to the next section, sub-section or +sub-sub-section at the same level in the hierarchy as the section, sub-section +or sub-sub-section that you are currently reading. Up takes you up one +level in the hierarchy and start gets you back here.

    +

    Please read the sections on customising and +compilers before +attempting to compile newmat.

    +

    1. Introduction

    +

    next - skip - +up - start

    + + + + + +
    1.1 +Conditions of use
    +1.2 Description
    +1.3 Is this the library for you?
    +1.4 Other matrix libraries
    1.5 +Where to find this library
    +1.6 How to contact the author
    +1.7 References
    +

    1.1 Conditions of use

    +

    next - skip - +up - start

    +
    +

    I place no restrictions on the use of newmat except that I take no liability for any problems that may arise from its use, +distribution or other dealings with it.

    +

    +You can use it in your commercial projects (as well as your non-commercial +projects).

    +

    +You can make and distribute modified or merged versions. You can +include parts of it in your own software.

    +

    +If you distribute modified or merged versions, please make it clear +which parts are mine and which parts are modified.

    +

    +For a substantially modified version, simply note that it is, in +part, derived from my software. A comment in the code will be +sufficient.

    +

    +The software is provided as is, without warranty of any kind.

    +

    +Please understand that there may still be bugs and errors. Use at +your own risk. I (Robert Davies) take no responsibility for any errors +or omissions in this package or for any misfortune that may befall you +or others as a result of your use, distribution or other dealings with it.


    +

    Please report bugs to me at robert at statsresearch.co.nz   +[replace at by you-know-what-character in the email address].

    +

    When reporting a bug please tell me which C++ compiler you are using, and +what version. Also give me details of your computer. And tell me which version +of newmat (e.g. newmat03 or newmat04) you are using and its date. Note any changes +you have made to my code. If at all possible give me a piece of code +illustrating the bug. See the problem report form.

    +

    Please do report bugs to me.

    +

    1.2 General description +

    +

    next - skip - +up - start

    +

    The package is intended for scientists and engineers who need to manipulate +a variety of types of matrices using standard matrix operations. Emphasis is on +the kind of operations needed in statistical calculations such as least +squares, linear equation solve and eigenvalues.

    +

    It supports matrix types

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Matrixrectangular matrix
    SquareMatrixsquare matrix
    nricMatrixfor use with Numerical Recipes in C programs
    UpperTriangularMatrix 
    LowerTriangularMatrix 
    DiagonalMatrix 
    SymmetricMatrix 
    BandMatrix 
    UpperBandMatrixupper triangular band matrix
    LowerBandMatrixlower triangular band matrix
    SymmetricBandMatrix 
    RowVectorderived from Matrix
    ColumnVectorderived from Matrix
    IdentityMatrixdiagonal matrix, elements have same value
    +
    +

    Only one element type (float or double) is supported.

    +

    The package includes the operations *, +, -, +Kronecker product, Schur product, concatenation, inverse, transpose, conversion between types, submatrix, +determinant, Cholesky decomposition, QR decomposition, singular value +decomposition, eigenvalues of a symmetric matrix, sorting, fast Fourier +transform, printing and an interface with Numerical Recipes in C.

    +

    It is intended for matrices in the range 10 x 10 to the maximum size your +machine will accommodate in a single array. The number of elements in an array +cannot exceed the maximum size of an int. The package will work for very +small matrices but becomes rather inefficient. Some of the factorisation +functions are not (yet) optimised for paged memory and so become inefficient +when used with very large matrices.

    +

    A lazy evaluation approach to evaluating matrix expressions is used +to improve efficiency and reduce the use of temporary storage.

    +

    I have tested versions of the package on variety of compilers and platforms +including Borland, Gnu, Microsoft and Sun. For more details +see the section on compilers.

    +

    1.3 Is this the library for +you?

    +

    next - skip - +up - start

    +

    Do you

    +
      +
    • understand * to mean matrix multiply and not element by element +multiply
    • +
    • need matrix operators such as * and + defined as +operators so you can write things like X = A * (B + C);
    • +
    • need a variety of types of matrices (but not sparse)
    • +
    • need only one element type (float or double)
    • +
    • work with matrices in the range 10 x 10 up to what can be stored in memory +
    • +
    • tolerate a moderately large but not huge package
    • +
    • need high quality but not necessarily the latest numerical methods.
    • +
    +

    Then newmat may be the right matrix library for you.

    +

    1.4 Other matrix libraries +

    +

    next - skip - +up - start

    +

    For details of other C++ matrix libraries look at +http://www.robertnz.net/cpp_site.html. +Look at the section lists of libraries which gives the locations of +several very comprehensive lists of matrix and other C++ libraries and at the +section source code. Or just search on Google.

    +

    1.5 Where to find this +library

    +

    next - skip - +up - start

    + +

    1.6 How to contact the +author

    +

    next - skip - +up - start

    +
       Robert Davies
        16 Gloucester Street
        Wilton
        Wellington
        New Zealand
     
    -   Internet: robert at statsresearch.co.nz
    - - [replace at by you-know-what.] - -

    1.7 References

    -

    - next - skip - - up - start -

    -
      -
    • - The matrix LU decomposition is from Golub, G.H. & Van Loan, C.F. - (1996), Matrix Computations, published by Johns Hopkins - University Press. -
    • -
    • - Part of the matrix inverse/solve routine is adapted from Press, - Flannery, Teukolsky, Vetterling (1988), Numerical Recipes in C, - published by the Cambridge University Press. -
    • -
    • - Many of the advanced matrix routines are adapted from routines in - Wilkinson and Reinsch (1971), - Handbook for Automatic Computation, Vol II, Linear Algebra - published by Springer Verlag. -
    • -
    • - The fast Fourier transform is adapted from Carl de Boor (1980), - Siam J Sci Stat Comput, pp173-8 and the fast trigonometric - transforms from Charles Van Loan (1992) in - Computational frameworks for the fast Fourier transform published - by SIAM. -
    • -
    • - The sort function is derived from Sedgewick, Robert (1992), - Algorithms in C++ published by Addison Wesley. -
    • -
    -

    For references about Newmat see

    -
      -
    • - Davies, R.B. (1994) Writing a matrix package in C++. In OON-SKI'94: The - second annual object-oriented numerics conference, pp 207-213. Rogue - Wave Software, Corvallis. -
    • -
    • - Eddelbuttel, Dirk (1996) Object-oriented econometrics: matrix - programming in C++ using GCC and Newmat. Journal of Applied - Econometrics, Vol 11, No 2, pp 199-209. -
    • -
    -

    2. Getting started

    -

    - next - skip - - up - start -

    - - - - - -
    - 2.1 Overview
    - 2.2 Make files
    - 2.3 Customising
    - 2.4 Compilers
    - 2.5 Updating from previous versions
    - 2.6 Catching exceptions -
    - 2.7 Examples
    - 2.8 Testing
    - 2.9 Bugs
    - 2.10 Problem areas
    - 2.11 Files in newmat11
    -   -
    -

    2.1 Overview

    -

    - next - skip - - up - start -

    -

    - I use .h as the suffix of definition files and .cpp as the suffix of C++ - source files. -

    -

    - You will need to compile all the *.cpp files listed as program files in - the files section to get the complete package. - Ideally you should store the resulting object files as a library. The - tmt*.cpp files are used for testing, example.cpp is - an example and sl_ex.cpp, nl_ex.cpp and garch.cpp - are examples of the non-linear solve and - optimisation routines. A demonstration and test of the exception mechanism - is in test_exc.cpp. The files nm_ex1.cpp, nm_ex2.cpp and nm_ex3.cpp - contain more simple examples. -

    -

    - I include a number of make files for compiling the example and the - test package. See the section on make files for - details. Alternatively, with the PC compilers, its pretty quick just to - load all the files in the interactive environments by pointing and - clicking. -

    -

    - Use the large or win32 console model when you are using a PC. Do not - outline inline functions. You may need to increase the stack size - on older operating systems or compilers. -

    -

    - Your source files that access the newmat will need to #include one or more - of the following files. -

    - - - - - - - - - - - - - - - - - - - - - -
    include.hto access just the compiler options
    newmat.hto access just the main matrix library (includes include.h)
    newmatap.h - to access the advanced matrix routines such as Cholesky decomposition, - QR triangularisation etc (includes newmat.h) -
    newmatio.h - to access the output routines (includes - newmat.h) You can use this only with compilers that support the - standard input/output routines including manipulators (all recent - compilers) -
    newmatnl.h - to access the non-linear optimisation routines (includes newmat.h) -
    -

    - See the section on customising to see how to edit - include.h for your environment and the section on - compilers for any special problems with the - compiler you are using. -

    -

    2.2 Make files

    -

    - next - skip - - up - start -

    -

    - I have included make files for compiling my test and example - programs for various versions of CC, Borland, Microsoft, Open Watcom, - Intel and Gnu compilers. You can generate make files for a number of other - compilers with my genmake utility. - Make files provide a way of compiling your programs without using - the IDE that comes with PC compilers. See the - files section for details. -

    -

    PC

    -

    - I include make files for various versions of Borland, Microsoft and Intel - compilers. With the Borland compiler you will need to edit it to show - where you have stored your Borland compiler. For make files for other - compilers use my genmake utility. To compile my - test and example programs use Borland 5.5 (Builder 5) use -

    -
       make -f nm_b55.mak
    -

    or with Borland 5.6 (Builder 6) use

    -
       make -f nm_b56.mak
    -

    or with Microsoft VC++ 6 or 7 use

    -
       nmake -f nm_m6.mak
    -

    - There are some more notes in the - genmake documentation about using these make - files. -

    -

    Unix

    -

    - The make file for the Unix CC compilers link a .cxx file to each - .cpp file since some of these compilers do not recognise .cpp as a - legitimate extension for a C++ file. I suggest you delete this part of the - make file and, if necessary, rename the .cpp files to something - your compiler recognises. -

    -

    - My make file for Gnu GCC on Unix systems is for use with - gmake rather than make. I assume your compiler - recognises the .cpp extension. Ordinary make works with it on the - Sun but did not the Silicon Graphics or HP machines when I had access to - them, many years ago. On Linux use make. -

    -

    My make file for the CC compilers works with the ordinary make.

    -

    To compile everything with the CC compiler use

    -
    -   make -f nm_cc.mak
    -
    - -

    or for the gnu compiler use

    -
    -   make -f nm_gnu.mak
    -
    - -

    - There is a line in the make file for CC rm -f $*.cxx. Some - systems won't accept this line and you will need to delete it. In this - case, if you have a bad compile and you are using my scheme for linking - .cxx files, you will need to delete the .cxx file link generated by that - compile before you can do the next one. -

    -

    2.3 Customising

    -

    - next - skip - - up - start -

    -

    - The file include.h sets a variety of options including several - compiler dependent options. You may need to edit include.h to get the - options you require. If you are using a compiler different from one I have - worked with you may have to set up a new section in include.h appropriate - for your compiler. -

    -

    - Borland, Gnu, Microsoft and Watcom are recognised automatically. If none - of these are recognised a default set of options is used. These are fine - for AT&T, HPUX and Sun C++. If you using a compiler I don't know about - you may have to write a new set of options. -

    -

    - There is an option in include.h for selecting whether you use compiler - supported exceptions, simulated exceptions, or disable exceptions. I now - set compiler supported exceptions as the default. Use the option - for compiler supported exceptions if and only if you have set the - option on your compiler to recognise exceptions. Disabling exceptions - sometimes helps with compilers that are incompatible with my exception - simulation scheme. -

    -

    - Activate the appropriate statement to make the element type - float or double. I suggest you leave it at double. -

    -

    - The option DO_FREE_CHECK is used for tracking - memory leaks and normally should not be activated. -

    -

    - Activate SETUP_C_SUBSCRIPTS if you want to use traditional C style - element access. Note that this does - not change the starting point for indices when you are using round - brackets for accessing elements or selecting submatrices. It does enable - you to use C style square brackets. This also activates additional - constructors for Matrix, ColumnVector and RowVector to simplify use with - Numerical Recipes in C++. -

    -

    - Activate #define use_namespace if you want to use - namespaces. Do this only if you are sure your - compiler supports namespaces. If you do turn this option on, be prepared - to turn it off again if the compiler reports inaccessible variables or the - linker reports missing links. -

    -

    - Activate #define _STANDARD_ to use the standard names for the - included files and to find the floating point precision data using the - floating point standard. This will work with most recent compilers and is - done automatically for Borland, Gnu, Intel and Microsoft compilers. -

    -

    - If you haven't defined _STANDARD_ and are using a compiler that - include.h does not recognise and you want to pick up the floating - point precision data from float.h then activate - #define use_float_h. Otherwise the floating point precision data - will be accessed from values.h. You may need to do this with - computers from Digital, in particular. -

    -

    There is a line

    -
       //#define set_unix_options
    -

    - You can activate this if you are using a Linux or Unix system. It is not - used by Newmat but is used by some of my other programs. -

    -

    2.4 Compilers

    -

    - next - skip - - up - start -

    - - - - - -
    - 2.4.1 AT&T
    - 2.4.2 Borland
    - 2.4.3 Gnu G++
    - 2.4.4 HPUX -
    - 2.4.5 Intel
    - 2.4.6 Microsoft
    - 2.4.7 Sun
    - 2.4.8 Watcom -
    -

    - I have tested this library on a number of compilers. Here are the levels - of success and any special considerations. In most cases I have chosen - code that works under all the compilers I have access to, but I have had - to include some specific work-arounds for some compilers. For the newest - PC versions, I use a Pentium 4 computer running windows XP or Linux (Red - Hat workstation version). The Unix versions are on a Sun Sparc station. - Thanks to Victoria University for access to the Sparc. -

    -

    - I have set up a block of code for each of the compilers in include.h. - Turbo, Borland, Gnu, Microsoft and Watcom are recognised automatically. - There is a default option that works for AT&T, Sun C++ and HPUX. So - you don't have to make any changes for these compilers. Otherwise you may - have to build your own set of options in include.h. -

    -

    2.4.1 AT&T

    -

    - next - skip - - up - start -

    -

    - The AT&T compiler used to be available on a wide variety of Unix - workstations. I don't know if anyone still uses it. However the AT&T - options are the default if your compiler is not recognised. -

    -

    - AT&T C++ 2.1; 3.0.1 on a Sun: Previous versions worked on these - compilers, which I no longer have access to. -

    -

    - In AT&T 2.1 you may get an error when you use an expression for the - single argument when constructing a Vector or DiagonalMatrix or one of the - Triangular Matrices. You need to evaluate the expression separately. -

    -

    2.4.2 Borland

    -

    - next - skip - - up - start -

    -

    Newer compilers

    -

    - Borland Builder version 8. My tests here have been compiling from a - make file using nm_b58.mak and making a console program. This - works fine except that my values of LnMinimum and - LnMaximum in precisio.h are not correct. -

    -

    - Borland Builder version 6: My tests have been on the - personal version. See the notes for version 5. If you are compiling - with a make file you can use nm_b56.mak as a model. You can set the - newmat options to use namespace and the standard library. If you - are compiling a GUI program you may need to comment out the line defining - TypeDefException in include.h. I don't believe exceptions - work completely correctly in either version 5 or version 6. However, this - does not seem to be a problem with my use of them in newmat. -

    -

    - Borland Builder version 5: This works fine in console mode and no - special editing of the source codes is required. I haven't tested it in - GUI mode. You can set the newmat options to use namespace and the - standard library. - - You should turn off the Borland option to use pre-compiled - headers. - There are notes on compiling with the IDE on my - website. Alternatively you can use the - nm_b55.mak make file. -

    -

    - Borland Builder version 4: I have successfully used this on older - versions of newmat using the console wizard (menu item file/new - select - new tab). Use compiler exceptions. Suppose you are compiling my test - program tmt. Rename my main() function in tmt.cpp to - my_main(). Rename tmt.cpp to tmt_main.cpp. Borland - will generate a new file tmt.cpp containing their - main() function. Put the line int my_main(); above this - function and put return my_main(); into the body of - main(). -

    -

    - Borland compiler version 5.5: this is the free C++ compiler - available from Borland's web site. I suggest you use the compiler - supported exceptions and turn on standard in include.h. You can use - the make file nm_b55.mak after editing to correct the file - locations for your system. -

    -

    Older compilers

    -

    Borland C++ 5.02:

    -

    I am not longer checking compatibility with this compiler.

    -

    - Use the large or 32 bit flat model. If you are not debugging, turn off the - options that collect debugging information. Use my simulated exceptions. -

    -

    - When running my test program under ms-dos you may run out of memory. - Either compile the test routine to run under easywin or use - simulated exceptions rather than the built in exceptions. -

    -

    - If you can, upgrade to windows 95 or window NT and use the 32 bit console - model. -

    -

    - If you are using the 16 bit large model, don't forget to keep all matrices - less than 64K bytes in length (90x90 for a rectangular matrix if you are - using double as your element type). Otherwise your program will - crash without warning or explanation. You will need to break the - tmt set of test files into several parts to get the - program to fit into your computer and run without stack overflow. -

    -

    - You can generate make files for versions 5 with my - genmake utility. -

    -

    Borland C++ 3 and 4.

    -

    - The program used to compile in version 3.1 if you enable the - simulated booleans - comment out the line - #define bool_LIB 0 in include.h and use the - simulated exceptions. I haven't checked the latest versions of - Newmat. The main test program is too large to run unless you break it up - into several parts. I haven't tried it under version 4. -

    -

    2.4.3 Gnu G++

    -

    - next - skip - - up - start -

    -

    - Gnu G++ 3, 4 (Linux), 3 (Sun): These work OK. If you are using a - much earlier version see if you can upgrade. It  used to work with - 2.95 and 2.96 but I don't have access to these now. You can't use - standard with the 2.9X versions. The namespace option worked with - 2.96 on Linux but not with 2.95 on the Sun. Standard is automatically - turned on with the 3.X. -

    -

    - This version of Newmat is not compatible with versions 2.6 or earlier. -

    -

    2.4.4 HP-UX

    -

    - next - skip - - up - start -

    -

    - HP 9000 series HP-UX. I no longer have access to this compiler. Newmat09 - worked without problems with the simulated exceptions; haven't tried the - built-in exceptions. -

    -

    - With recent versions of the compiler you may get warning messages like - Unsafe cast between pointers/references to incomplete classes. At - present, I think these can be ignored. -

    - -

    2.4.5 Intel

    -

    - next - skip - - up - start -

    - -

    - Newmat works correctly with the Intel 10 C++ compiler for Windows and - Linux. (Not tested for the other versions). Standard is automatically - turned on for both the Linux versions and Windows versions. If this causes - a problem for the version you are using you can find the lines in - include.h that control this and comment them out. Note that the - Intel compiler for Linux is free for non-commercial use. (One of - the versions of 8.1 gave a warning message every time I had something like - Real x; ... if (x==0.0) ..., which was often. This is now seems - to be fixed.) -

    - -

    2.4.6 Microsoft

    -

    - next - skip - - up - start -

    -

    Newer versions

    -

    - See my web site for instructions how to work - Microsoft's IDE. -

    -

    - Microsoft Visual C++ 7, 7.1, 8: These work OK. All my tests have - been in console mode. You can turn on my namespace option. Standard is - turned on by default for these versions. -

    -

    - Microsoft Visual C++ 6: Get the latest service pack. I have - tried this in console mode and it seems to work satisfactorily. Use the - compiler supported exceptions. You may be able to use the namespace and - standard options. If you want to work under MFC you may need to - #include "stdafx.h" at the beginning of each .cpp file - (or turn off precompiled headers). -

    -

    - Microsoft Visual C++ 5: I have tried this in console mode on - previous versions of Newmat. It seems to work satisfactorily. There may be - a problem with namespace (fixed by Service Pack 3?). - Turn optimisation off. Use the compiler supported exceptions. If - you want to work under MFC  you may need to - #include "stdafx.h" at the beginning of each .cpp file - (or turn off precompiled headers). -

    -

    Older versions

    -

    I doubt whether these will work.

    -

    2.4.7 Sun

    -

    - next - skip - - up - start -

    -

    - Sun C++ (version = ?): This seems to work fine with compiler - supported exceptions. Sun C++ (version 5): There was a problem with - exceptions. If you use my simulated exceptions the non-linear optimisation - programs hang. If you use the compiler supported exceptions my tmt and - test_exc programs crash. You should disable exceptions. -

    -

    2.4.8 Watcom

    -

    - next - skip - - up - start -

    -

    - Open Watcom (version 1.7a): this works. You can set the standard - option in include.h. The scientific and - fixed manipulators don't work. -

    -

    - Watcom C++ (version 10a): this used to work, I don't know if it - works now. -

    -

    2.5 Updating from previous versions

    -

    - next - skip - - up - start -

    -

    - Newmat11 - if you are upgrading from earlier versions note the - following: -

    -
      -
    • - The class Exception in myexcept.h has been replaced by - BaseException and a typedef statement included so - programs that use the Exception class will still work. If the - Exception class was causing a problem comment out the line - defining TypeDefException in include.h. -
    • -
    • - Newmat11 does not support the TEMP_DESTROYED_QUICKLY options so won't - work with very old versions of Gnu G++ -
    • -
    • Old AT&T work-arounds are removed
    • -
    • - The simulated Booleans class is now stored at the end of include.h. In - general, I am not testing with compilers that don't support bool. -
    • -
    • - QRZ and QRZT no longer throw an exception if they generate a singular - triangular matrix -
    • -
    • - Converting functions to lower case. Both the old and new names will - work. See the list of functions for new and old - names -
    • -
    • - nm_i5.mak, nm_il5.mak replaced by nm_i8.mak, - nm_il8.mak -
    • -
    • extra file nm_misc.cpp to be included in compilation
    • -
    • - scientific and fixed manipulators now recognised in output - statements. If you want fixed output and have been using - scientific in a previous output statement, you may need to - include the fixed manipulator. (Doesn't work in Visual C++, - version 6 and open Watcom). -
    • -
    -

    - Newmat10 includes new maxima, minima, - determinant, dot product and Frobenius norm - functions, a faster FFT, revised - make files for GCC and CC compilers, several - corrections, new ReSize function, - IdentityMatrix and - Kronecker Product. Singular values from - SVD are sorted. The program files include a new file, - newfft.cpp, so you will need to include this in the list of files - in your IDE and make files. There is also a new test file tmtm.cpp. - Pointer arithmetic now mostly meets requirements of - standard. You can use << to load data into - rows of a matrix. The default options in include.h - have been changed. If you are updating from a beta version of newmat09 - look through the next section as there were some late changes to newmat09. -

    -

    If you are upgrading from newmat08 note the following:

    -
      -
    • - Boolean, TRUE, FALSE are now bool, true, false. See - customising if your compiler supports the bool - class. -
    • -
    • ReDimension is now ReSize.
    • -
    • - The simulated exception package has been updated. -
    • -
    • - Operators ==, !=, +=, -=, - *=, |=, &= are now supported as - binary matrix operators. -
    • -
    • - A+=f, A-=f, A*=f, A/=f, - f+A, f-A, f*A are supported for - A matrix, f scalar. -
    • -
    • Fast trigonometric transforms.
    • -
    • - Reverse function for reversing order of elements in - a vector or matrix. -
    • -
    • IsSingular function.
    • -
    • - An option is included for defining namespaces. -
    • -
    • - Dummy inequality operators are defined for compatibility with the STL. -
    • -
    • - The row/column classes in newmat3.cpp have been modified to improve - efficiency and correct an invalid use of pointer arithmetic. Most users - won't be using these classes explicitly; if you are, please contact me - for details of the changes. -
    • -
    • Matrix LU decomposition rewritten (faster for large arrays).
    • -
    • The sort function rewritten (faster).
    • -
    • - The documentation files newmata.txt and newmatb.txt have been - amalgamated and both are included in the hypertext version. -
    • -
    • Some of the make files reorganised again.
    • -
    -

    If you are upgrading from newmat07 note the following:

    -
      -
    • - .cxx files are now .cpp files. Some versions of won't accept .cpp. The - make files for Gnu and AT&T link the .cpp files to .cxx files - before compilation and delete the links after compilation. -
    • -
    • - An option in include.h allows you to use compiler - supported exceptions, simulated exceptions or disable exceptions. Edit - the file include.h to select one of these three options. Don't simulate - exceptions if you have set your compiler's option to implement - exceptions. -
    • -
    • New QR decomposition functions.
    • -
    • A non-linear least squares class.
    • -
    • No need to explicitly set the AT&T option in include.h.
    • -
    • - Concatenation and elementwise multiplication. -
    • -
    • A new GenericMatrix class.
    • -
    • Sum function.
    • -
    • Some of the make files reorganised.
    • -
    -

    If you are upgrading from newmat06 note the following:

    -
      -
    • - If you are using << to load a Real into a submatrix change this to - =. -
    • -
    -

    - If you are upgrading from newmat03 or newmat04 note the - following -

    -
      -
    • .hxx files are now .h files
    • -
    • real changed to Real
    • -
    • BOOL changed to Boolean
    • -
    • CopyToMatrix changed to AsMatrix, etc
    • -
    • real(A) changed to A.AsScalar()
    • -
    -

    - The current version is quite a bit longer that newmat04, so if you are - almost out of space with newmat04, don't throw newmat04 away until you - have checked your program will work under this version. -

    -

    See the change history for other changes.

    -

    2.6 Catching exceptions

    -

    - next - skip - - up - start -

    -

    - This section applies particularly to people using - compiler supported exceptions rather than my - simulated exceptions. -

    -
    -

    - If newmat detects an error it will throw an exception. It is important - that you catch this exception and print the error message. - Otherwise you will get an unhelpful message like - abnormal termination. -

    -
    -

    I suggest you set up your main program like 

    -
    -#define WANT_STREAM             // or #include <iostream>
    +   Internet: robert at statsresearch.co.nz
    + +[replace at by you-know-what.] + + +

    1.7 References

    +

    next - skip - +up - start

    +
      +
    • The matrix LU decomposition is from Golub, G.H. & Van Loan, C.F. +(1996), Matrix Computations, published by Johns Hopkins University +Press.
    • +
    • Part of the matrix inverse/solve routine is adapted from Press, Flannery, +Teukolsky, Vetterling (1988), Numerical Recipes in C, published by the +Cambridge University Press.
    • +
    • Many of the advanced matrix routines are adapted from routines in Wilkinson +and Reinsch (1971), Handbook for Automatic Computation, Vol II, Linear +Algebra published by Springer Verlag.
    • +
    • The fast Fourier transform is adapted from Carl de Boor (1980), Siam J +Sci Stat Comput, pp173-8 and the fast trigonometric transforms from Charles +Van Loan (1992) in Computational frameworks for the fast Fourier +transform published by SIAM.
    • +
    • The sort function is derived from Sedgewick, Robert (1992), Algorithms +in C++ published by Addison Wesley.
    • +
    +

    For references about Newmat see

    +
      +
    • Davies, R.B. (1994) Writing a matrix package in C++. In OON-SKI'94: The +second annual object-oriented numerics conference, pp 207-213. Rogue Wave +Software, Corvallis.
    • +
    • Eddelbuttel, Dirk (1996) Object-oriented econometrics: matrix programming +in C++ using GCC and Newmat. Journal of Applied Econometrics, Vol 11, No 2, pp +199-209.
    • +
    +

    2. Getting started

    +

    next - skip - +up - start

    + + + + + +
    2.1 Overview
    +2.2 Make files
    +2.3 Customising
    +2.4 Compilers
    +2.5 Updating from previous versions
    +2.6 Catching exceptions
    2.7 Examples
    +2.8 Testing
    +2.9 Bugs
    +2.10 Problem areas
    +2.11 Files in newmat11
    + 
    +

    2.1 Overview

    +

    next - skip - +up - start

    +

    I use .h as the suffix of definition files and .cpp as the suffix of C++ +source files.

    +

    You will need to compile all the *.cpp files listed as program files in the +files section to get the complete package. Ideally you +should store the resulting object files as a library. The tmt*.cpp files are +used for testing, example.cpp is an example and sl_ex.cpp, nl_ex.cpp and garch.cpp are examples +of the non-linear solve and optimisation routines. A +demonstration and test of the exception mechanism is in test_exc.cpp. The files +nm_ex1.cpp, nm_ex2.cpp and nm_ex3.cpp contain more simple examples.

    +

    I include a number of make files for compiling the example and the +test package. See the section on make files for details. +Alternatively, with the PC compilers, its pretty quick just to load all the files in the +interactive environments by pointing and clicking.

    +

    Use the large or win32 console model when you are using a PC. Do not +outline inline functions. You may need to increase the stack size on +older operating systems or compilers.

    +

    Your source files that access the newmat will need to #include one or more +of the following files.

    + + + + + + + + + + + + + + + + + + + + + +
    include.hto access just the compiler options
    newmat.hto access just the main matrix library (includes include.h)
    newmatap.hto access the advanced matrix routines such as Cholesky decomposition, QR +triangularisation etc (includes newmat.h)
    newmatio.hto access the output routines (includes newmat.h) You +can use this only with compilers that support the standard input/output +routines including manipulators (all recent compilers)
    newmatnl.hto access the non-linear optimisation routines (includes newmat.h)
    +

    See the section on customising to see how to edit +include.h for your environment and the section on compilers for any special problems with the compiler you +are using.

    +

    2.2 Make files

    +

    next - skip - +up - start

    +

    I have included make files for compiling my test and example programs for +various versions of CC, Borland, Microsoft, Open Watcom, Intel and Gnu compilers. You +can generate make files for a number of other compilers with my +genmake utility. Make files provide +a way of compiling your programs without using the IDE that comes with +PC compilers. See the files section for details.

    +

    PC

    +

    I include make files for various versions of Borland, Microsoft and Intel +compilers. With the +Borland compiler you will need to edit it to show where +you have stored your Borland compiler. For make files for other compilers use my +genmake utility. To compile my test and example +programs use Borland 5.5 (Builder 5) use

    +
       make -f nm_b55.mak
    +

    or with Borland 5.6 (Builder 6) use

    +
       make -f nm_b56.mak
    +

    or with Microsoft VC++ 6 or 7 use

    +
       nmake -f nm_m6.mak
    +

    There are some more notes in the +genmake documentation about using these make files.

    +

    Unix

    +

    The make file for the Unix CC compilers link a .cxx file to each .cpp +file since some of these compilers do not recognise .cpp as a legitimate +extension for a C++ file. I suggest you delete this part of the make +file and, if necessary, rename the .cpp files to something your compiler +recognises.

    +

    My make file for Gnu GCC on Unix systems is for use with +gmake rather than make. I assume your compiler recognises the +.cpp extension. Ordinary make works with it on the Sun but did not the +Silicon Graphics or HP machines when I had access to them, many years ago. On Linux use make.

    +

    My make file for the CC compilers works with the ordinary make.

    +

    To compile everything with the CC compiler use

    +
       make -f nm_cc.mak
    +
    + +

    or for the gnu compiler use

    +
       make -f nm_gnu.mak
    +
    + +

    There is a line in the make file for CC rm -f $*.cxx. Some systems +won't accept this line and you will need to delete it. In this case, if you +have a bad compile and you are using my scheme for linking .cxx files, you will +need to delete the .cxx file link generated by that compile before you can do +the next one.

    +

    2.3 Customising

    +

    next - skip - +up - start

    +

    The file include.h sets a variety of options including several +compiler dependent options. You may need to edit include.h to get the options +you require. If you are using a compiler different from one I have worked with +you may have to set up a new section in include.h appropriate for your +compiler.

    +

    Borland, Gnu, Microsoft and Watcom are recognised automatically. If +none of these are recognised a default set of options is used. These are fine +for AT&T, HPUX and Sun C++. If you using a compiler I don't know about you +may have to write a new set of options.

    +

    There is an option in include.h for selecting whether you use compiler +supported exceptions, simulated exceptions, or disable exceptions. I now set + compiler supported exceptions as the default. Use the option for +compiler supported exceptions if and only if you have set the option on +your compiler to recognise exceptions. Disabling exceptions sometimes helps +with compilers that are incompatible with my exception simulation scheme.

    +

    Activate the appropriate statement to make the element type float or +double. I suggest you leave it at double.

    +

    The option DO_FREE_CHECK is used for tracking memory +leaks and normally should not be activated.

    +

    Activate SETUP_C_SUBSCRIPTS if you want to use traditional C style +element access. Note that this does not change +the starting point for indices when you are using round brackets for accessing +elements or selecting submatrices. It does enable you to use C style square +brackets. This also activates additional constructors for Matrix, ColumnVector +and RowVector to simplify use with Numerical Recipes in C++.

    +

    Activate #define use_namespace if you want to use namespaces. Do this only if you are sure your compiler +supports namespaces. If you do turn this option on, be prepared to turn it off +again if the compiler reports inaccessible variables or the linker reports +missing links.

    +

    Activate #define _STANDARD_ to use the standard names for the +included files and to find the floating point precision data using the floating +point standard. This will work with most recent compilers and is done +automatically for Borland, Gnu, Intel and Microsoft compilers.

    +

    If you haven't defined _STANDARD_ and are using a compiler that +include.h does not recognise and you want to pick up the floating point +precision data from float.h then activate #define use_float_h. +Otherwise the floating point precision data will be accessed from +values.h. You may need to do this with computers from Digital, in +particular.

    +

    There is a line

    +
       //#define set_unix_options
    +

    You can activate this if you are using a Linux or Unix system. It is not used +by Newmat but is used by some of my other programs.

    +

    2.4 Compilers

    +

    next - skip - +up - start

    + + + + + +
    +2.4.1 AT&T
    +2.4.2 Borland
    +2.4.3 Gnu G++
    +2.4.4 HPUX
    +2.4.5 Intel
    +2.4.6 Microsoft
    +2.4.7 Sun
    +2.4.8 Watcom
    +

    I have tested this library on a number of compilers. Here are the levels of +success and any special considerations. In most cases I have chosen code that +works under all the compilers I have access to, but I have had to include some +specific work-arounds for some compilers. For the newest PC versions, I use a Pentium +4 computer running windows XP or Linux +(Red Hat workstation version). The Unix versions are on a Sun Sparc +station. Thanks to Victoria University for access to the Sparc.

    +

    I have set up a block of code for each of the compilers in include.h. Turbo, +Borland, Gnu, Microsoft and Watcom are recognised automatically. There is a +default option that works for AT&T, Sun C++ and HPUX. So you don't +have to make any changes for these compilers. Otherwise you may have to build +your own set of options in include.h.

    +

    2.4.1 AT&T

    +

    next - skip - +up - start

    +

    The AT&T compiler used to be available on a wide variety of Unix +workstations. I don't know if anyone still uses it. However the AT&T options are +the default if your compiler is not recognised.

    +

    AT&T C++ 2.1; 3.0.1 on a Sun: Previous versions worked on these +compilers, which I no longer have access to.

    +

    In AT&T 2.1 you may get an error when you use an expression for the +single argument when constructing a Vector or DiagonalMatrix or one of the +Triangular Matrices. You need to evaluate the expression separately.

    +

    2.4.2 Borland

    +

    next - skip - +up - start

    +

    Newer compilers

    +

    Borland Builder version 8. My tests here have been compiling from a +make file using nm_b58.mak and making a console program. This works fine +except that my values of LnMinimum and LnMaximum in precisio.h +are not correct.

    +

    Borland Builder version 6: My tests have been on the personal +version. See the notes for version 5. If you are +compiling with a make file you can use nm_b56.mak as a model. You can set +the newmat options to use namespace and the standard library. If you are +compiling a GUI program you may need to comment out the line defining +TypeDefException in include.h. I don't believe exceptions work +completely correctly in either version 5 or version 6. However, this does not +seem to be a problem with my use of them in newmat.

    +

    Borland Builder version 5: This works fine in console mode and no +special editing of the source codes is required. I haven't tested it in GUI +mode. You can set the newmat options to use namespace and the standard library. You +should turn off the Borland option to use pre-compiled headers. There +are notes on compiling with the IDE on my website. +Alternatively you can use the nm_b55.mak make file.

    +

    Borland Builder version 4: I have successfully used this on older +versions of newmat using the +console wizard (menu item file/new - select new tab). Use compiler +exceptions. Suppose you are compiling my test program tmt. Rename my +main() function in tmt.cpp to my_main(). Rename +tmt.cpp to tmt_main.cpp. Borland will generate a new file +tmt.cpp containing their main() function. Put the line int +my_main(); above this function and put return my_main(); into the +body of main().

    +

    Borland compiler version 5.5: this is the free C++ compiler available +from Borland's web site. I suggest you use +the compiler supported exceptions and turn on standard in include.h. You +can use the make file nm_b55.mak after editing to correct the file locations for +your system.

    +

    Older compilers

    +

    Borland C++ 5.02:

    +

    I am not longer checking compatibility with this compiler.

    +

    Use the large or 32 bit flat model. If you are not debugging, turn off the +options that collect debugging information. Use my simulated exceptions.

    +

    When running my test program under ms-dos you may run out of memory. Either +compile the test routine to run under easywin or use simulated exceptions +rather than the built in exceptions.

    +

    If you can, upgrade to windows 95 or window NT and use the 32 bit console +model.

    +

    If you are using the 16 bit large model, don't forget to keep all matrices +less than 64K bytes in length (90x90 for a rectangular matrix if you are using +double as your element type). Otherwise your program will crash +without warning or explanation. You will need to break the tmt set of test files into several parts to get the program +to fit into your computer and run without stack overflow.

    +

    You can generate make files for versions 5 with my +genmake utility.

    +

    Borland C++ 3 and 4.

    +

    The program used to compile in version 3.1 if you enable the simulated booleans +- comment out the line #define bool_LIB 0 in include.h +and use the simulated exceptions. I haven't checked the latest versions +of Newmat. The main test program is too large to run +unless you break it up into several parts. I haven't tried it under version 4.

    +

    2.4.3 Gnu G++

    +

    next - skip - +up - start

    +

    Gnu G++ 3, 4 (Linux), 3 (Sun): These work OK. If you are using a much earlier version +see if you can upgrade. It  used to work with 2.95 and 2.96 but I don't +have access to these now. You can't use standard with the 2.9X +versions. The namespace option worked with 2.96 on Linux but not with 2.95 on +the Sun. Standard is automatically turned on with the 3.X.

    +

    This version of Newmat is not compatible with versions 2.6 or earlier.

    +

    2.4.4 HP-UX

    +

    next - skip - +up - start

    +

    HP 9000 series HP-UX. I no longer have access to this compiler. Newmat09 +worked without problems with the simulated exceptions; haven't tried the +built-in exceptions.

    +

    With recent versions of the compiler you may get warning messages like +Unsafe cast between pointers/references to incomplete classes. At +present, I think these can be ignored.

    + +

    2.4.5 Intel

    +

    next - skip - +up - start

    + +

    Newmat works correctly with the Intel 10 C++ compiler for Windows and Linux. (Not tested for the other versions). Standard is +automatically turned on for both the Linux versions and Windows versions. If +this causes a problem for the version you are using you can find the lines in +include.h that control this and comment them out. Note that the Intel compiler for +Linux is free for non-commercial use. (One of the versions of 8.1 gave a +warning message every time I had something like +Real x; ... if (x==0.0) ..., which was often. This is now seems to be fixed.)

    + +

    2.4.6 Microsoft

    +

    next - skip - +up - start

    +

    Newer versions

    +

    See my web site for instructions how to work +Microsoft's IDE.

    +

    Microsoft Visual C++ 7, 7.1, 8: These work OK. All my tests have +been in console mode. You can turn on my namespace option. Standard is turned on +by default for these versions.

    +

    Microsoft Visual C++ 6: Get the latest service pack. I have tried this +in console mode and it seems to work satisfactorily. Use the compiler supported exceptions. You may be able to +use the namespace and standard options. If you want to work under MFC +you may need to #include "stdafx.h" at the beginning of each .cpp file +(or turn off precompiled headers).

    +

    Microsoft Visual C++ 5: I have tried this in console mode on previous +versions of Newmat. It +seems to work satisfactorily. There may be a problem with namespace (fixed by Service Pack 3?). Turn optimisation +off. Use the compiler supported exceptions. If +you want to work under MFC  +you may need to #include "stdafx.h" at the +beginning of each .cpp file (or turn off precompiled headers).

    +

    Older versions

    +

    I doubt whether these will work.

    +

    2.4.7 Sun

    +

    next - skip - +up - start

    +

    Sun C++ (version = ?): This seems to work fine with +compiler supported exceptions. Sun C++ (version +5): There was a problem with exceptions. If you use my simulated +exceptions the non-linear optimisation programs hang. If you use the compiler +supported exceptions my tmt and test_exc programs crash. You should +disable exceptions.

    +

    2.4.8 Watcom

    +

    next - skip - +up - start

    +

    Open Watcom (version 1.7a): this works. You can set the standard +option in include.h. The scientific and fixed +manipulators don't work.

    +

    Watcom C++ (version 10a): this used to work, I don't know if it works +now.

    +

    2.5 Updating from previous +versions

    +

    next - skip - +up - start

    +

    Newmat11 - if you are upgrading from earlier versions note the +following:

    +
      +
    • The class Exception in myexcept.h has been replaced by + BaseException and a typedef statement included so programs that use + the Exception class will still work. If the Exception class was + causing a problem comment out the line defining TypeDefException in + include.h.
    • +
    • Newmat11 does not support the TEMP_DESTROYED_QUICKLY options so won't work + with very old versions of Gnu G++
    • +
    • Old AT&T work-arounds are removed
    • +
    • The simulated Booleans class is now stored at the end of include.h. In + general, I am not testing with compilers that don't support bool.
    • +
    • QRZ and QRZT no longer throw an exception if they generate a singular + triangular matrix
    • +
    • Converting functions to lower case. Both the old and new names will work. See the list of + functions for new and old names
    • +
    • nm_i5.mak, nm_il5.mak replaced by nm_i8.mak, + nm_il8.mak
    • +
    • extra file nm_misc.cpp to be included in compilation
    • +
    • scientific and fixed manipulators now recognised in output + statements. If you want fixed output and have been using + scientific in a previous output statement, you may need to include the + fixed manipulator. (Doesn't work in Visual C++, version 6 and open + Watcom).
    • +
    +

    Newmat10 includes new maxima, minima, +determinant, dot product and Frobenius norm functions, a +faster FFT, revised make files for GCC +and CC compilers, several corrections, new ReSize function, IdentityMatrix +and Kronecker Product. Singular values from +SVD are sorted. The program files include a new file, newfft.cpp, so you +will need to include this in the list of files in your IDE and make files. There +is also a new test file tmtm.cpp. +Pointer arithmetic now mostly meets requirements of +standard. You can use << to load data into rows +of a matrix. The default options in include.h have been +changed. If you are updating from a beta version of newmat09 look through the +next section as there were some late changes to newmat09.

    +

    If you are upgrading from newmat08 note the following: +

    +
      +
    • Boolean, TRUE, FALSE are now bool, true, false. See +customising if your compiler supports the bool class. +
    • +
    • ReDimension is now ReSize. +
    • +
    • The simulated exception package has +been updated.
    • +
    • Operators ==, !=, +=, +-=, *=, |=, &= are now supported as +binary matrix operators.
    • +
    • A+=f, A-=f, A*=f, A/=f, +f+A, f-A, f*A are supported for A +matrix, f scalar.
    • +
    • Fast trigonometric transforms. +
    • +
    • Reverse function for reversing order of +elements in a vector or matrix.
    • +
    • IsSingular function.
    • +
    • An option is included for defining namespaces.
    • +
    • Dummy inequality operators are defined for compatibility +with the STL.
    • +
    • The row/column classes in newmat3.cpp have been modified to +improve efficiency and correct an invalid use of pointer arithmetic. Most users +won't be using these classes explicitly; if you are, please contact me for +details of the changes.
    • +
    • Matrix LU decomposition rewritten (faster for large arrays). +
    • +
    • The sort function rewritten (faster).
    • +
    • The documentation files newmata.txt and newmatb.txt have +been amalgamated and both are included in the hypertext version.
    • +
    • Some of the make files reorganised +again.
    • +
    +

    If you are upgrading from newmat07 note the following: +

    +
      +
    • .cxx files are now .cpp files. Some versions of won't accept +.cpp. The make files for Gnu and AT&T link the .cpp files to .cxx +files before compilation and delete the links after compilation.
    • +
    • An option in include.h allows you to +use compiler supported exceptions, simulated exceptions or disable exceptions. +Edit the file include.h to select one of these three options. Don't simulate +exceptions if you have set your compiler's option to implement exceptions. +
    • +
    • New QR decomposition functions. +
    • +
    • A non-linear least squares class. +
    • +
    • No need to explicitly set the AT&T option in include.h. +
    • +
    • Concatenation and elementwise +multiplication.
    • +
    • A new GenericMatrix class. +
    • +
    • Sum function.
    • +
    • Some of the make files reorganised. +
    • +
    +

    If you are upgrading from newmat06 note the following: +

    +
      +
    • If you are using << to load a Real into a submatrix +change this to =.
    • +
    +

    If you are upgrading from newmat03 or newmat04 +note the following

    +
      +
    • .hxx files are now .h files
    • +
    • real changed to Real
    • +
    • BOOL changed to Boolean
    • +
    • CopyToMatrix changed to AsMatrix, etc
    • +
    • real(A) changed to A.AsScalar()
    • +
    +

    The current version is quite a bit longer that newmat04, so +if you are almost out of space with newmat04, don't throw newmat04 away until +you have checked your program will work under this version.

    +

    See the change history for other changes.

    +

    2.6 Catching exceptions

    +

    next - skip - +up - start

    +

    This section applies particularly to people using compiler supported +exceptions rather than my simulated exceptions.

    +
    +

    If newmat detects an error it will throw an exception. It is important that +you catch this exception and print the error message. Otherwise you will get an +unhelpful message like abnormal termination.

    +
    +

    I suggest you set up your +main program like 

    +
    #define WANT_STREAM             // or #include <iostream>
     #include "newmat.h"             // or #include "newmatap.h"
     #include "newmatio.h"           // if you are using my matrix output functions
     
    @@ -1056,1103 +753,889 @@ 

    2.6 Catching exceptions

    catch(...) { cout << "exception caught in main program" << endl; } return 0; }
    -

    Or see my file nm_ex1.cpp for an easy way of organising this.

    -

    - If you are using a GUI version rather a console version of the program you - will need to catch the exception and display the error message in a pop-up - window. -

    -

    - If you are using my simulated exceptions or have set the disable - exceptions option in include.h then uncaught exceptions - automatically print the error message generated by the exception so you - can ignore this section. Alternatively use Try, Catch and - CatchAll in place of try, catch and - catch(...) in the preceding code. -

    -

    - See the section on exceptions for more information - on the exception structure. -

    -

    2.7 Examples

    -

    - next - skip - - up - start -

    -

    - I include a number of example files. See the sections on - make files and on - compilers for information about compiling them. -

    -

    - Invert matrix: nm_ex1.cpp. Load values into a 4x4 matrix; - invert it and check the result. The output is in nm_ex1.txt. -

    -

    - Eigenvalues and eigenvectors of Hilbert matrix: - nm_ex2.cpp. Calculate the eigenvalues and eigenvectors of a 7x7 - Hilbert matrix. The output is in nm_ex2.txt. -

    -

    Values in precisio.h: nm_ex3.cpp.

    -

    - Linear regression example: example.cpp. This gives a - linear regression example using five different algorithms. The correct - output is given in example.txt. The program carries out a rough - check that no memory is left allocated on the heap when it terminates. See - the section on testing for a comment on the - reliability of this check and the use of the DO_FREE_CHECK option. -

    -

    - Other example files are nl_ex.cpp and garch.cpp for - demonstrating the non-linear fitting routines, sl_ex for - demonstrating the solve function and test_exc for demonstrating - and testing exception handling. -

    -

    2.8 Testing

    -

    - next - skip - - up - start -

    -

    - The library package contains a comprehensive test program in the form of a - series of files with names of the form tmt?.cxx. The files consist of a - large number of matrix formulae all of which evaluate to zero (except the - first one which is used to check that we are detecting non-zero matrices). - The printout should state that it has found just one non-zero matrix. -

    -

    - The test program should be run with Real typedefed to - double rather than float in include.h. -

    -

    - Make sure the C subscripts are enabled if you want - to test these. -

    -

    - If you are carrying out some form of bounds checking, for example, with - Borland's CodeGuard, then disable the testing of the - Numerical Recipes in C interface. Activate the - statement #define DONT_DO_NRIC in tmt.h. -

    -

    - Various versions of the make file (extension .mak) are included with the - package. See the section on make files. -

    -

    - The program also allocates and deletes a large block and small block of - memory before it starts the main testing and then at the end of the test. - It then checks that the blocks of memory were allocated in the same place. - If not, then one suspects that there has been a memory leak. i.e. a piece - of memory has been allocated and not deleted. -

    -

    - This is not foolproof. For example, programs may allocate extra print - buffers while the program is running. I have tried to overcome this by - doing a print before I allocate the first memory block. Programs may - allocate memory for different sized items in different places, or might - not allocate items consecutively. Or they might mix the items with memory - blocks from other programs. Nevertheless, I seem to get consistent answers - from some of the compilers I work with, so I think this is a - worthwhile test. The compilers that the test seems to work for include the - Borland compilers, Microsoft VC++ 6 , Watcom, and Gnu 2.96 for Linux. -

    -

    - If the DO_FREE_CHECK option in include.h is - activated, the program checks that each new is balanced with - exactly one delete. This provides a more definitive test of no - memory leaks. There are additional statements in myexcept.cpp which can be - activated to print out details of the memory being allocated and released. -

    -

    - I have included a facility for checking that each piece of code in the - library is really exercised by the test routines. Each block of code in - the main part of the library contains a word REPORT. - newmat.h has a line defining REPORT that can be - activated (deactivate the dummy version). This gives a printout of the - number of times each of the REPORT statements in the - .cpp files is accessed. Use a grep with line numbers to locate - the lines on which REPORT occurs and compare these with the lines - that the printout shows were actually accessed. One can then see which - lines of code were not accessed. -

    -

    2.9 Bugs

    -

    - next - skip - - up - start -

    -
      -
    • - Small memory leaks may occur when an exception is thrown and caught. -
    • -
    • - My exception scheme may not be not properly linked in with the standard - library exceptions. In particular, my scheme may fail to catch - out-of-memory exceptions. -
    • -
    -

    2.10 Problem areas

    -

    - next - skip - - up - start -

    -

    - This section lists parts of Newmat which users (including me) have - found difficult or unnatural. Also see the - newmat FAQ list on my - website. -

    -

    - Invert, element access, matrix multiply etc causes the program to - crash -

    -
    -

    - Newmat throws an exception when it detects an error. This can cause a - program crash unless the exception is caught with a - catch statement. See catching exceptions. -

    -
    -

    - 1x1 matrix not automatically converted to a Real -

    -
    -

    - Use the as_scalar() member function or the - dotproduct() function to take the dot product of - two vectors. -

    -
    -

    Constructors do not initialise elements

    -
    -

    - For example, Matrix A(4,5); does not initialise the elements of - A. Use the statement A=0.0 to set the values to zero. -

    -
    -

    - resize does not initialise elements -

    -
    -

    - For example, A.resize(5,6); does not set the elements of - A. If you want to keep values use resize_keep. See - resize. -

    -
    -

    Setting Matrix to a scalar sets all the values

    -
    -

    - A(1,3) = 0.0; sets one element of a Matrix to zero. - A = 0.0; sets all the elements to zero. This is very convenient - but also a source of error that is hard to see if you wanted - A(1,3) = 0.0; but left out the element details. -

    -
    -

    Symmetry not detected automatically

    -
    -

    - For example, SymmetricMatrix SM = A.t() * A; will fail. Use - SymmetricMatrix SM; SM << A.t() * A; -

    -
    -

    - << does not work with constructors -

    -
    -

    - For example, SymmetricMatrix SM << A.t() * A; does not - work. -

    -
    -

    Multiple multiplication may be inefficient

    -
    -

    - For example, A * B * X where A and B are - matrices and X is a column vector is likely to be much slower - than A * (B * X). -

    -
    -

     

    -

    2.11 List of files

    -

    - next - skip - - up - start -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Documentationreadme.txtreadme file
     nm11.htmdocumentation file
     add_time.pgnimage used by nm11.htm
     rbd.cssstyle sheet for nm11.htm
     _newmat.doxdescription file for Doxygen
     _rbd_com.doxdescription file for Doxygen
    Header filescontrolw.hcontrol word definition file
     include.hdetails of include files and options
     myexcept.hgeneral exception handler definitions
     newmat.hmain matrix class definition file
     newmatap.happlications definition file
     newmatio.hinput/output definition file
     newmatnl.hnon-linear optimisation definition file
     newmatrc.hrow/column functions definition files
     newmatrm.hrectangular matrix access definition files
     precisio.hnumerical precision constants
     solution.hone dimensional solve definition file
    Program filesbandmat.cppband matrix routines
     cholesky.cppCholesky decomposition
     evalue.cppeigenvalues and eigenvector calculation
     fft.cppfast Fourier, trig. transforms
     hholder.cppQR routines
     jacobi.cppeigenvalues by the Jacobi method
     myexcept.cppgeneral error and exception handler
     newfft.cppnew fast Fourier transform
     newmat1.cpptype manipulation routines
     newmat2.cpprow and column manipulation functions
     newmat3.cpprow and column access functions
     newmat4.cppconstructors, resize, utilities
     newmat5.cpptranspose, evaluate, matrix functions
     newmat6.cppoperators, element access
     newmat7.cppinvert, solve, binary operations
     newmat8.cppLU decomposition, scalar functions
     newmat9.cppoutput routines
     newmatex.cppmatrix exception handler
     newmatnl.cppnon-linear optimisation
     newmatrm.cpprectangular matrix access functions
     nm_misc.cppmiscellaneous classes, functions
     sort.cppsorting functions
     solution.cppone dimensional solve
     submat.cppsubmatrix functions
     svd.cppsingular value decomposition
    Example filesnm_ex1.cppsimple example - invert matrix
     nm_ex1.txtoutput from nm_ex1.cpp
     nm_ex2.cppsimple example - eigenvalues of Hilbert matrix
     nm_ex2.txtoutput from nm_ex2.cpp
     nm_ex3.cppscientific format and constants from precisio.h
     nm_ex3.txtoutput from nm_ex3.cpp
     example.cppexample of use of package
     example.txtoutput from example
     sl_ex.cppexample of OneDimSolve routine
     sl_ex.txtoutput from example
     nl_ex.cppexample of non-linear least squares
     nl_ex.txtoutput from example
     garch.cppexample of maximum-likelihood fit
     garch.datdata file for garch.cpp
     garch.txtoutput from example
     test_exc.cppdemonstration exceptions
     test_exc.txtoutput from test_exc.cpp
    Test filestmt.hheader file for test files
     tmt*.cpp - test files (see the section on testing) -
     tmt.txtoutput from test files
    Make filesnm_gnu.makmake file for Gnu G++
     nm_cc.makmake file for AT&T, Sun and HPUX
     nm_b55.makmake file for Borland C++ 5.5
     nm_b56.makmake file for Borland Builder C++ 6
     nm_b58.makmake file for Borland Builder C++ 8
     nm_m6.makmake file for VC++ 6&7
     nm_m8.makmake file for VC++ 8
     nm_i8.makmake file for Intel C++ 8,9 under Windows
     nm_i10.makmake file for Intel C++ 10 under Windows
     nm_il8.makmake file for Intel C++ 8,9,10 under Linux
     nm_ow.makmake file for Open Watcom
     newmat.lfl - library file list for use with genmake -
     nm_targ.txt - target file list for use with genmake -
     Makefile.inused for compiling with Opt++
    - -

     

    -

    - These are the .cpp files you need to include in your make file or project: -

    -

    Basic newmat

    - - - - - - - -
    -
      -
    • bandmat.cpp
    • -
    • myexcept.cpp
    • -
    • newmat1.cpp
    • -
    • newmat2.cpp
    • -
    -
    -
      -
    • newmat3.cpp
    • -
    • newmat4.cpp
    • -
    • newmat5.cpp
    • -
    • newmat6.cpp
    • -
    -
    -
      -
    • newmat7.cpp
    • -
    • newmat8.cpp
    • -
    • newmat9.cpp
    • -
    • newmatex.cpp
    • -
    -
    -
      -
    • newmatrm.cpp
    • -
    • submat.cpp
    • -
    -
    -

    Factorisations etc

    - - - - - - - -
    -
      -
    • cholesky.cpp
    • -
    • evalue.cpp
    • -
    • fft.cpp
    • -
    -
    -
      -
    • hholder.cpp
    • -
    • jacobi.cpp
    • -
    -
    -
      -
    • sort.cpp
    • -
    • svd.cpp
    • -
    -

     

    -
    -
      -
    • newfft.cpp
    • -
    • nm_misc.cpp
    • -
    -
    -

    Nonlinear routines

    - - - - - - - -
    -
      -
    • newmatnl.cpp
    • -
    -
    -
      -
    • solution.cpp
    • -
    -
    -

     

    - -

    3. Reference manual

    -

    - next - skip - - up - start -

    - - - - - -
    - 3.1 Constructors
    - 3.2 Accessing elements
    - 3.3 Assignment and copying
    - 3.4 Entering values
    - 3.5 Unary operations
    - 3.6 Binary operations
    - 3.7 Matrix and scalar ops
    - 3.8 Scalar functions - size & shape
    - 3.9 Scalar functions - maximum & minimum
    - 3.10 Scalar functions - numerical
    - 3.11 Submatrices
    - 3.12 Change dimension
    - 3.13 Change type
    - 3.14 Multiple matrix solve
    - 3.15 Memory management
    - 3.16 Efficiency
    - 3.17 Output
    - 3.18 Accessing unspecified type -
    - 3.19 Cholesky decomposition
    - 3.20 QR decomposition
    - 3.21 Singular value decomposition
    - 3.22 Eigenvalue decomposition
    - 3.23 Sorting
    - 3.24 Fast Fourier transform
    - 3.25 Fast trigonometric transforms
    - 3.26 Numerical recipes in C
    - 3.27 Exceptions
    - 3.28 Cleanup following exception
    - 3.29 Non-linear applications
    - 3.30 Standard template library
    - 3.31 Namespace
    - 3.32 Updating the Cholesky matrix
    - 3.33 Accessing C functions
    - 3.34 Simple integer array class
    - 3.35 Extend orthonormal set of columns
    - 3.36 Miscellaneous functions -
    -

    See also function summary.

    - -

    3.1 Constructors

    -

    - next - skip - - up - start -

    -

    - To construct an m x n matrix, A, (m and - n are integers) use -

    -
    -    Matrix A(m,n);
    -
    - -

    - The SquareMatrix, UpperTriangularMatrix, LowerTriangularMatrix, - SymmetricMatrix and DiagonalMatrix types are square. To construct an - n x n matrix use, for example -

    -
    -    SquareMatrix SQ(n);
    +

    Or see my file nm_ex1.cpp for an easy way of organising this.

    +

    If you are using a GUI version rather a console version of the program you +will need to catch the exception and display the error message in a pop-up +window.

    +

    If you are using my simulated exceptions or have set the disable exceptions +option in include.h then uncaught exceptions automatically print the +error message generated by the exception so you can ignore this section. +Alternatively use Try, Catch and CatchAll in place of try, catch +and catch(...) in the preceding code.

    +

    See the section on exceptions for more information on +the exception structure.

    +

    2.7 Examples

    +

    next - skip - +up - start

    +

    I include a number of example files. See the sections on make +files and on compilers for information about compiling +them.

    +

    Invert matrix: nm_ex1.cpp. Load values into a 4x4 matrix; invert it +and check the result. The output is in nm_ex1.txt.

    +

    Eigenvalues and eigenvectors of Hilbert matrix: nm_ex2.cpp. Calculate the +eigenvalues and eigenvectors of a 7x7 Hilbert matrix. The output is in +nm_ex2.txt.

    +

    Values in precisio.h: nm_ex3.cpp.

    +

    Linear regression example: example.cpp. This gives a linear +regression example using five different algorithms. The correct output is given +in example.txt. The program carries out a rough check that no memory +is left allocated on the heap when it terminates. See the section on +testing for a comment on the reliability of this check +and the use of the DO_FREE_CHECK option.

    +

    Other example files are nl_ex.cpp and garch.cpp for +demonstrating the non-linear fitting routines, sl_ex for demonstrating +the solve function and test_exc for demonstrating and testing exception +handling.

    +

    2.8 Testing

    +

    next - skip - +up - start

    +

    The library package contains a comprehensive test program in the form of a +series of files with names of the form tmt?.cxx. The files consist of a large +number of matrix formulae all of which evaluate to zero (except the first one +which is used to check that we are detecting non-zero matrices). The printout +should state that it has found just one non-zero matrix.

    +

    The test program should be run with Real typedefed to double +rather than float in include.h.

    +

    Make sure the C subscripts are enabled if you want +to test these.

    +

    If you are carrying out some form of bounds checking, for example, with +Borland's CodeGuard, then disable the testing of the Numerical Recipes in C interface. Activate the statement +#define DONT_DO_NRIC in tmt.h.

    +

    Various versions of the make file (extension .mak) are included with the +package. See the section on make files.

    +

    The program also allocates and deletes a large block and small block of +memory before it starts the main testing and then at the end of the test. It +then checks that the blocks of memory were allocated in the same place. If not, +then one suspects that there has been a memory leak. i.e. a piece of memory has +been allocated and not deleted.

    +

    This is not foolproof. For example, programs may allocate extra print buffers +while the program is running. I have tried to overcome this by doing a print +before I allocate the first memory block. Programs may allocate memory for +different sized items in different places, or might not allocate items +consecutively. Or they might mix the items with memory blocks from other +programs. Nevertheless, I seem to get consistent answers from some of the +compilers I work with, so I think this is a worthwhile test. The compilers that +the test seems to work for include the Borland compilers, Microsoft VC++ 6 , +Watcom, and Gnu 2.96 for Linux.

    +

    If the DO_FREE_CHECK option in include.h is activated, +the program checks that each new is balanced with exactly one +delete. This provides a more definitive test of no memory leaks. There +are additional statements in myexcept.cpp which can be activated to print out +details of the memory being allocated and released.

    +

    I have included a facility for checking that each piece of code in the +library is really exercised by the test routines. Each block of code in the +main part of the library contains a word REPORT. newmat.h has +a line defining REPORT that can be activated (deactivate the dummy +version). This gives a printout of the number of times each of the +REPORT statements in the .cpp files is accessed. Use a grep +with line numbers to locate the lines on which REPORT occurs and +compare these with the lines that the printout shows were actually accessed. +One can then see which lines of code were not accessed.

    +

    2.9 Bugs

    +

    next - skip - +up - start

    +
      +
    • Small memory leaks may occur when an exception is thrown and caught.
    • +
    • My exception scheme may not be not properly linked in with the standard +library exceptions. In particular, my scheme may fail to catch out-of-memory +exceptions.
    • +
    +

    2.10 Problem areas

    +

    next - skip - +up - start

    +

    This section lists parts of Newmat which users (including me) have found +difficult or unnatural. Also see the newmat FAQ list on +my website.

    +

    Invert, element access, matrix multiply etc causes the program to crash

    +
    +

    Newmat throws an exception when it detects an error. This can cause a program +crash unless the exception is caught with a catch statement. See +catching exceptions.

    +
    +

    1x1 matrix not automatically converted to a Real

    +
    +

    Use the as_scalar() member function or the +dotproduct() function to take the dot +product of two vectors.

    +
    +

    Constructors do not initialise elements

    +
    +

    For example, Matrix A(4,5); does not initialise the elements of A. Use the +statement A=0.0 to set the values to zero.

    +
    +

    resize does not initialise elements

    +
    +

    For example, A.resize(5,6); does not set the elements of A. +If you want to keep values use resize_keep. See resize.

    +
    +

    Setting Matrix to a scalar sets all the values

    +
    +

    A(1,3) = 0.0; sets one element of a Matrix to zero. A = 0.0; sets all the +elements to zero. This is very convenient but also a source of error that is + +hard to see if you wanted A(1,3) = 0.0; but left out the element details.

    +
    +

    Symmetry not detected automatically

    +
    +

    For example, SymmetricMatrix SM = A.t() * A; will fail. Use SymmetricMatrix +SM; SM << A.t() * A;

    +
    +

    << does not work with constructors

    +
    +

    For example, SymmetricMatrix SM << A.t() * A; does not work.

    +
    +

    Multiple multiplication may be inefficient

    +
    +

    For example, A * B * X where A and B are matrices and X is a column vector is +likely to be much slower than A * (B * X).

    +
    +

     

    +

    2.11 List of files

    +

    next - skip - +up - start

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Documentationreadme.txtreadme file
     nm11.htmdocumentation file
     add_time.pgnimage used by nm11.htm
     rbd.cssstyle sheet for nm11.htm
     _newmat.doxdescription file for Doxygen
     _rbd_com.doxdescription file for Doxygen
    Header filescontrolw.hcontrol word definition file
     include.hdetails of include files and options
     myexcept.hgeneral exception handler definitions
     newmat.hmain matrix class definition file
     newmatap.happlications definition file
     newmatio.hinput/output definition file
     newmatnl.hnon-linear optimisation definition file
     newmatrc.hrow/column functions definition files
     newmatrm.hrectangular matrix access definition files
     precisio.hnumerical precision constants
     solution.hone dimensional solve definition file
    Program filesbandmat.cppband matrix routines
     cholesky.cppCholesky decomposition
     evalue.cppeigenvalues and eigenvector calculation
     fft.cppfast Fourier, trig. transforms
     hholder.cppQR routines
     jacobi.cppeigenvalues by the Jacobi method
     myexcept.cppgeneral error and exception handler
     newfft.cppnew fast Fourier transform
     newmat1.cpptype manipulation routines
     newmat2.cpprow and column manipulation functions
     newmat3.cpprow and column access functions
     newmat4.cppconstructors, resize, utilities
     newmat5.cpptranspose, evaluate, matrix functions
     newmat6.cppoperators, element access
     newmat7.cppinvert, solve, binary operations
     newmat8.cppLU decomposition, scalar functions
     newmat9.cppoutput routines
     newmatex.cppmatrix exception handler
     newmatnl.cppnon-linear optimisation
     newmatrm.cpprectangular matrix access functions
     nm_misc.cppmiscellaneous classes, functions
     sort.cppsorting functions
     solution.cppone dimensional solve
     submat.cppsubmatrix functions
     svd.cppsingular value decomposition
    Example filesnm_ex1.cppsimple example - invert matrix
     nm_ex1.txtoutput from nm_ex1.cpp
     nm_ex2.cppsimple example - eigenvalues of Hilbert matrix
     nm_ex2.txtoutput from nm_ex2.cpp
     nm_ex3.cppscientific format and constants from precisio.h
     nm_ex3.txtoutput from nm_ex3.cpp
     example.cppexample of use of package
     example.txtoutput from example
     sl_ex.cppexample of OneDimSolve routine
     sl_ex.txtoutput from example
     nl_ex.cppexample of non-linear least squares
     nl_ex.txtoutput from example
     garch.cppexample of maximum-likelihood fit
     garch.datdata file for garch.cpp
     garch.txtoutput from example
     test_exc.cppdemonstration exceptions
     test_exc.txtoutput from test_exc.cpp
    Test filestmt.hheader file for test files
     tmt*.cpptest files (see the section on testing)
     tmt.txtoutput from test files
    Make filesnm_gnu.makmake file for Gnu G++
     nm_cc.makmake file for AT&T, Sun and HPUX
     nm_b55.makmake file for Borland C++ 5.5
     nm_b56.makmake file for Borland Builder C++ 6
     nm_b58.makmake file for Borland Builder C++ 8
     nm_m6.makmake file for VC++ 6&7
     nm_m8.makmake file for VC++ 8
     nm_i8.makmake file for Intel C++ 8,9 under Windows
     nm_i10.makmake file for Intel C++ 10 under Windows
     nm_il8.makmake file for Intel C++ 8,9,10 under Linux
     nm_ow.makmake file for Open Watcom
     newmat.lfllibrary file list for use with genmake
     nm_targ.txttarget file list for use with genmake
     Makefile.inused for compiling with Opt++
    + +

     

    +

    These are the .cpp files you need to include in your make file or project:

    +

    Basic newmat

    + + + + + + + +
      +
    • bandmat.cpp
    • +
    • myexcept.cpp
    • +
    • newmat1.cpp
    • +
    • newmat2.cpp
    • +
    +
      +
    • newmat3.cpp
    • +
    • newmat4.cpp
    • +
    • newmat5.cpp
    • +
    • newmat6.cpp
    • +
    +
      +
    • newmat7.cpp
    • +
    • newmat8.cpp
    • +
    • newmat9.cpp
    • +
    • newmatex.cpp
    • +
    +
      +
    • newmatrm.cpp
    • +
    • submat.cpp
    • +
    +
    +

    Factorisations etc

    + + + + + + + +
      +
    • cholesky.cpp
    • +
    • evalue.cpp
    • +
    • fft.cpp
    • +
    +
    +
      +
    • hholder.cpp
    • +
    • jacobi.cpp
    • +
    +
    +
      +
    • sort.cpp
    • +
    • svd.cpp
    • +
    +

     

      +
    • newfft.cpp
    • +
    • nm_misc.cpp
    • +
    +
    +

    Nonlinear routines

    + + + + + + + +
      +
    • newmatnl.cpp
    • +
    +
      +
    • solution.cpp
    • +
    +
    +

     

    + +

    3. Reference manual

    +

    next - skip - +up - start

    + + + + + +
    3.1 +Constructors
    +3.2 Accessing elements
    +3.3 Assignment and copying
    +3.4 Entering values
    +3.5 Unary operations
    +3.6 Binary operations
    +3.7 Matrix and scalar ops
    +3.8 Scalar functions - size & shape
    +3.9 Scalar functions - maximum & minimum
    +3.10 Scalar functions - numerical
    +3.11 Submatrices
    +3.12 Change dimension
    +3.13 Change type
    +3.14 Multiple matrix solve
    +3.15 Memory management
    +3.16 Efficiency
    +3.17 Output
    +3.18 Accessing unspecified type
    +3.19 Cholesky decomposition
    +3.20 QR decomposition
    +3.21 Singular value decomposition
    +3.22 Eigenvalue decomposition
    +3.23 Sorting
    +3.24 Fast Fourier transform
    +3.25 Fast trigonometric transforms
    +3.26 Numerical recipes in C
    +3.27 Exceptions
    +3.28 Cleanup following exception
    +3.29 Non-linear applications
    +3.30 Standard template library
    +3.31 Namespace
    +3.32 Updating the Cholesky matrix
    +3.33 Accessing C functions
    +3.34 Simple integer array class
    +3.35 Extend orthonormal set of columns
    +3.36 Miscellaneous functions
    +

    See also function summary.

    + +

    3.1 Constructors

    +

    next - skip - +up - start

    +

    To construct an m x n matrix, A, (m and +n are integers) use

    +
        Matrix A(m,n);
    +
    + +

    The SquareMatrix, UpperTriangularMatrix, LowerTriangularMatrix, SymmetricMatrix and +DiagonalMatrix types are square. To construct an n x n matrix +use, for example

    +
        SquareMatrix SQ(n);
         UpperTriangularMatrix UT(n);
         LowerTriangularMatrix LT(n);
         SymmetricMatrix S(n);
         DiagonalMatrix D(n);
    -
    +
    -

    - Band matrices need to include bandwidth information in their constructors. -

    -
    -    BandMatrix BM(n, lower, upper);
    +

    Band matrices need to include bandwidth information in their constructors. +

    +
        BandMatrix BM(n, lower, upper);
         UpperBandMatrix UB(n, upper);
         LowerBandMatrix LB(n, lower);
         SymmetricBandMatrix SB(n, lower);
    -
    - -

    - The integers upper and lower are the number of non-zero - diagonals above and below the diagonal (excluding the diagonal) - respectively.  The UpperBandMatrix and LowerBandMatrix are upper and - lower triangular band matrices. So an UpperBandMatrix is essentially a - BandMatrix with lower = 0 and a LowerBandMatrix is a BandMatrix - with upper = 0. -

    -

    - The RowVector and ColumnVector types take just one argument in their - constructors: -

    -
    -    RowVector RV(n);
    +
    + +

    The integers upper and lower are the number of non-zero +diagonals above and below the diagonal (excluding the diagonal) +respectively.  The UpperBandMatrix and LowerBandMatrix are upper and lower +triangular band matrices. So an UpperBandMatrix is essentially a BandMatrix with +lower = 0 and a LowerBandMatrix is a BandMatrix with upper = 0.

    +

    The RowVector and ColumnVector types take just one argument in their +constructors:

    +
        RowVector RV(n);
         ColumnVector CV(n);
    -
    - -

    - These constructors do not initialise the elements of the - matrices. - - To set all the elements to zero use, for example, -

    -
    -    Matrix A(m, n); A = 0.0;
    -
    - -

    - The IdentityMatrix takes one argument in its constructor specifying its - dimension. -

    -
        IdentityMatrix I(n);
    -

    - The value of the diagonal elements is set to 1 by default, but you - can change this value as with other matrix types. -

    - -

    - You can also construct vectors and matrices without specifying the - dimension. For example -

    -
    -    Matrix A;
    -
    - -

    - In this case the dimension must be set by an - assignment statement or a - resize statement. -

    -

    - You can also use a constructor to set a matrix equal to another matrix or - matrix expression. -

    -
    -    Matrix A = UT;
    +
    + +

    These constructors do not initialise the elements of the matrices. + +To set all the elements to zero use, for example,

    +
        Matrix A(m, n); A = 0.0;
    +
    + +

    The IdentityMatrix takes one argument in its constructor specifying its +dimension.

    +
        IdentityMatrix I(n);
    +

    The value of the diagonal elements is set to 1 by default, but you can +change this value as with other matrix types.

    + +

    You can also construct vectors and matrices without specifying the +dimension. For example

    +
        Matrix A;
    +
    + +

    In this case the dimension must be set by an assignment +statement or a resize statement.

    +

    You can also use a constructor to set a matrix equal to another matrix or +matrix expression.

    +
        Matrix A = UT;
         Matrix A = UT * LT;
    -
    - -

    - Only conversions that don't lose information are supported - eg you cannot - convert an upper triangular matrix into a diagonal matrix using =. -

    -

    3.2 Accessing elements

    -

    - next - skip - - up - start -

    -

    - Elements are accessed by expressions of the form A(i,j) where - i and j run from 1 to the appropriate dimension. Access - elements of vectors with just one argument. Diagonal matrices can accept - one or two subscripts. -

    -

    - This is different from the earliest version of the package in which the - subscripts ran from 0 to one less than the appropriate dimension. Use - A.element(i,j) if you want this earlier convention. -

    -

    - A(i,j) and A.element(i,j) can appear on either side of - an = sign. -

    -

    - If you activate the #define SETUP_C_SUBSCRIPTS in - include.h you can also access elements using the traditional C - style notation. That is A[i][j] for matrices (except diagonal) - and V[i] for vectors and diagonal matrices. The subscripts start - at zero (i.e. like element) and there is no range checking. Because - of the possibility of confusing V(i) and V[i], I suggest - you do not activate this option unless you really want to use it. -

    -

    - Symmetric matrices are stored as lower triangular matrices. It is - important to remember this if you are using the A[i][j] method of - accessing elements. Make sure the first subscript is greater than or equal - to the second subscript. However, if you are using the - A(i,j) method the program will swap i and j if - necessary; so it doesn't matter if you think of the storage as being in - the upper triangle (but it does matter in some other situations - such as when entering data). -

    -

    The IdentityMatrix type does not support element access.

    -

    - For interfacing with traditional C functions that involve one and two - dimensional arrays see accessing C functions. -

    -

    3.3 Assignment and copying

    -

    - next - skip - - up - start -

    -

    - The operator = is used for copying matrices, converting matrices, - or evaluating expressions. For example -

    -
    -    A = B;  A = L;  A = L * U;
    -
    - -

    - Only conversions that don't lose information are supported. The dimensions - of the matrix on the left hand side are adjusted to those of the matrix or - expression on the right hand side. Elements on the right hand side which - are not present on the left hand side are set to zero. -

    -

    - The operator << can be used in place of = where it - is permissible for information to be lost. -

    -

    For example

    -
    -    SymmetricMatrix S; Matrix A;
    +
    + +

    Only conversions that don't lose information are supported - eg you cannot +convert an upper triangular matrix into a diagonal matrix using =.

    +

    3.2 Accessing elements +

    +

    next - skip - +up - start

    +

    Elements are accessed by expressions of the form A(i,j) where +i and j run from 1 to the appropriate dimension. Access elements +of vectors with just one argument. Diagonal matrices can accept one or two +subscripts.

    +

    This is different from the earliest version of the package in which the +subscripts ran from 0 to one less than the appropriate dimension. Use +A.element(i,j) if you want this earlier convention.

    +

    A(i,j) and A.element(i,j) can appear on either side of an += sign.

    +

    If you activate the #define SETUP_C_SUBSCRIPTS in +include.h you can also access elements using the traditional C style +notation. That is A[i][j] for matrices (except diagonal) and +V[i] for vectors and diagonal matrices. The subscripts start at zero +(i.e. like element) and there is no range checking. Because of the +possibility of confusing V(i) and V[i], I suggest you do +not activate this option unless you really want to use it.

    +

    Symmetric matrices are stored as lower triangular matrices. It is important +to remember this if you are using the A[i][j] method of accessing +elements. Make sure the first subscript is greater than or equal to the second +subscript. However, if you are using the A(i,j) method the program +will swap i and j if necessary; so it doesn't matter if you +think of the storage as being in the upper triangle (but it does matter +in some other situations such as when entering data).

    +

    The IdentityMatrix type does not support element access.

    +

    For interfacing with traditional C functions that involve one and two +dimensional arrays see accessing C functions.

    +

    3.3 Assignment and copying

    +

    next - skip - +up - start

    +

    The operator = is used for copying matrices, converting matrices, +or evaluating expressions. For example

    +
        A = B;  A = L;  A = L * U;
    +
    + +

    Only conversions that don't lose information are supported. The dimensions +of the matrix on the left hand side are adjusted to those of the matrix or +expression on the right hand side. Elements on the right hand side which are +not present on the left hand side are set to zero.

    +

    The operator << can be used in place of = where it +is permissible for information to be lost.

    +

    For example

    +
        SymmetricMatrix S; Matrix A;
         ......
         S << A.t() * A;
    -
    - -

    is acceptable whereas

    -
    -    S = A.t() * A;                            // error
    -
    - -

    - will cause a runtime error since the package does not (yet?) recognise - A.t()*A as symmetric. -

    -

    - Note that you can not use << with constructors. For - example -

    -
    -    SymmetricMatrix S << A.t() * A;           // error
    -
    - -

    does not work.

    -

    - Also note that << cannot be used to load values from a full - matrix into a band matrix, since it will be unable to determine the - bandwidth of the band matrix. -

    -

    A third copy routine is used in a similar role to =. Use

    -
    -    A.inject(D);
    -
    - -

    - to copy the elements of D to the corresponding elements of - A but leave the elements of A unchanged if there is no - corresponding element of D (the = operator would set - them to 0). This is useful, for example, for setting the diagonal elements - of a matrix without disturbing the rest of the matrix. Unlike - = and <<, inject does not reset the dimensions of - A, which must match those of D. Inject does - not test for no loss of information. The name Inject can be - used instead on inject. -

    -

    - You cannot replace D by a matrix expression. The effect of - inject(D) depends on the type of D. If D is an - expression it might not be obvious to the user what type it would have. So - I thought it best to disallow expressions. -

    -

    - Inject can be used for loading values from a regular matrix into a band - matrix. (Don't forget to zero any elements of the left hand side that will - not be set by the loading operation). -

    -

    - Both << and inject can be used with submatrix expressions - on the left hand side. See the section on - submatrices. -

    -

    To set the elements of a matrix to a scalar use operator =

    -
    -    Real r; int m,n;
    +
    + +

    is acceptable whereas

    +
        S = A.t() * A;                            // error
    +
    + +

    will cause a runtime error since the package does not (yet?) recognise +A.t()*A as symmetric.

    +

    Note that you can not use << with constructors. For +example

    +
        SymmetricMatrix S << A.t() * A;           // error
    +
    + +

    does not work.

    +

    Also note that << cannot be used to load values from a full +matrix into a band matrix, since it will be unable to determine the bandwidth +of the band matrix.

    +

    A third copy routine is used in a similar role to =. Use

    +
        A.inject(D);
    +
    + +

    to copy the elements of D to the corresponding elements of +A but leave the elements of A unchanged if there is no +corresponding element of D (the = operator would set them to +0). This is useful, for example, for setting the diagonal elements of a matrix +without disturbing the rest of the matrix. Unlike = and +<<, inject does not reset the dimensions of A, which +must match those of D. Inject does not test for no loss of +information. The name Inject can be used instead on inject.

    +

    You cannot replace D by a matrix expression. The effect of inject(D) depends on the type of D. If D is an +expression it might not be obvious to the user what type it would have. So I +thought it best to disallow expressions.

    +

    Inject can be used for loading values from a regular matrix into a band +matrix. (Don't forget to zero any elements of the left hand side that will not +be set by the loading operation).

    +

    Both << and inject can be used with submatrix expressions on +the left hand side. See the section on submatrices.

    +

    To set the elements of a matrix to a scalar use operator =

    +
        Real r; int m,n;
         ......
    -    Matrix A(m,n); A = r;
    - - To swap the values in two matrices A and B use one of the - following expressions -
       A.swap(B);
    -
       swap(A,B);
    - The matrices A and B must be of the same type. This can be - any of the matrix types listed in the - section on constructors, - CroutMatrix, BandLUMatrix or - GenericMatrix. Swap works by switching pointers and - does not do any actual copying of the main data arrays. -

    Notes:

    - -
      -
    • - When you do a matrix assignment to another matrix or matrix expression - with either = or << the original data array - associated with the matrix being assigned to is destroyed even if there - is no change in length. See the section on storage. - This means, in particular, that pointers to matrix elements - e.g. - Real* a; a = &(A(1,1)); become invalid. If you want avoid - this you can use Inject rather than =. But remember - that you may need to zero the matrix first.
      -
    • -
    - -

    3.4 Entering values

    -

    - next - skip - - up - start -

    -

    You can load the elements of a matrix from an array:

    -
    -    Matrix A(3,2);
    +    Matrix A(m,n); A = r;
    + + +To swap the values in two matrices A and B use one of the +following expressions
       A.swap(B);
    +
       swap(A,B);
    +The matrices A and B must be of the same type. This can be any +of the matrix types listed in the section on constructors, +CroutMatrix, BandLUMatrix or +GenericMatrix. Swap works by switching pointers and does not do any actual copying +of the main data arrays.

    Notes:

    + +
      +
    • When you do a matrix assignment to another matrix or matrix expression with +either = or << the original data array associated with the matrix + being assigned to is destroyed +even if there is no change in length. See the section on storage. +This means, in particular, that pointers to matrix elements - e.g. +Real* a; a = &(A(1,1)); become invalid. If you want avoid this you + can use +Inject rather than =. But remember that you may need to zero + the matrix first.
      +
    • +
    + +

    3.4 Entering values

    +

    next - skip - +up - start

    +

    You can load the elements of a matrix from an array:

    +
        Matrix A(3,2);
         Real a[] = { 11,12,21,22,31,33 };
    -    A << a;
    -

    or

    -
    -    Matrix A(3,2);
    +    A << a;
    +

    or

    +
        Matrix A(3,2);
         int a[] = { 11,12,21,22,31,33 };
         A << a;
    -

    - This construction does not check that the numbers of elements match - correctly. This version of << can be used with submatrices - on the left hand side. It is not defined for band matrices. -

    -

    Note that you enter only the values stored in a matrix. For example

    -
    -    SymmetricMatrix A(2);
    +

    This construction does not check that the numbers of elements match +correctly. This version of << can be used with submatrices on +the left hand side. It is not defined for band matrices.

    +

    Note that you enter only the values stored in a matrix. For example

    +
        SymmetricMatrix A(2);
         Real a[] = { 11,12,22 };
         A << a;
    -

    - Alternatively you can enter short lists using a sequence of numbers - separated by << . -

    -
    -    Matrix A(3,2);
    +

    Alternatively you can enter short lists using a sequence of numbers +separated by << .

    +
        Matrix A(3,2);
         A << 11 << 12
           << 21 << 22
           << 31 << 32;
    -
    - -

    - This does check for the correct total number of entries, although the - message for there being insufficient numbers in the list may be delayed - until the end of the block or the next use of this construction. This does - not work for band matrices or for long lists. It does work for - submatrices if the submatrix is a single complete row. For example -

    -
    -    Matrix A(3,2);
    +
    + +

    This does check for the correct total number of entries, although the +message for there being insufficient numbers in the list may be delayed until +the end of the block or the next use of this construction. This does not +work for band matrices or for long lists. It does work for submatrices if the +submatrix is a single complete row. For example

    +
        Matrix A(3,2);
         A.row(1) << 11 << 12;
         A.row(2) << 21 << 22;
         A.row(3) << 31 << 32;
    -
    +
    -

    Load only values that are actually stored in the matrix. For example

    -
    -    SymmetricMatrix S(2);
    +

    Load only values that are actually stored in the matrix. For example

    +
        SymmetricMatrix S(2);
         S.row(1) << 11;
         S.row(2) << 21 << 22;
    -
    - -

    - Try to restrict this way of loading data to numbers. You can include - expressions, but these must not call a function which includes the same - construction. -

    - -

    - Remember that matrices are stored by rows and that symmetric matrices are - stored as lower triangular matrices when using these methods to - enter data. -

    -

    3.5 Unary operators

    -

    - next - skip - - up - start -

    -

    The package supports unary operations

    -
    -    X = -A;           // change sign of elements
    +
    + +

    Try to restrict this way of loading data to numbers. You can include +expressions, but these must not call a function which includes the same +construction.

    + +

    Remember that matrices are stored by rows and that symmetric matrices are +stored as lower triangular matrices when using these methods to enter +data.

    +

    3.5 Unary operators

    +

    next - skip - +up - start

    +

    The package supports unary operations

    +
        X = -A;           // change sign of elements
         X = A.t();        // transpose
         X = A.i();        // inverse (of square matrix A)
         X = A.reverse();  // reverse order of elements of vector
    @@ -2164,21 +1647,17 @@ 

    3.5 Unary operators

    ColumnVector X = A.sum_square_rows(); // sum of squares of // elements of each row RowVector X = A.sum_square_columns(); // sum of squares of - // elements of each column
    - -

    - See the function summary list for the older - depreciated function name. -

    - -

    3.6 Binary operators

    -

    - next - skip - - up - start -

    -

    The package supports binary operations

    -
    -    X = A + B;       // matrix addition
    +                                           // elements of each column
    + +

    See the function summary list for the older +depreciated function name.

    + + +

    3.6 Binary operators

    +

    next - skip - +up - start

    +

    The package supports binary operations

    +
        X = A + B;       // matrix addition
         X = A - B;       // matrix subtraction
         X = A * B;       // matrix multiplication
         X = A.i() * B;   // equation solve (square matrix A)
    @@ -2198,165 +1677,103 @@ 

    3.6 Binary operators

    A &= B; // A = A & B; A.SP_eq(B); // A = SP(A, B); <, >, <=, >= // included for compatibility with STL - see notes -
    - -

    Notes:

    -
      -
    • - If you are doing repeated multiplication. For example A*B*C, - use brackets to force the order of evaluation to minimise the number of - operations. If C is a column vector and A is not a - vector, then it will usually reduce the number of operations to use - A*(B*C). -
    • -
    • - In the equation solve example case the inverse is not explicitly - calculated. An LU decomposition of A is performed and this is - applied to B. This is more efficient than calculating the - inverse and then multiplying. See also - multiple matrix solving. -
    • -
    • - The package does not (yet?) recognise B*A.i() as an equation - solve and the inverse of A would be calculated. It is probably - better to use (A.t().i()*B.t()).t(). -
    • -
    • - Horizontal or vertical concatenation returns a result of type Matrix, - RowVector or ColumnVector. -
    • -
    • - If A is m x p, B is m x - q, then A | B is m x (p+q) with - the k-th row being the elements of the k-th row of - A followed by the elements of the k-th row of - B. -
    • -
    • - If A is p x n, B is q x - n, then A & B is (p+q) x - n with the k-th column being the elements of the - k-th column of A followed by the elements of the - k-th column of B. -
    • -
    • - For complicated concatenations of matrices, consider instead using - submatrices. -
    • -
    • - See the section on submatrices on using a - submatrix on the RHS of an expression. -
    • -
    • - crossproduct - assumes A and B are both RowVectors of length 3 or both - ColumnVectors of length 3. Result is a Matrix of same dimension as A or - B (will automatically convert to RowVector if A and B are RowVectors and - ColumnVector if they are ColumnVectors). -
    • -
    • - crossproduct_rows - assumes A and B are of type Matrix with the same - number of rows and 3 columns. Does a cross product on corresponding - pairs of rows. -
    • -
    • - crossproduct_columns - assumes A and B are of type Matrix with  the - same number of columns and 3 rows. Does a cross product on corresponding - pairs of columns. -
    • -
    • - Two matrices are equal if their difference is zero. They may be of - different types. For the CroutMatrix or BandLUMatrix they must be of the - same type and have all their elements equal. This is not a very useful - operator and is included for compatibility with some container - templates. -
    • -
    • - The inequality operators are included for compatibility with some - versions of the standard template library. If - actually called, they will throw an exception. So don't try to sort a - list of matrices. -
    • -
    • - A row vector multiplied by a column vector yields a 1x1 matrix, - not a Real. To get a Real result use either - as_scalar or dotproduct. -
    • -
    • - The result from Kronecker product, KP(A, B), possesses an - attribute such as upper triangular, lower triangular, band, symmetric, - diagonal if both of the matrices A and B have the - attribute. If A is band and B is a square type (eg - SquareMatrix, Diagonal, LowerTriangularMatrix etc) then the result is - band. -
    • -
    • - Elementwise product is also known as the Schur product or the Hadamard - product. -
    • -
    • - See the function summary list for the older - depreciated function names. -
    • -
    -

    - Remember that the product of symmetric matrices is not necessarily - symmetric so the following code will not run: -

    -
    -   SymmetricMatrix A, B;
    +
    + +

    Notes:

    +
      +
    • If you are doing repeated multiplication. For example A*B*C, use +brackets to force the order of evaluation to minimise the number of operations. +If C is a column vector and A is not a vector, then it will +usually reduce the number of operations to use A*(B*C).
    • +
    • In the equation solve example case the inverse is not explicitly +calculated. An LU decomposition of A is performed and this is applied +to B. This is more efficient than calculating the inverse and then +multiplying. See also multiple matrix solving.
    • +
    • The package does not (yet?) recognise B*A.i() as an equation solve +and the inverse of A would be calculated. It is probably better to use +(A.t().i()*B.t()).t().
    • +
    • Horizontal or vertical concatenation returns a result of type Matrix, +RowVector or ColumnVector.
    • +
    • If A is m x p, B is m x q, +then A | B is m x (p+q) with the k-th row +being the elements of the k-th row of A followed by the +elements of the k-th row of B.
    • +
    • If A is p x n, B is q x n, +then A & B is (p+q) x n with the k-th +column being the elements of the k-th column of A followed by +the elements of the k-th column of B.
    • +
    • For complicated concatenations of matrices, consider instead using +submatrices.
    • +
    • See the section on submatrices on using a submatrix +on the RHS of an expression.
    • +
    • crossproduct - assumes A and B are both RowVectors of length 3 or both +ColumnVectors of length 3. Result is a Matrix of same dimension as A or B (will +automatically convert to RowVector if A and B are RowVectors and ColumnVector if +they are ColumnVectors).
    • +
    • crossproduct_rows - assumes A and B are of type Matrix with the same number +of rows and 3 columns. Does a cross product on corresponding pairs of rows.
    • +
    • crossproduct_columns - assumes A and B are of type Matrix with  the same +number of columns and 3 rows. Does a cross product on corresponding pairs of +columns.
    • +
    • Two matrices are equal if their difference is zero. They may be of +different types. For the CroutMatrix or BandLUMatrix they must be of the same +type and have all their elements equal. This is not a very useful operator and +is included for compatibility with some container templates.
    • +
    • The inequality operators are included for compatibility with some versions +of the +standard template library. If actually called, they will +throw an exception. So don't try to sort a list of matrices.
    • +
    • A row vector multiplied by a column vector yields a 1x1 matrix, not +a Real. To get a Real result use either as_scalar or +dotproduct.
    • +
    • The result from Kronecker product, KP(A, B), possesses an attribute such as +upper triangular, lower triangular, band, symmetric, diagonal if both of the +matrices A and B have the attribute. If A is band and B is a square type +(eg SquareMatrix, Diagonal, LowerTriangularMatrix etc) then +the result is band.
    • +
    • Elementwise product is also known as the Schur product or the Hadamard +product.
    • +
    • See the function summary list for the older +depreciated function names.
    • +
    +

    Remember that the product of symmetric matrices is not +necessarily symmetric so the following code will not run:

    +
       SymmetricMatrix A, B;
        .... put values in A, B ....
    -   SymmetricMatrix C = A * B;   // run time error
    - -

    Use instead

    -
       Matrix C = A * B;
    - -

    - or, if you know the product will be symmetric, use -

    -
    -   SymmetricMatrix C; C << A * B;
    -
    - -

    3.7 Matrix and scalar

    -

    - next - skip - - up - start -

    -

    - The following expressions multiply the elements of a matrix A by - a scalar f: A * f or f * A . Likewise one can - divide the elements of a matrix A by a scalar f: - A / f . -

    -

    - The expressions A + f and A - f add or subtract a - rectangular matrix of the same dimension as A with elements equal - to f to or from the matrix A . -

    -

    - The expression f + A is an alternative to A + f. The - expression f - A subtracts matrix A from a rectangular - matrix of the same dimension as A and with elements equal to - f . -

    -

    - The expression A += f replaces A by A + f. - Operators -=, *=, /= are similarly defined. -

    -

    - 3.8 Scalar functions of a matrix - size & shape -

    -

    - next - skip - - up - start -

    -

    - This page describes functions returning the values associated with the - size and shape of matrices. The following pages describe other scalar - matrix functions. -

    -
    -    int m = A.nrows();                     // number of rows
    +   SymmetricMatrix C = A * B;   // run time error
    + +

    Use instead

    +
       Matrix C = A * B;
    + +

    or, if you know the product will be symmetric, +use

    +
       SymmetricMatrix C; C << A * B;
    +
    + +

    3.7 Matrix and scalar

    +

    next - skip - +up - start

    +

    The following expressions multiply the elements of a matrix A by a +scalar f: A * f or f * A . Likewise one can divide +the elements of a matrix A by a scalar f: A / f . +

    +

    The expressions A + f and A - f add or subtract a +rectangular matrix of the same dimension as A with elements equal to +f to or from the matrix A .

    +

    The expression f + A is an alternative to A + f. The +expression f - A subtracts matrix A from a rectangular matrix +of the same dimension as A and with elements equal to f . +

    +

    The expression A += f replaces A by A + f. +Operators -=, *=, /= are similarly defined.

    +

    3.8 Scalar functions of a +matrix - size & shape

    +

    next - skip - +up - start

    +

    This page describes functions returning the values associated with the size +and shape of matrices. The following pages describe other scalar matrix +functions.

    +
        int m = A.nrows();                     // number of rows
         int n = A.ncols();                     // number of columns
         MatrixType mt = A.type();              // type of matrix
         Real* s = A.data();                    // pointer to array of elements
    @@ -2365,37 +1782,24 @@ 

    const Real* s = A.const_data(); // pointer to array of elements int l = A.size(); // length of array of elements MatrixBandWidth mbw = A.bandwidth(); // upper and lower bandwidths -

    - -

    - MatrixType mt = A.type() returns the type of a matrix. Use - mt.value() to get a string (UT, LT, Rect, Sym, Diag, Band, UB, - LB, Crout, BndLU) showing the type (Vector types are returned as Rect). -

    -

    - MatrixBandWidth has member functions upper() and - lower() for finding the upper and lower bandwidths (number of - diagonals above and below the diagonal, both zero for a diagonal matrix). - For non-band matrices -1 is returned for both these values. -

    -

    - See the function summary list for the older - depreciated function names. -

    -

    - 3.9 Scalar functions of a matrix - maximum & - minimum -

    -

    - next - skip - - up - start -

    -

    - This page describes functions for finding the maximum and minimum elements - of a matrix. -

    -
    -    int i, j;
    +
    + +

    MatrixType mt = A.type() returns the type of a matrix. Use +mt.value() to get a string (UT, LT, Rect, Sym, Diag, Band, UB, LB, +Crout, BndLU) showing the type (Vector types are returned as Rect).

    +

    MatrixBandWidth has member functions upper() and +lower() for finding the upper and lower bandwidths (number of diagonals +above and below the diagonal, both zero for a diagonal matrix). For non-band +matrices -1 is returned for both these values.

    +

    See the function summary list for the older +depreciated function names.

    +

    3.9 Scalar functions of a +matrix - maximum & minimum

    +

    next - skip - +up - start

    +

    This page describes functions for finding the maximum and minimum elements +of a matrix.

    +
        int i, j;
         Real mv = A.maximum_absolute_value();    // maximum of absolute values
         Real mv = A.minimum_absolute_value();    // minimum of absolute values
         Real mv = A.maximum();                   // maximum value
    @@ -2408,31 +1812,23 @@ 

    Real mv = A.minimum_absolute_value2(i,j);// minimum of absolute values Real mv = A.maximum2(i,j); // maximum value Real mv = A.minimum2(i,j); // minimum value -

    - -

    - All these functions throw an exception if A has no rows or no - columns. -

    -

    - The versions A.maximum_absolute_value1(i), etc return the - location of the extreme element in a RowVector, ColumnVector or - DiagonalMatrix. The versions A.maximum_absolute_value2(i,j), etc - return the row and column numbers of the extreme element. If the extreme - value occurs more than once the location of the last one is given. -

    -

    - The versions maximum_absolute_value(A), minimum_absolute_value(A), - maximum(A), minimum(A) can be used in place of A.maximum_absolute_value(), - A.minimum_absolute_value(), A.maximum(), A.minimum(). -

    -

    3.10 Scalar functions of a matrix - numerical

    -

    - next - skip - - up - start -

    -
    -    Real r = A.as_scalar();                // value of 1x1 matrix
    +
    + +

    All these functions throw an exception if A has no rows or no +columns.

    +

    The versions A.maximum_absolute_value1(i), etc return the location of +the extreme element in a RowVector, ColumnVector or DiagonalMatrix. The +versions A.maximum_absolute_value2(i,j), etc return the row and column +numbers of the extreme element. If the extreme value occurs more than once the +location of the last one is given.

    +

    The versions maximum_absolute_value(A), minimum_absolute_value(A), maximum(A), +minimum(A) can be used in place of A.maximum_absolute_value(), +A.minimum_absolute_value(), A.maximum(), A.minimum().

    +

    3.10 Scalar functions of a +matrix - numerical

    +

    next - skip - +up - start

    +
        Real r = A.as_scalar();                // value of 1x1 matrix
         Real ssq = A.sum_square();             // sum of squares of elements
         Real sav = A.sum_absolute_value();     // sum of absolute values
         Real s = A.sum();                      // sum of values
    @@ -2450,111 +1846,74 @@ 

    3.10 Scalar functions of a matrix - numerical

    BandLUMatrix Real s = dotproduct(A, B); // dot product of A and B // interpreted as vectors -
    +
    + +

    See the function summary list for the older +depreciated function names.

    -

    - See the function summary list for the older - depreciated function names. -

    - -

    - A.log_determinant() returns a value of type LogAndSign. If - ld is of type LogAndSign use -

    -
    -    ld.value()     to get the value of the determinant
    +

    A.log_determinant() returns a value of type LogAndSign. If ld is of +type LogAndSign use

    +
        ld.value()     to get the value of the determinant
         ld.sign()      to get the sign of the determinant (values 1, 0, -1)
         ld.log_value() to get the log of the absolute value.
    -
    - -

    - Note that the direct use of the function determinant() will often - cause a floating point overflow exception. -

    -

    - A.is_zero() returns Boolean value true if the matrix - A has all elements equal to 0.0. -

    -

    - is_singular() is defined only for CroutMatrix and BandLUMatrix. - It returns true if one of the diagonal elements of the LU - decomposition is exactly zero. -

    -

    - dotproduct(const Matrix& A, const Matrix& B) converts - both of the arguments to rectangular matrices, checks that they have the - same number of elements and then calculates the first element of - A * first element of B + second element of - A * second element of B + ... ignoring the row/column - structure of A and B. It is primarily intended for the - situation where A and B are row or column vectors. -

    -

    - The versions sum(A), sum_square(A), sum_absolute_value(A), trace(A), - log_determinant(A), determinant(A), norm1(A), norm_infinity(A), - norm_Frobenius(A) can be used in place of A.sum(), A.sum_square(), - A.sum_absolute_value(), A.trace(), A.log_determinant(), A.determinant(A), - A.norm1(), A.norm_infinity(), A.norm_Frobenius(). -

    -

    3.11 Submatrices

    -

    - next - skip - - up - start -

    -
    -    A.submatrix(fr,lr,fc,lc)
    -
    - -

    - This selects a submatrix from A. The arguments - fr,lr,fc,lc are the first row, last - row, first column, last column of the submatrix with the numbering - beginning at 1. -

    -

    - I allow lr = fr-1 or lc = fc-1 or to indicate that a - matrix of zero rows or columns is to be returned. -

    -

    - A submatrix command may be used in any matrix expression or on the left - hand side of =, << or inject. - inject does not check no information loss. You can also use - the construction -

    -
    -    Real c; .... A.submatrix(fr,lr,fc,lc) = c;
    -
    - -

    to set a submatrix equal to a constant.

    -

    The following are variants of submatrix:

    -
    -    A.sym_submatrix(f,l)            //   assumes fr=fc and lr=lc
    +
    + +

    Note that the direct use of the function determinant() will often +cause a floating point overflow exception.

    +

    A.is_zero() returns Boolean value true if the matrix +A has all elements equal to 0.0.

    +

    is_singular() is defined only for CroutMatrix and BandLUMatrix. It +returns true if one of the diagonal elements of the LU decomposition +is exactly zero.

    +

    dotproduct(const Matrix& A, const Matrix& B) converts both +of the arguments to rectangular matrices, checks that they have the same number +of elements and then calculates the first element of A * first element +of B + second element of A * second element of B + +... ignoring the row/column structure of A and B. It is +primarily intended for the situation where A and B are row or +column vectors.

    +

    The versions sum(A), sum_square(A), sum_absolute_value(A), trace(A), +log_determinant(A), determinant(A), norm1(A), norm_infinity(A), norm_Frobenius(A) +can be used in place of A.sum(), A.sum_square(), A.sum_absolute_value(), +A.trace(), A.log_determinant(), A.determinant(A), A.norm1(), A.norm_infinity(), A.norm_Frobenius(). +

    +

    3.11 Submatrices

    +

    next - skip - +up - start

    +
        A.submatrix(fr,lr,fc,lc)
    +
    + +

    This selects a submatrix from A. The arguments +fr,lr,fc,lc are the first row, last row, +first column, last column of the submatrix with the numbering beginning at 1. +

    +

    I allow lr = fr-1 or lc = fc-1 or to indicate that a +matrix of zero rows or columns is to be returned.

    +

    A submatrix command may be used in any matrix expression or on the left hand +side of =, << or inject. inject does not check +no information loss. You can also use the construction

    +
        Real c; .... A.submatrix(fr,lr,fc,lc) = c;
    +
    + +

    to set a submatrix equal to a constant.

    +

    The following are variants of submatrix:

    +
        A.sym_submatrix(f,l)            //   assumes fr=fc and lr=lc
         A.rows(f,l)                     //   select rows
         A.row(f)                        //   select single row
         A.columns(f,l)                  //   select columns
         A.column(f)                     //   select single column
    -
    - -

    - See the function summary list for the older - depreciated function names. -

    - -

    - In each case f and l mean the first and last row or - column to be selected (starting at 1). -

    -

    - I allow l = f-1 to indicate that a matrix of zero rows or columns - is to be returned. -

    -

    - If submatrix or its variant occurs on the right hand side of an - = or << or within an expression think of its type - as follows -

    -
    -    A.submatrix(fr,lr,fc,lc)           If A is RowVector or
    +
    + +

    See the function summary list for the older +depreciated function names.

    + +

    In each case f and l mean the first and last row or column +to be selected (starting at 1).

    +

    I allow l = f-1 to indicate that a matrix of zero rows or columns +is to be returned.

    +

    If submatrix or its variant occurs on the right hand side of an = +or << or within an expression think of its type as follows

    +
        A.submatrix(fr,lr,fc,lc)           If A is RowVector or
                                            ColumnVector then same type
                                            otherwise type Matrix
         A.sym_submatrix(f,l)               Same type as A
    @@ -2562,64 +1921,44 @@ 

    3.11 Submatrices

    A.row(f) Type RowVector A.columns(f,l) Type Matrix A.column(f) Type ColumnVector -
    - -

    - If submatrix or its variant appears on the left hand side of = or - << , think of its type being Matrix. Thus - L.row(1) where L is LowerTriangularMatrix expects - L.ncols() elements even though it will use only one of them. If - you are using = the program will check for no loss of data. -

    - -

    - A submatrix can appear on the left-hand side of += or - -= with a matrix expression on the right-hand side. It can also - appear on the left-hand side of +=, -=, *= or - /= with a Real on the right-hand side. In each case there must be - no loss of information. The SP_eq function is also - defined for a submatrix. -

    -

    - The row version can appear on the left hand side of - << for loading literal data into a - row. Load only the number of elements that are actually going to be stored - in memory. -

    -

    - Do not use the += and -= operations with a submatrix - of a SymmetricMatrix or BandSymmetricMatrix on the LHS. -

    -

    - You can't pass a submatrix (or any of its variants) as a reference - non-constant matrix in a function argument. For example, the following - will not work: -

    -
    -   void YourFunction(Matrix& A);
    +
    + +

    If submatrix or its variant appears on the left hand side of = or +<< , think of its type being Matrix. Thus L.row(1) +where L is LowerTriangularMatrix expects L.ncols() elements +even though it will use only one of them. If you are using = the +program will check for no loss of data.

    + +

    A submatrix can appear on the left-hand side of += or -= +with a matrix expression on the right-hand side. It can also appear on the +left-hand side of +=, -=, *= or /= with a +Real on the right-hand side. In each case there must be no loss of information. +The SP_eq function is also defined for a submatrix. +

    +

    The row version can appear on the left hand side of +<< for loading literal data into a row. +Load only the number of elements that are actually going to be stored in +memory.

    +

    Do not use the += and -= operations with a submatrix of a +SymmetricMatrix or BandSymmetricMatrix on the LHS.

    +

    You can't pass a submatrix (or any of its variants) as a reference +non-constant matrix in a function argument. For example, the following will not +work:

    +
       void YourFunction(Matrix& A);
        ...
        Matrix B(10,10);
        YourFunction(B.submatrix(1,5,1,5))    // won't compile
    -

    - If you are are using the submatrix facility to build a matrix from a small - number of components, consider instead using the - concatenation operators. -

    -

    3.12 Change dimensions

    -

    - next - skip - - up - start -

    -

    - The following operations change the dimensions of a matrix. The values of - the elements are lost, for resize. resize_keep keeps - element values and zeros the elements in the matrix with the new size that - are not in the matrix with the old size. -

    -
    -    A.resize(nrows,ncols);        // for type Matrix or nricMatrix
    +

    If you are are using the submatrix facility to build a matrix from a small +number of components, consider instead using the concatenation operators.

    +

    3.12 Change dimensions

    +

    next - skip - +up - start

    +

    The following operations change the dimensions of a matrix. The values of the +elements are lost, for resize. resize_keep keeps element +values and zeros the elements in the matrix with the new size that are not in +the matrix with the old size.

    +
        A.resize(nrows,ncols);        // for type Matrix or nricMatrix
         A.resize(n);                  // for other types, except Band
         A.resize(n,lower,upper);      // for BandMatrix
         A.resize(n,lower);            // for LowerBandMatrix
    @@ -2629,654 +1968,450 @@ 

    3.12 Change dimensions

    A.cleanup(); // resize to zero dimensions A.resize_keep(nrows,ncols); // for type Matrix or nricMatrix, keep values A.resize_keep(n); // for other types, except Band, keep values -
    - -

    - Use A.cleanup() to set the dimensions of A to zero and - release all the heap memory. -

    -

    - A.resize(B) sets the dimensions of A to those of a - matrix B. This includes the band-width in the case of a band - matrix. It is an error for A to be a band matrix and - B not a band matrix (or diagonal matrix). -

    -

    - Remember that resize destroys values. If you want to resize, but - keep the values in the bit that is left use resize_keep. -

    -

    - See the function summary list for the older - depreciated function names. -

    - -

    3.13 Change type

    -

    - next - skip - - up - start -

    -

    - The following functions interpret the elements of a matrix (stored row by - row) to be a vector or matrix of a different type. Actual copying is - usually avoided where these occur as part of a more complicated - expression. -

    -
    -    A.as_row()
    +
    + +

    Use A.cleanup() to set the dimensions of A to zero and +release all the heap memory.

    +

    A.resize(B) sets the dimensions of A to those of a matrix +B. This includes the band-width in the case of a band matrix. It is an +error for A to be a band matrix and B not a band matrix (or +diagonal matrix).

    +

    Remember that resize destroys values. If you want to resize, but +keep the values in the bit that is left use resize_keep.

    +

    See the function summary list for the older +depreciated function names.

    + +

    3.13 Change type

    +

    next - skip - +up - start

    +

    The following functions interpret the elements of a matrix (stored row by +row) to be a vector or matrix of a different type. Actual copying is usually +avoided where these occur as part of a more complicated expression.

    +
        A.as_row()
         A.as_column()
         A.as_diagonal()
         A.as_matrix(nrows,ncols)
         A.as_scalar()
    -
    - -

    - The expression A.as_scalar() is used to convert a 1 x 1 matrix to - a scalar. -

    -

    - See the function summary list for the older - depreciated function names. -

    -

    3.14 Multiple matrix solve

    -

    - next - skip - - up - start -

    -

    - To solve the matrix equation Ay = b where A is a square - matrix of equation coefficients, y is a column vector of values - to be solved for, and b is a column vector, use the code -

    -
    -    int n = something
    +
    + +

    The expression A.as_scalar() is used to convert a 1 x 1 matrix to a +scalar.

    +

    See the function summary list for the older +depreciated function names.

    +

    3.14 Multiple matrix solve

    +

    next - skip - +up - start

    +

    To solve the matrix equation Ay = b where A is a square +matrix of equation coefficients, y is a column vector of values to be +solved for, and b is a column vector, use the code

    +
        int n = something
         Matrix A(n,n); ColumnVector b(n);
         ... put values in A and b
         ColumnVector y = A.i() * b;       // solves matrix equation
    -
    - -

    - The following notes are for the case where you want to solve more than one - matrix equation with different values of b but the same - A. Or where you want to solve a matrix equation and also find the - determinant of A. In these cases you probably want to avoid - repeating the LU decomposition of A for each solve or determinant - calculation. -

    -

    If A is a square or symmetric matrix use

    -
    -    ColumnVector p, q;
    +
    + +

    The following notes are for the case where you want to solve more than one +matrix equation with different values of b but the same A. Or +where you want to solve a matrix equation and also find the determinant of +A. In these cases you probably want to avoid repeating the LU +decomposition of A for each solve or determinant calculation.

    +

    If A is a square or symmetric matrix use

    +
        ColumnVector p, q;    
         ...
         CroutMatrix X = A;                // carries out LU decomposition
         ColumnVector Ap = X.i()*p; ColumnVector Aq = X.i()*q;
         LogAndSign ld = X.log_determinant();
    -
    +
    -

    rather than

    -
    -    ColumnVector p, q;
    +

    rather than

    +
        ColumnVector p, q;    
         ...
         ColumnVector Ap = A.i()*p; ColumnVector Aq = A.i()*q;
         LogAndSign ld = A.log_determinant();
    -
    - -

    since each operation will repeat the LU decomposition.

    -

    If A is a BandMatrix or a SymmetricBandMatrix begin with

    -
    -    BandLUMatrix X = A;               // carries out LU decomposition
    -
    - -

    - A CroutMatrix or BandLUMatrix can be copied and you can have a constructor - with no parameters (use = to give it values). They work with - release(), release_and_delete and - GenericMatrix and - ReturnMatrix. You can't do any other manipulation - apart from taking the inverse or solving with i(), or finding the - determinant or log determinant. See the - function summary list for accessing the internals - of a CroutMatrix or BandLUMatrix. -

    -

    You can alternatively use

    -
    -    LinearEquationSolver X = A;
    -
    - -

    - This will choose the most appropriate decomposition of A. That - is, the band form if A is banded; the Crout decomposition if - A is square or symmetric and no decomposition if A is - triangular or diagonal. It doesn't know about positive definite matrices - so won't use Cholesky. -

    -

    3.15 Memory management

    -

    - next - skip - - up - start -

    -

    - The package does not support delayed copy. Several strategies are required - to prevent unnecessary matrix copies. -

    -

    - Where a matrix is called as a function argument use a constant reference. - For example -

    -
    -    YourFunction(const Matrix& A)
    -
    - -

    rather than

    -
    -    YourFunction(Matrix A)
    -
    - -

    Skip the rest of this section on your first reading.

    -

    - A second place where it is desirable to avoid unnecessary copies is when a - function is returning a matrix. Matrices can be returned from a function - with the return command as you would expect. However these may incur one - and possibly two copyings of the matrix. To avoid this use the following - instructions. -

    -

    - Make your function of type ReturnMatrix . Then precede the return - statement with a release statement (or a - release_and_delete statement if the matrix was created with new). - For example -

    -
    -    ReturnMatrix MakeAMatrix()
    +
    + +

    since each operation will repeat the LU decomposition.

    +

    If A is a BandMatrix or a SymmetricBandMatrix begin with

    +
        BandLUMatrix X = A;               // carries out LU decomposition
    +
    + +

    A CroutMatrix or BandLUMatrix can be copied and you can have a constructor +with no parameters (use = to give it values). They work with +release(), release_and_delete and +GenericMatrix and ReturnMatrix. You +can't do any other manipulation apart from taking the inverse or solving with +i(), or finding the determinant or log determinant. See the function summary list +for accessing the internals of a CroutMatrix or BandLUMatrix.

    +

    You can alternatively use

    +
        LinearEquationSolver X = A;
    +
    + +

    This will choose the most appropriate decomposition of A. That is, +the band form if A is banded; the Crout decomposition if A is +square or symmetric and no decomposition if A is triangular or +diagonal. It doesn't know about positive definite matrices so won't use +Cholesky.

    +

    3.15 Memory management

    +

    next - skip - +up - start

    +

    The package does not support delayed copy. Several strategies are required +to prevent unnecessary matrix copies.

    +

    Where a matrix is called as a function argument use a constant reference. +For example

    +
        YourFunction(const Matrix& A)
    +
    + +

    rather than

    +
        YourFunction(Matrix A)
    +
    + +

    Skip the rest of this section on your first reading.

    +

    A second place where it is desirable to avoid unnecessary copies is when a +function is returning a matrix. Matrices can be returned from a function with +the return command as you would expect. However these may incur one and +possibly two copyings of the matrix. To avoid this use the following +instructions.

    +

    Make your function of type ReturnMatrix . Then precede the return statement +with a release statement (or a release_and_delete statement if the matrix was +created with new). For example

    +
        ReturnMatrix MakeAMatrix()
         {
            Matrix A;                // or any other matrix type
            ......
            A.release(); return A;
         }
    -
    +
    -

    or

    -
    -    ReturnMatrix MakeAMatrix()
    +

    or

    +
        ReturnMatrix MakeAMatrix()
         {
            Matrix* m = new Matrix;
            ......
            m->release_and_delete(); return *m;
         }
    -
    +
    -

    - If your compiler objects to this code, replace the return statements with -

    -
    -    return A.for_return();
    -
    +

    If your compiler objects to this code, replace the return statements with +

    +
        return A.for_return();
    +
    -

    or

    -
        return m->for_return();
    +

    or

    +
        return m->for_return();
    -
    -

    - Do not forget to make the function of type ReturnMatrix. -

    -
    -

    In particular, don't do

    -
        Matrix MakeAMatrix()
    +
    +

    Do not forget to make the function of type ReturnMatrix.

    +
    +

    In particular, don't do

    +
        Matrix MakeAMatrix()
         {
            Matrix A;                // or any other matrix type
            ......
            A.release(); return A;   // will compile but could give wrong answers.
         }
    -

    - since with some compilers A might retain its - released status after being returned. -

    -

    - You can also use .release() or - ->release_and_delete() to allow a matrix expression to recycle - space. Suppose you call -

    -
    -    A.release();
    -
    - -

    - just before A is used just once in an expression. Then the memory - used by A is either returned to the system or reused in the - expression. In either case, A's memory is destroyed. This - procedure can be used to improve efficiency and reduce the use of memory. -

    -

    - Use ->release_and_delete for matrices created by new if you - want to completely delete the matrix after it is accessed. -

    -

    - See the function summary list for the older - depreciated function names. -

    -

    3.16 Efficiency

    -

    - next - skip - - up - start -

    -

    - The package tends to be not very efficient for dealing with matrices with - short rows. This is because some administration is required for accessing - rows for a variety of types of matrices. To reduce the administration a - special multiply routine is used for rectangular matrices in place of the - generic one. Where operations can be done without reference to the - individual rows (such as adding matrices of the same type) appropriate - routines are used. -

    -

    - When you are using small matrices (say smaller than 10 x 10) you may find - it faster to use rectangular matrices rather than the triangular or - symmetric ones. -

    -

    3.17 Output

    -

    - next - skip - - up - start -

    -

    To print a matrix use an expression like

    -
    -   Matrix A, B C;
    +

    since with some compilers A might retain its released status +after being returned.

    +

    You can also use .release() or ->release_and_delete() to +allow a matrix expression to recycle space. Suppose you call

    +
        A.release();
    +
    + +

    just before A is used just once in an expression. Then the memory +used by A is either returned to the system or reused in the +expression. In either case, A's memory is destroyed. This procedure +can be used to improve efficiency and reduce the use of memory.

    +

    Use ->release_and_delete for matrices created by new if you want +to completely delete the matrix after it is accessed.

    +

    See the function summary list for the older +depreciated function names.

    +

    3.16 Efficiency

    +

    next - skip - +up - start

    +

    The package tends to be not very efficient for dealing with matrices with +short rows. This is because some administration is required for accessing rows +for a variety of types of matrices. To reduce the administration a special +multiply routine is used for rectangular matrices in place of the generic one. +Where operations can be done without reference to the individual rows (such as +adding matrices of the same type) appropriate routines are used.

    +

    When you are using small matrices (say smaller than 10 x 10) you may find it +faster to use rectangular matrices rather than the triangular or symmetric +ones.

    +

    3.17 Output

    +

    next - skip - +up - start

    +

    To print a matrix use an expression like

    +
       Matrix A, B C;
        ......
        cout << setw(10) << setprecision(5) << A << endl;
        cout << setw(10) << setprecision(5) << scientific << B << endl;
        cout << setw(10) << setprecision(5) << fixed << C << endl;
    -
    - -

    - This will work only with systems that support the standard input/output - routines including manipulators. The scientific and fixed manipulators - won't work with Visual C++, version 6. -

    -

    - You need to #include the files iostream.h, iomanip.h, newmatio.h in your - C++ source files that use this facility. The files iostream.h, iomanip.h - will be included automatically if you include the statement - #define WANT_STREAM at the beginning of your source file. So you - can begin your file with either -

    -
    -   #define WANT_STREAM
    +
    + +

    This will work only with systems that support the standard input/output +routines including manipulators. The scientific and fixed manipulators won't +work with Visual C++, version 6.

    +

    You need to #include the files iostream.h, +iomanip.h, newmatio.h in your C++ source files that use this facility. The +files iostream.h, iomanip.h will be included automatically if you include the +statement #define WANT_STREAM at the beginning of your source file. So +you can begin your file with either

    +
       #define WANT_STREAM
        #include "newmatio.h"
    -
    +
    -

    or

    -
    -   #include <iostream>
    +

    or

    +
       #include <iostream>
        #include <iomanip>
        #include "newmatio.h"
    -
    +
    -

    - The present version of this routine is useful only for matrices small - enough to fit within a page or screen width. -

    -

    - To print several vectors or matrices in columns use a - concatenation operator: -

    -
    -   ColumnVector A, B;
    +

    The present version of this routine is useful only for matrices small enough +to fit within a page or screen width.

    +

    To print several vectors or matrices in columns use a concatenation operator:

    +
       ColumnVector A, B;
        .....
        cout << setw(10) << setprecision(5) << (A | B) << endl;
    -
    - -

    3.18 Unspecified type

    -

    - next - skip - - up - start -

    -

    Skip this section on your first reading.

    -

    - If you want to work with a matrix of unknown type, say in a function. You - can construct a matrix of type GenericMatrix. Eg -

    -
    -   Matrix A;
    +
    + +

    3.18 Unspecified type

    +

    next - skip - +up - start

    +

    Skip this section on your first reading.

    +

    If you want to work with a matrix of unknown type, say in a function. You +can construct a matrix of type GenericMatrix. Eg

    +
       Matrix A;
        .....                                  // put some values in A
        GenericMatrix GM = A;
    -
    - -

    - A GenericMatrix matrix can be used anywhere where a matrix expression can - be used and also on the left hand side of an =. You can pass any - type of matrix to a const GenericMatrix& argument in a - function. However most scalar functions including nrows(), ncols(), type() - and element access do not work with it. Nor does the ReturnMatrix - construct. swap does work with objects of - type GenericMatrix. See also the paragraph on - LinearEquationSolver. -

    -

    - An alternative and less flexible approach is to use BaseMatrix or - GeneralMatrix. -

    -

    - Suppose you wish to write a function which accesses a matrix of unknown - type including expressions (eg A*B). Then use a layout similar to - the following: -

    -
    -   void YourFunction(BaseMatrix& X)
    +
    + +

    A GenericMatrix matrix can be used anywhere where a matrix expression can be +used and also on the left hand side of an =. You can pass any type of +matrix to a const +GenericMatrix& argument in a function. However most scalar functions +including nrows(), ncols(), type() and element access do not work with it. Nor +does the ReturnMatrix construct. swap does work with objects of type +GenericMatrix. See also the paragraph on LinearEquationSolver.

    +

    An alternative and less flexible approach is to use BaseMatrix or +GeneralMatrix.

    +

    Suppose you wish to write a function which accesses a matrix of unknown type +including expressions (eg A*B). Then use a layout similar to the +following:

    +
       void YourFunction(BaseMatrix& X)
        {
           GeneralMatrix* gm = X.Evaluate();   // evaluate an expression
                                               // if necessary
           ........                            // operations on *gm
           gm->tDelete();                      // delete *gm if a temporary
        }
    -
    - -

    - See, as an example, the definitions of operator<< in - newmat9.cpp. -

    -

    - Under certain circumstances; particularly where X is to be used - just once in an expression you can leave out the - Evaluate() statement and the corresponding tDelete(). - Just use X in the expression. -

    -

    - If you know YourFunction will never have to handle a formula as its - argument you could also use -

    -
    -   void YourFunction(const GeneralMatrix& X)
    +
    + +

    See, as an example, the definitions of operator<< in +newmat9.cpp.

    +

    Under certain circumstances; particularly where X is to be used +just once in an expression you can leave out the Evaluate() statement +and the corresponding tDelete(). Just use X in the +expression.

    +

    If you know YourFunction will never have to handle a formula as its argument +you could also use

    +
       void YourFunction(const GeneralMatrix& X)
        {
           ........                            // operations on X
        }
    -
    - -

    Do not try to construct a GeneralMatrix or BaseMatrix.

    -

    3.19 Cholesky decomposition

    -

    - next - skip - - up - start -

    -

    - Suppose S is symmetric and positive definite. Then there exists a - unique lower triangular matrix L such that - L * L.t() = S. To calculate this use -

    -
    -    SymmetricMatrix S;
    +
    + +

    Do not try to construct a GeneralMatrix or BaseMatrix.

    +

    3.19 Cholesky +decomposition

    +

    next - skip - +up - start

    +

    Suppose S is symmetric and positive definite. Then there exists a +unique lower triangular matrix L such that L * L.t() = S. To +calculate this use

    +
        SymmetricMatrix S;
         ......
         LowerTriangularMatrix L = Cholesky(S);
    -
    +
    -

    - If S is a symmetric band matrix then L is a band matrix - and an alternative procedure is provided for carrying out the - decomposition: -

    -
    -    SymmetricBandMatrix S;
    +

    If S is a symmetric band matrix then L is a band matrix +and an alternative procedure is provided for carrying out the decomposition: +

    +
        SymmetricBandMatrix S;
         ......
    -    LowerBandMatrix L = Cholesky(S);
    - -

    - See section 3.32 on updating a Cholesky - decomposition.
    -

    - -

    3.20 QR decomposition

    -

    - next - skip - - up - start -

    -

    This is a variant on the usual QR transformation.

    -

    Start with matrix (dimensions shown to left and below the matrix)

    -
    -       / 0    0 \      s
    +    LowerBandMatrix L = Cholesky(S);
    + +

    See section 3.32 on updating a Cholesky +decomposition.
    +

    + +

    3.20 QR decomposition

    +

    next - skip - +up - start

    +

    This is a variant on the usual QR transformation.

    +

    Start with matrix (dimensions shown to left and below the matrix)

    +
           / 0    0 \      s
            \ X    Y /      n
     
              s    t
    -
    +
    -

    - Our version of the QR decomposition multiplies this matrix by an - orthogonal matrix Q to get -

    -
    -       / U    M \      s
    +

    Our version of the QR decomposition multiplies this matrix by an orthogonal +matrix Q to get

    +
           / U    M \      s
            \ 0    Z /      n
     
              s    t
    +
    + +

    where U is upper triangular (the R of the QR transform). That is +

    +
          Q  / 0   0 \  =  / U   M \
    +         \ X   Y /     \ 0   Z / 
    + +

    This is good for solving least squares problems: choose b (matrix or column +vector) to minimise the sum of the squares of the elements of

    +
             Y - X*b
    +
    + +

    Then choose b = U.i()*M; The residuals Y - X*b are in +Z.

    +

    This is the usual QR transformation applied to the matrix X with +the square zero matrix concatenated on top of it. It gives the same triangular +matrix as the QR transform applied directly to X and generally seems +to work in the same way as the usual QR transform. However it fits into the +matrix package better and also gives us the residuals directly. It turns out to +be essentially a modified Gram-Schmidt decomposition.

    +

    Two routines are provided in newmat:

    +
        QRZ(X, U);
    +
    + +

    replaces X by orthogonal columns and forms U.

    +
        QRZ(X, Y, M);
    +
    + +

    uses X from the first routine, replaces Y by Z +and forms M. There is also a routine

    +
        QRZ(X, Y, U, M);
    +

    which does both of these.

    +

    To extend U to a square orthogonal matrix see the function for +extending an orthonormal set of columns.

    +

    The are also routines QRZT(X, L), QRZT(X, Y, M) +and QRZT(X, Y, L, M) +which do the same decomposition on the transposes of all these matrices. QRZT +replaces the routines HHDecompose in earlier versions of newmat. +HHDecompose is +still defined but just calls QRZT.

    +

    For an example of the use of this decomposition see the file +example.cpp.

    +

    See the section on updating a Cholesky decomposition +for updating U.

    +

    Alternatively to update U or L with a new block of data, X, one can use

    +
        updateQRZ(X, U);
     
    - -

    - where U is upper triangular (the R of the QR transform). That is -

    -
    -      Q  / 0   0 \  =  / U   M \
    -         \ X   Y /     \ 0   Z / 
    - -

    - This is good for solving least squares problems: choose b (matrix or - column vector) to minimise the sum of the squares of the elements of -

    -
    -         Y - X*b
    -
    - -

    - Then choose b = U.i()*M; The residuals Y - X*b are in - Z. -

    -

    - This is the usual QR transformation applied to the matrix X with - the square zero matrix concatenated on top of it. It gives the same - triangular matrix as the QR transform applied directly to X and - generally seems to work in the same way as the usual QR transform. However - it fits into the matrix package better and also gives us the residuals - directly. It turns out to be essentially a modified Gram-Schmidt - decomposition. -

    -

    Two routines are provided in newmat:

    -
    -    QRZ(X, U);
    -
    - -

    replaces X by orthogonal columns and forms U.

    -
    -    QRZ(X, Y, M);
    -
    - -

    - uses X from the first routine, replaces Y by - Z and forms M. There is also a routine -

    -
        QRZ(X, Y, U, M);
    -

    which does both of these.

    -

    - To extend U to a square orthogonal matrix see the function for - extending an orthonormal set of columns. -

    -

    - The are also routines QRZT(X, L), QRZT(X, Y, M) and - QRZT(X, Y, L, M) which do the same decomposition on the - transposes of all these matrices. QRZT replaces the routines - HHDecompose in earlier versions of newmat. - HHDecompose is still defined but just calls QRZT. -

    -

    - For an example of the use of this decomposition see the file - example.cpp. -

    -

    - See the section on - updating a Cholesky decomposition for updating - U. -

    -

    - Alternatively to update U or L with a new block of data, - X, one can use -

    -
    -    updateQRZ(X, U);
    -
    -

    or

    -
        updateQRZT(X, L);
    -

    You can update the M matrix with

    -
        updateQRZ(X, Y, M);
    -

    - At present, there is no corresponding function for updateQRZT. - Also note, at present, updateQRZ(X, Y, M) is not optimised for - accessing contiguous locations. -

    -

    - If you have carried out QRZ transforms on two blocks of data, X1, - X2, (same number of columns in each) with the data to be fitted - in Y1, Y2, you can combine them as follows -

    -
    -    // QRZ transforms of two blocks of data
    +

    or

    +
        updateQRZT(X, L);
    +

    You can update the M matrix with

    +
        updateQRZ(X, Y, M);
    +

    At present, there is no corresponding function for updateQRZT. Also +note, at present, updateQRZ(X, Y, M) is not optimised for accessing +contiguous locations.

    +

    If you have carried out QRZ transforms on two blocks of data, X1, X2, +(same number of columns in each) with the data to be fitted in Y1, +Y2, you can combine them as follows

    +
        // QRZ transforms of two blocks of data
         UpperTriangularMatrix U1, U2; Matrix M1, M2;
         QRZ(X1, U1); QRZ(X2, U2); QRZ(X1, Y1, M1); QRZ(X2, Y2, M2);
     
         // Now combine the results
         updateQRZ(U1, U2); updateQRZ(U1, M1, M2);
    -

    - Results are in U2 and M2. The values in U1 and - M1 are modified so use copies if you still need the original - values. -

    -

    - The functions updateQRZ(U1, U2) and - updateQRZ(U1, M1, M2) are not optimised for accessing - contiguous locations. This is probably not an - issue, since usually all the data will fit into cache memory.  -

    -

    Notes on updateQRZ and updateQRZT:

    -
      -
    • - Use these routines if your data is arriving in blocks or there is too - much to fit into memory. -
    • -
    • - Use QRZ or QRZT on the first block of data or you can - use updateQRZ or updateQRZT if U or - L is correctly dimensioned and set to zero. -
    • -
    • - The block of data, X, will be modified by these routines but - the modified data is probably not useful for further analysis. -
    • -
    • - The signs of some of the rows of U or columns of - L maybe the reverse of what you would expect (i.e. you get the - negative of what you get from QRZ or QRZT applied to the whole dataset). - Usually this will not be a problem. -
    • -
    • - The second version of updateQRZ is sometimes a more useful way of - combining blocks, especially if you want to use the - reduce function in Intel's Threaded Building Blocks to - parallelise QRZ. (Contact me for what you need to do to make Newmat - compatible with Threaded Building Blocks). -
    • -
    • - See the function summary list for the older - depreciated function names. -
    • -
    -

     

    -

    3.21 Singular value decomposition

    -

    - next - skip - - up - start -

    -

    - The singular value decomposition of an m x n Matrix - A (where m >= n) is a decomposition -

    -
    -    A  = U * D * V.t()
    -
    - -

    - where U is m x n with U.t() * U equalling - the identity, D is an n x n DiagonalMatrix and V is an n x - n orthogonal matrix (type Matrix in Newmat). -

    -

    - Singular value decompositions are useful for understanding the structure - of ill-conditioned matrices, solving least squares problems, and for - finding the eigenvalues of A.t() * A. -

    -

    - To calculate the singular value decomposition of A (with - m >= n) use one of -

    -
    -    SVD(A, D, U, V);                  // U = A is OK
    +

    Results are in U2 and M2. The values in U1 and +M1 are modified so use copies if you still need the original values.

    +

    The functions updateQRZ(U1, U2) and updateQRZ(U1, M1, M2) +are not optimised for accessing contiguous locations. +This is probably not an issue, since usually all the data will fit into cache +memory. 

    +

    Notes on updateQRZ and updateQRZT:

    +
      +
    • Use these routines if your data is arriving in blocks or there is too much to +fit into memory.
    • +
    • Use QRZ or QRZT on the first block of data or you can use + updateQRZ or +updateQRZT if U or L is correctly dimensioned and set to zero.
    • +
    • The block of data, X, will be modified by these routines but the +modified data is probably not useful for further analysis.
    • +
    • The signs of some of the rows of U or columns of L maybe the reverse of what you would +expect (i.e. you get the negative of what you get from QRZ or QRZT applied to + the whole dataset). Usually this will not be a problem.
    • +
    • The second version of updateQRZ is sometimes a more useful way of + combining blocks, especially if you want to use the reduce function + in Intel's Threaded Building Blocks to parallelise QRZ. (Contact me + for what you need to do to make Newmat compatible with Threaded Building + Blocks).
    • +
    • See the function summary list for the older +depreciated function names.
    • +
    +

     

    +

    3.21 Singular value +decomposition

    +

    next - skip - +up - start

    +

    The singular value decomposition of an m x n Matrix +A (where m >= n) is a decomposition

    +
        A  = U * D * V.t()
    +
    + +

    where U is m x n with U.t() * U equalling +the identity, D is an n x n DiagonalMatrix and +V is an n x n orthogonal matrix (type Matrix in +Newmat).

    +

    Singular value decompositions are useful for understanding the structure of +ill-conditioned matrices, solving least squares problems, and for finding the +eigenvalues of A.t() * A.

    +

    To calculate the singular value decomposition of A (with m +>= n) use one of

    +
        SVD(A, D, U, V);                  // U = A is OK
         SVD(A, D);
         SVD(A, D, U);                     // U = A is OK
         SVD(A, D, U, false);              // U (can = A) for workspace only
         SVD(A, D, U, V, false);           // U (can = A) for workspace only
    -
    - -

    - where A, U and V are of type - Matrix and D is a DiagonalMatrix. The values of - A are not changed unless A is also inserted as the third - argument. -

    - -

    The elements of D are sorted in descending order.

    - -

    - To extend U to a square orthogonal matrix see the function for - extending an orthonormal set of columns. -

    -

    - Remember that the SVD decomposition is not completely unique. The signs of - the elements in a column of U may be reversed if the signs in the - corresponding column in V are reversed. If a number of the - singular values are identical one can apply an orthogonal transformation - to the corresponding columns of U and the corresponding columns - of V. -

    -

    - If m < n apply the SVD transform to the transpose of A - and swap U and V. If necessary, extend U to a square matrix as described - above. -

    -

    3.22 Eigenvalue decomposition

    -

    - next - skip - - up - start -

    -

    - An eigenvalue decomposition of a SymmetricMatrix A is a - decomposition -

    -
    -    A  = V * D * V.t()
    -
    - -

    - where V is an orthogonal matrix (type Matrix in - Newmat) and D is a DiagonalMatrix. -

    -

    - Eigenvalue analyses are used in a wide variety of engineering, statistical - and other mathematical analyses. -

    -

    - The package includes two algorithms: Jacobi and Householder. The first is - extremely reliable but much slower than the second. -

    -

    - The code is adapted from routines in - Handbook for Automatic Computation, Vol II, Linear Algebra by - Wilkinson and Reinsch, published by Springer Verlag. -

    -
    -    Jacobi(A,D,S,V);                  // A, S symmetric; S is workspace,
    +
    + +

    where A, U and V are of type Matrix and +D is a DiagonalMatrix. The values of A are not +changed unless A is also inserted as the third argument.

    + +

    The elements of D are sorted in descending order.

    + +

    To extend U to a square orthogonal matrix see the function for +extending an orthonormal set of columns.

    +

    Remember that the SVD decomposition is not completely unique. The signs of the elements in a column of U may be reversed +if the signs in the corresponding column in V are reversed. If a +number of the singular values are identical one can apply an orthogonal +transformation to the corresponding columns of U and the corresponding +columns of V.

    +

    If m < n apply the SVD transform to the transpose +of A and swap U and V. If necessary, extend U to a square matrix as described +above.

    +

    3.22 Eigenvalue +decomposition

    +

    next - skip - +up - start

    +

    An eigenvalue decomposition of a SymmetricMatrix A is a +decomposition

    +
        A  = V * D * V.t()
    +
    + +

    where V is an orthogonal matrix (type Matrix in +Newmat) and D is a DiagonalMatrix.

    +

    Eigenvalue analyses are used in a wide variety of engineering, statistical +and other mathematical analyses.

    +

    The package includes two algorithms: Jacobi and Householder. The first is +extremely reliable but much slower than the second.

    +

    The code is adapted from routines in Handbook for Automatic Computation, +Vol II, Linear Algebra by Wilkinson and Reinsch, published by Springer +Verlag.

    +
        Jacobi(A,D,S,V);                  // A, S symmetric; S is workspace,
                                           //    S = A is OK; V is a matrix
         Jacobi(A,D);                      // A symmetric
         Jacobi(A,D,S);                    // A, S symmetric; S is workspace,
    @@ -3287,268 +2422,197 @@ 

    3.22 Eigenvalue decomposition

    eigenvalues(A,D,S); // A, S symmetric; S is for back // transforming, S = A is OK eigenvalues(A,D,V); // A symmetric; V is a matrix -
    - -

    - where A, S are of type SymmetricMatrix, - D is of type DiagonalMatrix and V is of type - Matrix. The values of A are not changed unless - A is also inserted as the third argument. If you need - eigenvectors use one of the forms with matrix V. The eigenvectors - are returned as the columns of V. -

    - -

    The elements of D are sorted in ascending order.

    -

    - Remember that an eigenvalue decomposition is not completely unique - see - the comments about the SVD decomposition. -

    -

    - See the function summary list for the older - depreciated function names. -

    -

    3.23 Sorting

    -

    - next - skip - - up - start -

    -

    - To sort the values in a matrix or vector, A, (in general this - operation makes sense only for vectors and diagonal matrices) use one of -

    -
    -    sort_ascending(A);
    +
    + +

    where A, S are of type SymmetricMatrix, +D is of type DiagonalMatrix and V is of type +Matrix. The values of A are not changed unless A is +also inserted as the third argument. If you need eigenvectors use one of the +forms with matrix V. The eigenvectors are returned as the columns of +V.

    + +

    The elements of D are sorted in ascending order.

    +

    Remember that an eigenvalue decomposition is not completely +unique - see the comments about the SVD +decomposition.

    +

    See the function summary list for the older +depreciated function names.

    +

    3.23 Sorting

    +

    next - skip - +up - start

    +

    To sort the values in a matrix or vector, A, (in general this +operation makes sense only for vectors and diagonal matrices) use one of

    +
        sort_ascending(A);
     
         sort_descending(A);
    -
    - -

    - I use the quicksort algorithm. The algorithm is similar to that in - Sedgewick's algorithms in C++. If the sort seems to be failing (as - quicksort can do) an exception is thrown. -

    -

    - You will get incorrect results if you try to sort a band matrix - but why - would you want to sort a band matrix? -

    -

    - See the function summary list for the older - depreciated function names. -

    -

    3.24 Fast Fourier transform

    -

    - next - skip - - up - start -

    -
    -   FFT(X, Y, F, G);                         // F=X and G=Y are OK
    -
    - -

    - where X, Y, F, G are ColumnVectors. - X and Y are the real and imaginary input vectors; - F and G are the real and imaginary output vectors. The - lengths of X and Y must be equal and should be the - product of numbers less than about 10 for fast execution. -

    -

    The formula is

    -
    -          n-1
    +
    + +

    I use the quicksort algorithm. The algorithm is similar to that in +Sedgewick's algorithms in C++. If the sort seems to be failing (as quicksort +can do) an exception is thrown.

    +

    You will get incorrect results if you try to sort a band matrix - but why +would you want to sort a band matrix?

    +

    See the function summary list for the older +depreciated function names.

    +

    3.24 Fast Fourier transform +

    +

    next - skip - +up - start

    +
       FFT(X, Y, F, G);                         // F=X and G=Y are OK
    +
    + +

    where X, Y, F, G are ColumnVectors. +X and Y are the real and imaginary input vectors; F +and G are the real and imaginary output vectors. The lengths of +X and Y must be equal and should be the product of numbers +less than about 10 for fast execution.

    +

    The formula is

    +
              n-1
        h[k] = SUM  z[j] exp (-2 pi i jk/n)
               j=0
    -
    - -

    - where z[j] is stored complex and stored in X(j+1) and - Y(j+1). Likewise h[k] is complex and stored in - F(k+1) and G(k+1). The fast Fourier algorithm takes - order n log(n) operations (for good values of - n) rather than n**2 that straight evaluation (see the file - tmtf.cpp) takes. -

    -

    I use one of two methods:

    -
      -
    • - A program originally written by Sande and Gentleman. This requires that - n can be expressed as a product of small numbers. -
    • -
    • - A method of Carl de Boor (1980), Siam J Sci Stat Comput, pp - 173-8. The sines and cosines are calculated explicitly. This gives - better accuracy, at an expense of being a little slower than is - otherwise possible. This is slower than the Sande-Gentleman program but - will work for all n --- although it will be very slow for - bad values of n. -
    • -
    -

    Related functions

    -
    -   FFTI(F, G, X, Y);                        // X=F and Y=G are OK
    +
    + +

    where z[j] is stored complex and stored in X(j+1) and +Y(j+1). Likewise h[k] is complex and stored in +F(k+1) and G(k+1). The fast Fourier algorithm takes order +n log(n) operations (for good values of n) rather than +n**2 that straight evaluation (see the file tmtf.cpp) takes. +

    +

    I use one of two methods:

    +
      +
    • A program originally written by Sande and Gentleman. This requires that +n can be expressed as a product of small numbers.
    • +
    • A method of Carl de Boor (1980), Siam J Sci Stat Comput, pp 173-8. +The sines and cosines are calculated explicitly. This gives better accuracy, at +an expense of being a little slower than is otherwise possible. This is slower +than the Sande-Gentleman program but will work for all n --- although it +will be very slow for bad values of n.
    • +
    +

    Related functions

    +
       FFTI(F, G, X, Y);                        // X=F and Y=G are OK
        RealFFT(X, F, G);
        RealFFTI(F, G, X);
    -
    - -

    - FFTI is the inverse transform for FFT. - RealFFT is for the case when the input vector is real, that is - Y = 0. I assume the length of X, denoted by n, is - even. That is, n must be divisible by 2. The program sets - the lengths of F and G to n/2 + 1. - RealFFTI is the inverse of RealFFT. -

    -

    - See also the section on fast - trigonometric transforms. -

    -

    There are also two dimensional versions

    -
    -   FFT2(X, Y, F, G);                       // F=X and G=Y are OK
    +
    + +

    FFTI is the inverse transform for FFT. RealFFT is +for the case when the input vector is real, that is Y = 0. I assume +the length of X, denoted by n, is even. That is, +n must be divisible by 2. The program sets the lengths of F and +G to n/2 + 1. RealFFTI is the inverse of +RealFFT.

    +

    See also the section on fast trigonometric +transforms.

    +

    There are also two dimensional versions

    +
       FFT2(X, Y, F, G);                       // F=X and G=Y are OK
        FFT2I(F, G, X, Y);                      // inverse, X=F and Y=G are OK
    -

    - where X, Y, F, G are of type Matrix. - X and Y are the real and imaginary input matrices; - F and G are the real and imaginary output matrices. The - dimensions of Y must be the same as those of X and - should be the product of numbers less than about 10 for fast execution. -

    -

    The formula is

    -
    -            m-1 n-1
    +

    where X, Y, F, G are of type Matrix. +X and Y are the real and imaginary input matrices; F +and G are the real and imaginary output matrices. The dimensions of Y +must be the same as those of X and should be the product of numbers +less than about 10 for fast execution.

    +

    The formula is

    +
                m-1 n-1
        h[p,q] = SUM SUM z[j,k] exp (-2 pi i (jp/m + kq/n))
                 j=0 k=0
    -
    - -

    - where z[j,k] is stored complex and stored in - X(j+1,k+1) and Y(j+1,k+1) and X and - Y have dimension m x n. Likewise h[p,q] is - complex and stored in F(p+1,q+1) and G(p+1,q+1). -

    -

     

    -

    3.25 Fast trigonometric transforms

    -

    - next - skip - - up - start -

    -

    - These are the sin and cosine transforms as defined by Charles Van Loan - (1992) in - Computational frameworks for the fast Fourier transform published - by SIAM. See page 229. Some other authors use slightly different - conventions. All the functions call the - fast Fourier transforms and require an - even transform length, denoted by m in these notes. That - is, m must be divisible by 2. As with the FFT m should be - the product of numbers less than about 10 for fast execution. -

    -

    The functions I define are

    -
    -   DCT(U,V);                // U, V are ColumnVectors, length m+1
    +
    + +

    where z[j,k] is stored complex and stored in X(j+1,k+1) and +Y(j+1,k+1) and X and Y have dimension m x n. Likewise h[p,q] is complex and stored in +F(p+1,q+1) and G(p+1,q+1). +

    +

     

    +

    3.25 Fast trigonometric +transforms

    +

    next - skip - +up - start

    +

    These are the sin and cosine transforms as defined by Charles Van Loan +(1992) in Computational frameworks for the fast Fourier transform +published by SIAM. See page 229. Some other authors use slightly different +conventions. All the functions call the fast Fourier +transforms and require an even transform length, denoted by +m in these notes. That is, m must be divisible by 2. As with the +FFT m should be the product of numbers less than about 10 for fast +execution.

    +

    The functions I define are

    +
       DCT(U,V);                // U, V are ColumnVectors, length m+1
        DCT_inverse(V,U);        // inverse of DCT
    -   DST(U,V);                // U, V are ColumnVectors, length m+1
    +   DST(U,V);                // U, V are ColumnVectors, length m+1
        DST_inverse(V,U);        // inverse of DST
    -   DCT_II(U,V);             // U, V are ColumnVectors, length m
    +   DCT_II(U,V);             // U, V are ColumnVectors, length m
        DCT_II_inverse(V,U);     // inverse of DCT_II
    -   DST_II(U,V);             // U, V are ColumnVectors, length m
    +   DST_II(U,V);             // U, V are ColumnVectors, length m
        DST_II_inverse(V,U);     // inverse of DST_II
    -
    - -

    - where the first argument is the input and the second argument is the - output. V = U is OK. The length of the output ColumnVector is set - by the functions. -

    -

    Here are the formulae:

    -

    DCT

    -
    -                   m-1                             k
    +
    + +

    where the first argument is the input and the second argument is the output. +V = U is OK. The length of the output ColumnVector is set by the +functions.

    +

    Here are the formulae:

    +

    DCT

    +
                       m-1                             k
        v[k] = u[0]/2 + SUM { u[j] cos (pi jk/m) } + (-) u[m]/2
                        j=1
    -
    +
    -

    - for k = 0...m, where u[j] and v[k] are stored - in U(j+1) and V(k+1). -

    -

    DST

    -
    -          m-1
    +

    for k = 0...m, where u[j] and v[k] are stored in +U(j+1) and V(k+1).

    +

    DST

    +
              m-1
        v[k] = SUM { u[j] sin (pi jk/m) }
               j=1
    -
    - -

    - for k = 1...(m-1), where u[j] and v[k] are - stored in U(j+1) and V(k+1)and where u[0] and - u[m] are ignored and v[0] and v[m] are set to - zero. For the inverse function v[0] and v[m] are ignored - and u[0] and u[m] are set to zero. -

    -

    DCT_II

    -
    -          m-1
    +
    + +

    for k = 1...(m-1), where u[j] and v[k] are stored +in U(j+1) and V(k+1)and where u[0] and u[m] +are ignored and v[0] and v[m] are set to zero. For the +inverse function v[0] and v[m] are ignored and u[0] +and u[m] are set to zero.

    +

    DCT_II

    +
              m-1
        v[k] = SUM { u[j] cos (pi (j+1/2)k/m) }
               j=0
    -
    +
    -

    - for k = 0...(m-1), where u[j] and v[k] are - stored in U(j+1) and V(k+1). -

    -

    DST_II

    -
    -           m
    +

    for k = 0...(m-1), where u[j] and v[k] are stored +in U(j+1) and V(k+1).

    +

    DST_II

    +
               m
        v[k] = SUM { u[j] sin (pi (j-1/2)k/m) }
               j=1
    -
    - -

    - for k = 1...m, where u[j] and v[k] are stored - in U(j) and V(k). -

    -

    - Note that the relationship between the subscripts in the formulae and - those used in newmat is different for DST_II (and DST_II_inverse). -

    -

    3.26 Interface to Numerical Recipes in C

    -

    - next - skip - - up - start -

    -

    - This section refers to Numerical Recipes in C. This section is - not relevant to Numerical Recipes in C++. I'll put a note on - the website soon on how to interface with Numerical Recipes in C++. -

    -

    - This package can be used with the vectors and matrices defined in - Numerical Recipes in C. You need to edit the routines in Numerical - Recipes so that the elements are of the same type as used in this package. - Eg replace float by double, vector by dvector and matrix by dmatrix, etc. - You may need to edit the function definitions to use the version - acceptable to your compiler (if you are using the first edition of NRIC). - You may need to enclose the code from Numerical Recipes in - extern "C" { ... }. You will also need to include the - matrix and vector utility routines. -

    -

    - Then any vector in Numerical Recipes with subscripts starting from 1 in a - function call can be accessed by a RowVector, ColumnVector or - DiagonalMatrix in the present package. Similarly any matrix with - subscripts starting from 1 can be accessed by an nricMatrix in the present - package. The class nricMatrix is derived from Matrix and can be used in - place of Matrix. In each case, if you wish to refer to a RowVector, - ColumnVector, DiagonalMatrix or nricMatrix X in an function from - Numerical Recipes, use X.nric() in the function call. -

    -

    - Numerical Recipes cannot change the dimensions of a matrix or vector. So - matrices or vectors must be correctly dimensioned before a Numerical - Recipes routine is called. -

    -

    For example

    -
    -   SymmetricMatrix B(44);
    +
    + +

    for k = 1...m, where u[j] and v[k] are stored in +U(j) and V(k).

    +

    Note that the relationship between the subscripts in the formulae and those +used in newmat is different for DST_II (and DST_II_inverse).

    +

    3.26 Interface to Numerical +Recipes in C

    +

    next - skip - +up - start

    +

    This section refers to Numerical Recipes in C. This section is not +relevant to Numerical Recipes in C++. I'll put a note on the website soon +on how to interface with Numerical Recipes in C++.

    +

    This package can be used with the vectors and matrices defined in +Numerical Recipes in C. You need to edit the routines in Numerical +Recipes so that the elements are of the same type as used in this package. Eg +replace float by double, vector by dvector and matrix by dmatrix, etc. You may +need to edit the function definitions to use the version acceptable to your +compiler (if you are using the first edition of NRIC). You may need to enclose +the code from Numerical Recipes in extern "C" { ... }. You +will also need to include the matrix and vector utility routines.

    +

    Then any vector in Numerical Recipes with subscripts starting from 1 in a +function call can be accessed by a RowVector, ColumnVector or DiagonalMatrix in +the present package. Similarly any matrix with subscripts starting from 1 can +be accessed by an nricMatrix in the present package. The class nricMatrix is +derived from Matrix and can be used in place of Matrix. In each case, if you +wish to refer to a RowVector, ColumnVector, DiagonalMatrix or nricMatrix +X in an function from Numerical Recipes, use X.nric() in the +function call.

    +

    Numerical Recipes cannot change the dimensions of a matrix or vector. So +matrices or vectors must be correctly dimensioned before a Numerical Recipes +routine is called.

    +

    For example

    +
       SymmetricMatrix B(44);
        .....                             // load values into B
        nricMatrix BX = B;                // copy values to an nricMatrix
        DiagonalMatrix D(44);             // Matrices for output
    @@ -3557,16 +2621,13 @@ 

    3.26 Interface to Numerical Recipes in C

    jacobi(BX.nric(),44,D.nric(),V.nric(),&nrot); // jacobi from NRIC cout << D; // print eigenvalues -
    +
    -

    3.27 Exceptions

    -

    - next - skip - - up - start -

    -

    Here is the class structure for exceptions:

    -
    -Exception
    +

    3.27 Exceptions

    +

    next - skip - +up - start

    +

    Here is the class structure for exceptions:

    +
    Exception
       Logic_error
         ProgramException                 miscellaneous matrix error
         IndexException                   index out of bounds
    @@ -3584,673 +2645,469 @@ 

    3.27 Exceptions

    SolutionException no convergence in solution routine OverflowException floating point overflow Bad_alloc out of space (new fails) -
    - -

    - I have attempted to mimic the exception class structure in the C++ - standard library, by defining the Logic_error and Runtime_error classes. -

    -

    - Suppose you have edited include.h to use my - simulated exceptions or to disable exceptions. If there is - no catch statement or exceptions are disabled then my - Terminate() function in myexcept.h is called when you - throw an exception. This prints out an error message, the dimensions and - types of the matrices involved, the name of the routine detecting the - exception, and any other information set by the - Tracer class. Also see the section on - error messages for additional notes on the messages - generated by the exceptions. -

    -

    - You can also print this information in a catch clause by printing - Exception::what(). -

    -

    - If you are using compiler supported exceptions then see the - section on catching exceptions.  -

    -

    - See the file test_exc.cpp as an example of catching an exception - and printing the error message. -

    -

    - The 08 version of newmat defined a member function - void SetAction(int) to help customise the action when an - exception is called. This has been deleted in the 09 and later versions. - Now include an instruction such as - cout << Exception::what() << endl; in the - Catch or CatchAll block to determine the action. -

    -

    - The library includes the alternatives of using the inbuilt exceptions - provided by a compiler, simulating exceptions, or disabling exceptions. - See customising for selecting the correct exception - option. -

    -

    - The rest of this section describes my partial simulation of exceptions for - compilers which do not support C++ exceptions. Skip the rest of this - section and the next section if you are using compiler supported - exceptions. I use Carlos Vidal's article in the September 1992 - C Users Journal as a starting point. -

    -

    - Newmat does a partial clean up of memory following throwing an exception - - see the next section. However, the present version will leave a little - heap memory unrecovered under some circumstances. I would not expect this - to be a major problem, but it is something that needs to be sorted out. -

    -

    - The functions/macros I define are Try, Throw, Catch, CatchAll and - CatchAndThrow. Try, Throw, Catch and CatchAll correspond to try, throw, - catch and catch(...) in the C++ standard. A list of Catch clauses must be - terminated by either CatchAll or CatchAndThrow but not both. Throw takes - an Exception as an argument or takes no argument (for passing on an - exception). I do not have a version of Throw for specifying which - exceptions a function might throw. Catch takes an exception class name as - an argument; CatchAll and CatchAndThrow don't have any arguments. Try, - Catch and CatchAll must be followed by blocks enclosed in curly brackets. -

    -

    - I have added another macro ReThrow to mean a rethrow, Throw(). This was - necessary to enable the package to be compatible with both my exception - package and C++ exceptions. -

    -

    If you want to throw an exception, use a statement like

    -
    -   Throw(Exception("Error message\n"));
    -
    - -

    - It is important to have the exception declaration in the Throw statement, - rather than as a separate statement. -

    -

    - All exception classes must be derived from the class, Exception, defined - in newmat and can contain only static variables. See the examples in - newmat if you want to define additional exceptions. -

    -

    - Note that the simulation exception mechanism does not work if you define - arrays of matrices. -

    -

    3.28 Cleanup after an exception

    -

    - next - skip - - up - start -

    -

    - This section is about the simulated exceptions used in newmat. It - is irrelevant if you are using the exceptions built into a compiler - or have set the disable-exceptions option. -

    -

    - The simulated exception mechanisms in newmat are based on the C functions - setjmp and longjmp. These functions do not call destructors so can lead to - garbage being left on the heap. (I refer to memory allocated by - new as heap memory). For example, when you call -

    -
    -   Matrix A(20,30);
    -
    - -

    - a small amount of space is used on the stack containing the row and column - dimensions of the matrix and 600 doubles are allocated on the heap for the - actual values of the matrix. At the end of the block in which A is - declared, the destructor for A is called and the 600 doubles are freed. - The locations on the stack are freed as part of the normal operations of - the stack. If you leave the block using a longjmp command those 600 - doubles will not be freed and will occupy space until the program - terminates. -

    -

    - To overcome this problem newmat keeps a list of all the currently declared - matrices and its exception mechanism will return heap memory when you do a - Throw and Catch. -

    -

    - However it will not return heap memory from objects from other packages. -

    -

    - If you want the mechanism to work with another class you will have to do - four things: -

    -
      -
    1. derive your class from class Janitor defined in except.h;
    2. -
    3. - define a function void CleanUp() in that class to return all - heap memory; -
    4. -
    5. - include the following lines in the class definition -
      -      public:
      +
      + +

      I have attempted to mimic the exception class structure in the C++ standard +library, by defining the Logic_error and Runtime_error classes.

      +

      Suppose you have edited include.h to use my simulated +exceptions or to disable exceptions. If there is no catch statement or exceptions are disabled then my +Terminate() function in myexcept.h is called when you throw an +exception. This prints out +an error message, the dimensions and types of the matrices involved, the name +of the routine detecting the exception, and any other information set by the +Tracer class. Also see the section on error messages for additional notes on the messages generated +by the exceptions.

      +

      You can also print this information in a catch clause by printing Exception::what(). +

      +

      If you are using compiler supported exceptions then see the section +on catching exceptions.  +

      +

      See the file test_exc.cpp as an example of catching an exception +and printing the error message.

      +

      The 08 version of newmat defined a member function void +SetAction(int) to help customise the action when an exception is called. +This has been deleted in the 09 and later versions. Now include an instruction +such as cout << Exception::what() << endl; in the +Catch or CatchAll block to determine the action.

      +

      The library includes the alternatives of using the inbuilt exceptions +provided by a compiler, simulating exceptions, or disabling exceptions. See +customising for selecting the correct exception option. +

      +

      The rest of this section describes my partial simulation of exceptions for +compilers which do not support C++ exceptions. Skip the rest of this section and +the next section if you are using compiler supported exceptions. I use Carlos Vidal's article in +the September 1992 C Users Journal as a starting point.

      +

      Newmat does a partial clean up of memory following throwing an exception - +see the next section. However, the present version will leave a little heap +memory unrecovered under some circumstances. I would not expect this to be a +major problem, but it is something that needs to be sorted out.

      +

      The functions/macros I define are Try, Throw, Catch, CatchAll and +CatchAndThrow. Try, Throw, Catch and CatchAll correspond to try, throw, catch +and catch(...) in the C++ standard. A list of Catch clauses must be terminated +by either CatchAll or CatchAndThrow but not both. Throw takes an Exception as +an argument or takes no argument (for passing on an exception). I do not have a +version of Throw for specifying which exceptions a function might throw. Catch +takes an exception class name as an argument; CatchAll and CatchAndThrow don't +have any arguments. Try, Catch and CatchAll must be followed by blocks enclosed +in curly brackets.

      +

      I have added another macro ReThrow to mean a rethrow, Throw(). This was +necessary to enable the package to be compatible with both my exception package +and C++ exceptions.

      +

      If you want to throw an exception, use a statement like

      +
         Throw(Exception("Error message\n"));
      +
      + +

      It is important to have the exception declaration in the Throw statement, +rather than as a separate statement.

      +

      All exception classes must be derived from the class, Exception, defined in +newmat and can contain only static variables. See the examples in newmat if you +want to define additional exceptions.

      +

      Note that the simulation exception mechanism does not work if you define +arrays of matrices.

      +

      3.28 Cleanup after an +exception

      +

      next - skip - +up - start

      +

      This section is about the simulated exceptions used in newmat. It is +irrelevant if you are using the exceptions built into a compiler or have set +the disable-exceptions option.

      +

      The simulated exception mechanisms in newmat are based on the C functions +setjmp and longjmp. These functions do not call destructors so can lead to +garbage being left on the heap. (I refer to memory allocated by new as +heap memory). For example, when you call

      +
         Matrix A(20,30);
      +
      + +

      a small amount of space is used on the stack containing the row and column +dimensions of the matrix and 600 doubles are allocated on the heap for the +actual values of the matrix. At the end of the block in which A is declared, +the destructor for A is called and the 600 doubles are freed. The locations on +the stack are freed as part of the normal operations of the stack. If you leave +the block using a longjmp command those 600 doubles will not be freed and will +occupy space until the program terminates.

      +

      To overcome this problem newmat keeps a list of all the currently declared +matrices and its exception mechanism will return heap memory when you do a +Throw and Catch.

      +

      However it will not return heap memory from objects from other packages. +

      +

      If you want the mechanism to work with another class you will have to do +four things:

      +
        +
      1. derive your class from class Janitor defined in except.h;
      2. +
      3. define a function void CleanUp() in that class to return all heap +memory;
      4. +
      5. include the following lines in the class definition
              public:
                  void* operator new(size_t size)
                  { do_not_link=true; void* t = ::operator new(size); return t; }
                  void operator delete(void* t) { ::operator delete(t); }
        -
        -
      6. -
      7. - be sure to include a copy constructor in you class definition, that is, - something like -
        -      X(const X&);
        -
        -
      8. -
      -

      - Use CleanUp() rather than cleanup() since this is what - is defined in class Janitor. -

      -

      - Note that the function CleanUp() does somewhat the same duties as - the destructor. However CleanUp() has to do the - cleaning for the class you are working with and also the classes it - is derived from. So it will often be wrong to use exactly the same code - for both CleanUp() - and the destructor or to define your destructor as a call to - CleanUp(). -

      -

      3.29 Non-linear applications

      -

      - next - skip - - up - start -

      -

      - Files solution.h, solution.cpp contain a class for solving for x in - y = f(x) where x is a one-dimensional - continuous monotonic function. This is not a matrix thing at all but is - included because it is a useful program and because it is a simpler - version of the coding technique used in the non-linear least squares. -

      -

      - Files newmatnl.h, newmatnl.cpp contain a series of classes for non-linear - least squares and maximum likelihood. These classes work on very - well-behaved functions but need upgrading for less well-behaved functions. - I haven't followed the usual practice of inflating the values of the - diagonal elements of the matrix of second derivatives. I originally - thought I could avoid this if my program had a good line search. But this - was wrong and when I use this program on all but the most well-behaved - problems I run the fit first with the diagonal elements inflated by a - factor of 2 to 5 and the critical value for the stopping criterion set to - something like 50. Then rerun with with no inflation factor and critical - value 0.0001. -

      -

      - Documentation for both of these is in the definition files. Simple - examples are in sl_ex.cpp, nl_ex.cpp and garch.cpp. -

      -

      3.30 Standard template library

      -

      - next - skip - - up - start -

      -

      - The standard template library (STL) is the set of - container templates (vector, deque, list etc) defined by the C++ - standards committee. Newmat is intended to be compatible with the STL in - the sense that you can store matrices in the standard containers. I have - defined == and inequality operators which - seem to be required by some versions of the STL. -

      -

      If you want to use the container classes with Newmat please note

      -
        -
      • Don't use simulated exceptions.
      • -
      • - Make sure the option DO_FREE_CHECK is - not turned on. -
      • -
      • - You can store only one type of matrix in a container. If you want to use - a variety of types use the GenericMatrix type or store pointers to the - matrices. -
      • -
      • - The vector and deque container templates like to copy their elements. - For the vector container this happens when you insert an element - anywhere except at the end or when you append an element and the current - vector storage overflows. Since Newmat does not have - copy-on-write this could get very inefficient. -
      • -
      • - You won't be able to sort the container or do anything that would call - an inequality operator. -
      • -
      -

      3.31 Namespace

      -

      - next - skip - - up - start -

      -

      - Namespace is used to avoid name clashes between different - libraries. I have included the namespace capability. Activate the line - #define use_namespace in include.h. Then include either - the statement -

      -
      -   using namespace NEWMAT;
      -
      - -

      - at the beginning of any file that needs to access the newmat library or -

      -
      -   using namespace RBD_LIBRARIES;
      -
      - -

      at the beginning of any file that needs to access all my libraries.

      -

      - This works correctly with Borland C++ version 5 and - Builder 5 and 6. -

      -

      - Microsoft Visual C++ version 5 works in my example - and test files, but fails with apparently insignificant changes (it may be - more reliable if you have applied service pack 3). If you #include - "newmatap.h", but no other newmat include file, then also - #include "newmatio.h". It seems to work with - Microsoft Visual C++ version 6 if you have - applied at least service pack 2. -

      -

      - My use of namespace does not work with Gnu g++ version - 2.8.1 but does work with versions 3.x. -

      -

      I have defined the following namespaces:

      -
        -
      • RBD_COMMON for functions and classes used by most of my libraries
      • -
      • NEWMAT for the newmat library
      • -
      • RBD_LIBRARIES for all my libraries
      • -
      -

      3.32 Updating the Cholesky matrix

      - -

      - next - skip - - up - start -

      - -

      - Suppose X is matrix and U has been formed with either -

      - -
      -   SymmetricMatrix A; A << X.t() * X;
      +
      + +
    6. +
    7. be sure to include a copy constructor in you class definition, that is, +something like
            X(const X&);
      +
      + +
    8. +
    +

    Use CleanUp() rather than cleanup() since this is what is +defined in class Janitor.

    +

    Note that the function CleanUp() does somewhat the same duties as +the destructor. However CleanUp() has to do the cleaning for +the class you are working with and also the classes it is derived from. So it +will often be wrong to use exactly the same code for both CleanUp() +and the destructor or to define your destructor as a call to +CleanUp().

    +

    3.29 Non-linear +applications

    +

    next - skip - +up - start

    +

    Files solution.h, solution.cpp contain a class for solving for x in +y = f(x) where x is a one-dimensional continuous +monotonic function. This is not a matrix thing at all but is included because +it is a useful program and because it is a simpler version of the coding technique used +in the non-linear least squares.

    +

    Files newmatnl.h, newmatnl.cpp contain a series of classes for non-linear +least squares and maximum likelihood. These classes work on very well-behaved +functions but need upgrading for less well-behaved functions. I haven't followed +the usual practice of inflating the values of the diagonal elements of the +matrix of second derivatives. I originally thought I could avoid this if my +program had a good line search. But this was wrong and when I use this program +on all but the most well-behaved problems I run the fit first with the diagonal +elements inflated by a factor of 2 to 5 and the critical value for the stopping +criterion set to something like 50. Then rerun with with no inflation factor and +critical value 0.0001.

    +

    Documentation for both of these is in the definition files. Simple examples +are in sl_ex.cpp, nl_ex.cpp and garch.cpp.

    +

    3.30 Standard template +library

    +

    next - skip - +up - start

    +

    The standard template library (STL) is the set of container templates +(vector, deque, list etc) defined by the C++ standards committee. Newmat is +intended to be compatible with the STL in the sense that you can store matrices +in the standard containers. I have defined == and +inequality operators which seem to be required by some versions of the STL.

    +

    If you want to use the container classes with Newmat please note

    +
      +
    • Don't use simulated exceptions.
    • +
    • Make sure the option DO_FREE_CHECK is not +turned on.
    • +
    • You can store only one type of matrix in a container. If you want to use a +variety of types use the GenericMatrix type or store pointers to the matrices. +
    • +
    • The vector and deque container templates like to copy their elements. For +the vector container this happens when you insert an element anywhere except at +the end or when you append an element and the current vector storage overflows. +Since Newmat does not have copy-on-write this could get very inefficient.
    • +
    • You won't be able to sort the container or do anything that would call an +inequality operator.
    • +
    +

    3.31 Namespace

    +

    next - skip - +up - start

    +

    Namespace is used to avoid name +clashes between different libraries. I have included the namespace capability. +Activate the line #define use_namespace in include.h. Then +include either the statement

    +
       using namespace NEWMAT;
    +
    + +

    at the beginning of any file that needs to access the newmat library or

    +
       using namespace RBD_LIBRARIES;
    +
    + +

    at the beginning of any file that needs to access all my libraries.

    +

    This works correctly with Borland C++ version 5 and +Builder 5 and 6.

    +

    Microsoft Visual C++ version 5 works in my example +and test files, but fails with apparently insignificant changes (it may be more +reliable if you have applied service pack 3). If you #include +"newmatap.h", but no other newmat include file, then also #include +"newmatio.h". It seems to work with Microsoft +Visual C++ version 6 if you have applied at least service pack 2.

    +

    My use of namespace does not work with Gnu g++ version +2.8.1 but does work with versions 3.x.

    +

    I have defined the following namespaces:

    +
      +
    • RBD_COMMON for functions and classes used by most of my libraries
    • +
    • NEWMAT for the newmat library
    • +
    • RBD_LIBRARIES for all my libraries
    • +
    +

    3.32 Updating the Cholesky matrix

    + + +

    next - skip - +up - start

    + + +

    Suppose X is matrix and U has been formed with either

    + + +
       SymmetricMatrix A; A << X.t() * X;
        UpperTriangularMatrix U = Cholesky(A).t();
    -

    or

    -
    -   UpperTriangularMatrix U;
    +

    or

    +
       UpperTriangularMatrix U;
        QRZ(X, U);
    -

    See sections 3.19 and 3.20.

    -

    - Now suppose we want to append an extra row to X or delete a row - from X or rearrange the columns of X. The functions - described here allow you to update - U without  recalculating it. -

    - -
    -   update_Cholesky(U, x);                    // x is a RowVector
    +

    See sections 3.19 and 3.20.

    +

    Now suppose we want to append an extra row to X or delete a row from X +or rearrange the columns of X. The functions described here allow you to +update U without  recalculating it.

    + + +
       update_Cholesky(U, x);                    // x is a RowVector
        downdate_Cholesky(U, x);                  // x is a RowVector
        right_circular_update_Cholesky(U, j, k);  // j and k are integers
        left_circular_update_Cholesky(U, j, k);   // j and k are integers
    -

    - update_Cholesky carries out the modification of - U corresponding to appending an extra row x to - X. -

    - -

    - downdate_Cholesky carries out the modification corresponding to - removing a row x from X. A - ProgramException exception is thrown if the modification fails. -

    - -

    - right_circular_update_Cholesky supposes that columns - j,j+1,...k of X are replaced by columns - k,j,j+1,...k-1. -

    - -

    - left_circular_update_Cholesky supposes that columns - j,j+1,...k of X are replaced by columns - j+1,...k,j. -

    - -

    - These functions are based on a contribution from Nick Bennett of - Schlumberger-Doll Research. See also the LINPACK User's Guide, Chapter 10, - Dongarra et. al., SIAM, Philadelphia, 1979. -

    - -

    - Where you want to append a number of new rows consider using the update - routine in section 3.20. -

    - -

    - See the function summary list for the older - depreciated function names. -

    - -

    3.33 Accessing C functions

    - -

    - next - skip - - up - start -

    - -

    - You have a C function that uses one and two dimensional arrays as - vectors and matrices. You want to access it from Newmat. -

    - -

    - One dimensional arrays are easy. Set up a ColumnVector, - RowVector or DiagonalMatrix with the correct dimension and - where the function has a double* argument enter - X.data() where X denotes the ColumnVector, - RowVector or DiagonalMatrix. (I am assuming you have left - Real being typedefed as a double). If you have a - const double* argument use X.const_data(). -

    - -

    - You can't do this with two dimensional arrays where you have a - double** argument. Newmat includes classes - RealStarStar and ConstRealStarStar for this situation. To - access a Matrix A from a function - c_function(double** a) use either -

    - -
       c_function(RealStarStar(A));
    -

    or

    -
    -   RealStarStar a(A);
    +

    update_Cholesky carries out the modification of U corresponding to appending +an extra row x to X.

    + + +

    downdate_Cholesky carries out the modification corresponding +to removing a row x from X. A ProgramException exception is +thrown if the modification fails.

    + + +

    right_circular_update_Cholesky supposes that columns j,j+1,...k of X are +replaced by columns k,j,j+1,...k-1.

    + + +

    left_circular_update_Cholesky supposes that columns j,j+1,...k of X are replaced +by columns j+1,...k,j.

    + + +

    These functions are based on a contribution from Nick Bennett of +Schlumberger-Doll Research. See also the LINPACK User's Guide, Chapter 10, +Dongarra et. al., SIAM, Philadelphia, 1979.

    + + +

    Where you want to append a number of new rows consider using the update +routine in section 3.20.

    + + +

    See the function summary list for the older +depreciated function names.

    + + +

    3.33 Accessing C functions

    + + +

    next - skip - +up - start

    + + +

    You have a C function that uses one and two dimensional arrays as +vectors and matrices. You want to access it from Newmat.

    + + +

    One dimensional arrays are easy. Set up a ColumnVector, RowVector +or DiagonalMatrix with the correct dimension and where the function has a +double* argument enter X.data() where X denotes the +ColumnVector, RowVector or DiagonalMatrix. (I am assuming you +have left Real being typedefed as a double). If you have a +const double* argument use X.const_data().

    + + +

    You can't do this with two dimensional arrays where you have a double** +argument. Newmat includes classes RealStarStar and ConstRealStarStar for this situation. +To access a Matrix A from a function c_function(double** a) +use either

    + + +
       c_function(RealStarStar(A));
    +

    or

    +
       RealStarStar a(A);
        c_function(a);
    -

    - If the argument is const double** use ConstRealStarStar. -

    - -

    - The Matrix A must be correctly dimensioned and must not be - resized or set equal to another matrix between setting up the - RealStarStar object and its use in the function. Also the following - construction will not work -

    - -
    -   double** a = RealStarStar(A);      // wrong
    +

    If the argument is const double** use ConstRealStarStar.

    + + +

    The Matrix A must be correctly dimensioned and must not be +resized or set equal to another matrix between setting up the RealStarStar +object and its use in the function. Also the following construction will not +work

    + + +
       double** a = RealStarStar(A);      // wrong
        c_function(a);
    -

    - since the RealStarStar structure will have been destroyed before - you get to the second line. -

    - -

    3.34 Simple integer array class

    - -

    - next - skip - - up - start -

    - -

    - This is primarily for use within Newmat. You can set up a simple - array of integers with the SimpleIntArray class. Here are the - descriptions of the constructors and functions. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - SimpleIntArray A; - - Constructs int array of length zero -
    - SimpleIntArray A(n); - - Constructs int array of length n - individual elements are - not initialised -
    A = i; - sets values to i where i is an int variable -
    A = B; - sets values to those of B where B is a SimpleIntArray, - change size if necessary. -
    n = A.size(); - return the length of A -
    A.resize(n); - change the length of A, don't keep values -
    - A.resize_keep(n); - - change the length of A, do keep values; if length is being - increased set new elements to zero. -
    int x = A[i]; - element access; i runs from 0 to n-1 -
    - int* d = A.data(); - - get beginning of data array -
    - const int* d = A.data(); - - get beginning of data array as const int* if A is const -
    - const int* d = A.const_data(); - - get beginning of data array as const int* -
    A.cleanup()resize to zero length
    - -   -

    3.35 Extend orthonormal set of columns

    -

    - next - skip - - up - start -

    -

    - Suppose a Matrix A's first n columns are - orthonormal so that A.Columns(1,n).t() * A.Columns(1,n) is the - identity matrix. Suppose we want to fill out the remaining columns of - A to make them orthonormal so that A.t() * A is the - identity matrix. Then use the function -

    -
       extend_orthonormal(A, n);
    -

    - Matrix A is then replaced by the matrix with the - additional columns. -

    -

    - Use this function to extend U from the QRZ or - SVD decompositions to form a square (orthogonal) - matrix. -

    -

    Notes:

    -
      -
    • the first n columns of A must be orthonormal
    • -
    • - n must be less or equal to the number of columns of A -
    • -
    • - the number of columns of A must be less than or equal to the - number of rows of A -
    • -
    - -

    3.36 Miscellaneous functions

    -

    - next - skip - - up - start -

    -

    - The section includes some miscellaneous functions I have needed for my - work. So far there are only the Helmert transforms. -

    -

    Helmert transforms

    -

    - This section refers to the Helmert transform used in some statistical - packages for extracting contrasts. It is different from the Helmert - transform used in geodesy. The version of the transform I am going to use - is based on the n x n matrix -

    -
    -| 1/sqrt(1*2)                       | * | -1  1              |
    +

    since the RealStarStar structure will have been destroyed before you +get to the second line.

    + + +

    3.34 Simple integer array class

    + + +

    next - skip - +up - start

    + + +

    This is primarily for use within Newmat. You can set up a simple array +of integers with the SimpleIntArray class. Here are the descriptions of +the constructors and functions.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    SimpleIntArray A; Constructs int array of length zero
    SimpleIntArray A(n); Constructs int array of length n - +individual elements are not initialised
    A = i; sets values to i where i is an int +variable
    A = B; sets values to those of B where +B is +a SimpleIntArray, change size if necessary.
    n = A.size(); return the length of A
    A.resize(n); change the length of A, don't keep +values
    A.resize_keep(n); change the length of A, do keep +values; if length is being increased set new elements to zero.
    int x = A[i]; element access; i runs from 0 to +n-1
    int* d = A.data(); get beginning of data array
    const int* d = A.data(); get beginning of data array as const +int* if A is const
    const int* d = A.const_data(); get beginning of data array as const +int*
    A.cleanup() resize to zero length
    + + 

    3.35 + +Extend orthonormal set of columns

    +

    next - skip - +up - start

    +

    Suppose a Matrix A's first n columns are orthonormal so that +A.Columns(1,n).t() * A.Columns(1,n) is the identity matrix. Suppose +we want to fill out the remaining columns of A to make them orthonormal so +that A.t() * A is the identity matrix. Then use the function

    +
       extend_orthonormal(A, n);
    +

    Matrix A is then replaced by the matrix with the additional +columns.

    +

    Use this function to extend U from the QRZ or +SVD decompositions to form a square (orthogonal) matrix.

    +

    Notes:

    +
      +
    • the first n columns of A must be orthonormal
    • +
    • n must be less or equal to the number of columns of A
    • +
    • the number of columns of A must be less than or equal to the number of + rows of A
    • +
    + +

    3.36 Miscellaneous functions

    +

    next - skip - +up - start

    +

    The section includes some miscellaneous functions I have needed for my work. So +far there are only the Helmert transforms.

    +

    Helmert transforms

    +

    This section refers to the Helmert transform used in some statistical +packages for extracting contrasts. It is different from the Helmert transform +used in geodesy. The version of the transform I am going to use is based on the +n x n matrix

    +
    | 1/sqrt(1*2)                       | * | -1  1              |
     |     1/sqrt(2*3)                   |   | -1 -1  2           |
     |          1/sqrt(3*4)              |   | -1 -1 -1  3        |
     |               ...                 |   |  ...               |
     |                  1/(sqrt(n-1)*n)  |   | -1 -1  ...  -1 n-1 |
     |                         1/sqrt(n) |   |  1  1  ...       1 | 
    -

    - You can interpret multiplying a column vector by this matrix as follows. - Form the k-th element in the resulting column vector by taking the - k+1-th element and subtracting the average of the previous - k elements. Then multiply by sqrt((k+1)/k) so we get - an orthonormal transform. The last element is just the sum divided by - sqrt(n). Usually one will omit the last element since we want just - the contrasts. -

    -

    - Here are the functions. X and Y are ColumnVectors, - A and B are matrices, b is a boolean, - j, n are integers, x is a Real. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - A = Helmert(n, b);
    - A = Helmert(n); -
    - Return the n x n Helmert matrix or the (n-1) x - n version with the last row omitted. -
    - Y = Helmert(X,b);
    - Y = Helmert(X); -
    - Multiply by the Helmert matrix. -
    - Y = Helmert(n,j,b);
    - Y = Helmert(n,j); -
    - Return j-th column of Helmert matrix as a ColumnVector. -
    - X = Helmert_transpose(Y,b);
    - X = Helmert_transpose(Y); -
    - Multiply by the transpose of the Helmert matrix. -
    - x = Helmert_transpose(Y,j,b);
    - x = Helmert_transpose(Y,j); -
    - Multiply by the transpose of the Helmert matrix, return just the - j-th element. -
    - B = Helmert(A,b);
    - B = Helmert(A); -
    - Multiply a Matrix by the Helmert matrix. -
    - A = Helmert_transpose(B,b);
    - A = Helmert_transpose(B); -
    - Multiply a Matrix by the transpose of the Helmert matrix. -
    - -

    - If b is true the full Helmert matrix is used, if it is false or - omitted the n-th row (or n-column of the transpose) is - omitted. -

    -

     

    - -

    4. Error messages

    -

    - next - skip - - up - start -

    -

    - Most error messages are self-explanatory. The message gives the size of - the matrices involved. Matrix types are referred to by the following - codes: -

    -
    -   Matrix or vector                   Rect
    +

    You can interpret multiplying a column vector by this matrix as follows. Form +the k-th element in the resulting column vector by taking the k+1-th +element and subtracting the average of the previous k elements. Then +multiply by sqrt((k+1)/k) so we get an orthonormal transform. The +last element is just the sum divided by sqrt(n). Usually one will omit +the last element since we want just the contrasts.

    +

    Here are the functions. X and Y are ColumnVectors, A +and B are matrices, b is a boolean, j, n are +integers, x is a Real.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    A = Helmert(n, b);
    +A = Helmert(n);
    Return the n x n +Helmert matrix or the (n-1) x n version with the last row omitted.
    Y = Helmert(X,b);
    +Y = Helmert(X);
    Multiply by the Helmert matrix.
    Y = Helmert(n,j,b);
    +Y = Helmert(n,j);
    Return j-th column of Helmert +matrix as a ColumnVector.
    X = Helmert_transpose(Y,b);
    +X = Helmert_transpose(Y);
    Multiply by the transpose of the +Helmert matrix.
    x = Helmert_transpose(Y,j,b);
    +x = Helmert_transpose(Y,j);
    Multiply by the transpose of the +Helmert matrix, return just the j-th element.
    B = Helmert(A,b);
    +B = Helmert(A);
    Multiply a Matrix by the Helmert +matrix.
    A = Helmert_transpose(B,b);
    +A = Helmert_transpose(B);
    Multiply a Matrix by the transpose of +the Helmert matrix.
    + +

    If b is true the full Helmert matrix is used, if it is false or +omitted the n-th row (or n-column of the transpose) is omitted.

    +

     

    + +

    4. Error messages

    +

    next - skip - +up - start

    +

    Most error messages are self-explanatory. The message gives the size of the +matrices involved. Matrix types are referred to by the following codes:

    +
       Matrix or vector                   Rect
        Symmetric matrix                   Sym
        Band matrix                        Band
        Symmetric band matrix              SmBnd
    @@ -4261,727 +3118,540 @@ 

    4. Error messages

    Diagonal matrix Diag Crout matrix (LU matrix) Crout Band LU matrix BndLU -
    - -

    Other codes should not occur.

    -

    - See the section on exceptions for more details on - the structure of the exception classes. -

    -

    - I have defined a class Tracer that is intended to help locate the place - where an error has occurred. At the beginning of a function I suggest you - include a statement like -

    -
    -   Tracer tr("name");
    -
    - -

    - where name is the name of the function. This name will be printed as part - of the error message, if an exception occurs in that function, or in a - function called from that function. You can change the name as you proceed - through a function with the ReName function -

    -
    -   tr.ReName("new name");
    -
    - -

    if, for example, you want to track progress through the function.

    -

    5. Notes on the design of the library

    -

    - next - skip - - up - start -

    - - - - - -
    - 5.1 Safety, usability, efficiency
    - 5.2 Matrix vs array library
    - 5.3 Design questions
    - 5.4 Data storage
    - 5.5 Memory management - 1
    - 5.6 Memory management - 2
    - 5.7 Evaluation of expressions -
    - 5.8 Explosion in the number of operations
    - 5.9 Destruction of temporaries
    - 5.10 A calculus of matrix types
    - 5.11 Pointer arithmetic
    - 5.12 Error handling
    - 5.13 Sparse matrices
    - 5.14 Complex matrices -
    -

    - I describe some of the ideas behind this package, some of the decisions - that I needed to make and give some details about the way it works. You - don't need to read this part of the documentation in order to use the - package. -

    -

    - It isn't obvious what is the best way of going about structuring a matrix - package. I don't think you can figure this out with - thought experiments. Different people have to try out different - approaches. And someone else may have to figure out which is best. Or, - more likely, the ultimate packages will lift some ideas from each of a - variety of trial packages. So, I don't claim my package is an - ultimate package, but simply a trial of a number of ideas. The - following pages give some background on these ideas. -

    -

    5.1 Safety, usability, efficiency

    -

    - next - skip - - up - start -

    -

    Some general comments

    -

    - A library like newmat needs to balance safety, - usability and efficiency. -

    -

    - By safety, I mean getting the right answer, and not causing crashes - or damage to the computer system. -

    -

    - By usability, I mean being easy to learn and use, including not - being too complicated, being intuitive, saving the users' time, being nice - to use. -

    -

    - Efficiency means minimising the use of computer memory and time. -

    -

    - In the early days of computers the emphasis was on efficiency. But - computer power gets cheaper and cheaper, halving in price every 18 months. - On the other hand the unaided human brain is probably not a lot better - than it was 100,000 years ago! So we should expect the balance to shift to - put more emphasis on safety and usability and a little less on efficiency. - So I don't mind if my programs are a little less efficient than programs - written in pure C (or Fortran) if I gain substantially in safety and - usability. But I would mind if they were a lot less efficient. -

    -

    Type of use

    -

    - Second reason for putting extra emphasis on safety and usability is the - way I and, I suspect, most other users actually use newmat. Most - completed programs are used only a few times. Some result is required for - a client, paper or thesis. The program is developed and tested, the result - is obtained, and the program archived. Of course bits of the program will - be recycled for the next project. But it may be less usual for the same - program to be run over and over again. So the cost, computer time + people - time, is in the development time and often, much less in the actual time - to run the final program. So good use of people time, especially during - development is really important. This means you need highly usable - libraries. -

    -

    - So if you are dealing with matrices, you want the good interface that I - have tried to provide in newmat, and, of course, reliable methods - underneath it. -

    -

    - Of course, efficiency is still important. We often want to run the biggest - problem our computer will handle and often a little bigger. The C++ - language almost lets us have both worlds. We can define a reasonably good - interface, and get good efficiency in the use of the computer. -

    -

    Levels of access

    -

    - We can imagine the black box model of a newmat. Suppose the - inside is hidden but can be accessed by the methods described in the - reference section. Then the interface is reasonably - consistent and intuitive. Matrices can be accessed and manipulated in much - the same way as doubles or ints in regular C. All accesses are checked. It - is most unlikely that an incorrect index will crash the system. In - general, users do not need to use pointers, so one shouldn't get pointers - pointing into space. And, hopefully, you will get simpler code with less - errors. -

    -

    - There are some exceptions to this. In particular, the - C-like subscripts are not checked for validity. - They give faster access but with a lower level of safety. -

    -

    - Then there is the data() function which takes you - to the data array within a matrix. This takes you right inside the - black box. But this is what you have to use if you are writing, for - example, a new matrix factorisation, and require fast access to the data - array. I have tried to write code to simplify access to the interior of a - rectangular matrix, see file newmatrm.cpp, but I don't regard this as very - successful, as yet, and have not included it in the documentation. Ideally - we should have improved versions of this code for each of the major types - of matrix. But, in reality, most of my matrix factorisations are written - in what is basically the C language with very little C++. -

    -

    - So our box is not very black. You have a choice of how far - you penetrate. On the outside you have a good level of safety, but in some - cases efficiency is compromised a little. If you penetrate inside the - box safety is reduced but you can get better efficiency. -

    -

    Some performance data

    -

    - This section looks at the performance on newmat for simple sums, - comparing it with C code and with a simple array program. (This is now - very old data). -

    -

    - The following table lists the time (in seconds) for carrying out the - operations X=A+B;, X=A+B+C;, X=A+B+C+D;, - X=A+B+C+D+E; where X,A,B,C,D,E are of type ColumnVector, - with a variety of programs. I am using Microsoft VC++, version 6 in - console mode under windows 2000 on a PC with a 1 ghz Pentium III and 512 - mbytes of memory. -

    -
        length    iters. newmat      C C-res.  subs.  array
    +
    + +

    Other codes should not occur.

    +

    See the section on exceptions for more details on the +structure of the exception classes.

    +

    I have defined a class Tracer that is intended to help locate the place +where an error has occurred. At the beginning of a function I suggest you +include a statement like

    +
       Tracer tr("name");
    +
    + +

    where name is the name of the function. This name will be printed as part of +the error message, if an exception occurs in that function, or in a function +called from that function. You can change the name as you proceed through a +function with the ReName function

    +
       tr.ReName("new name");
    +
    + +

    if, for example, you want to track progress through the function.

    +

    5. Notes on the design of the +library

    +

    next - skip - +up - start

    + + + + + +
    5.1 +Safety, usability, efficiency
    +5.2 Matrix vs array library
    +5.3 Design questions
    +5.4 Data storage
    +5.5 Memory management - 1
    +5.6 Memory management - 2
    +5.7 Evaluation of expressions
    5.8 Explosion in the number of operations
    +5.9 Destruction of temporaries
    +5.10 A calculus of matrix types
    +5.11 Pointer arithmetic
    +5.12 Error handling
    +5.13 Sparse matrices
    +5.14 Complex matrices
    +

    I describe some of the ideas behind this package, some of the decisions that +I needed to make and give some details about the way it works. You don't need +to read this part of the documentation in order to use the package.

    +

    It isn't obvious what is the best way of going about structuring a matrix +package. I don't think you can figure this out with thought experiments. +Different people have to try out different approaches. And someone else may +have to figure out which is best. Or, more likely, the ultimate packages will +lift some ideas from each of a variety of trial packages. So, I don't claim my +package is an ultimate package, but simply a trial of a number of ideas. +The following pages give some background on these ideas.

    +

    5.1 Safety, usability, +efficiency

    +

    next - skip - +up - start

    +

    Some general comments

    +

    A library like newmat needs to balance safety, +usability and efficiency.

    +

    By safety, I mean getting the right answer, and not causing crashes +or damage to the computer system.

    +

    By usability, I mean being easy to learn and use, including not being +too complicated, being intuitive, saving the users' time, being nice to use. +

    +

    Efficiency means minimising the use of computer memory and time.

    +

    In the early days of computers the emphasis was on efficiency. But computer +power gets cheaper and cheaper, halving in price every 18 months. On the other +hand the unaided human brain is probably not a lot better than it was 100,000 +years ago! So we should expect the balance to shift to put more emphasis on +safety and usability and a little less on efficiency. So I don't mind if my +programs are a little less efficient than programs written in pure C (or +Fortran) if I gain substantially in safety and usability. But I would mind if +they were a lot less efficient.

    +

    Type of use

    +

    Second reason for putting extra emphasis on safety and usability is the way +I and, I suspect, most other users actually use newmat. Most completed +programs are used only a few times. Some result is required for a client, paper +or thesis. The program is developed and tested, the result is obtained, and the +program archived. Of course bits of the program will be recycled for the next +project. But it may be less usual for the same program to be run over and over +again. So the cost, computer time + people time, is in the development time and +often, much less in the actual time to run the final program. So good use of +people time, especially during development is really important. This means you +need highly usable libraries.

    +

    So if you are dealing with matrices, you want the good interface that I have +tried to provide in newmat, and, of course, reliable methods underneath +it.

    +

    Of course, efficiency is still important. We often want to run the biggest +problem our computer will handle and often a little bigger. The C++ language +almost lets us have both worlds. We can define a reasonably good interface, and +get good efficiency in the use of the computer.

    +

    Levels of access

    +

    We can imagine the black box model of a newmat. Suppose the +inside is hidden but can be accessed by the methods described in the +reference section. Then the interface is reasonably +consistent and intuitive. Matrices can be accessed and manipulated in much the +same way as doubles or ints in regular C. All accesses are checked. It is most +unlikely that an incorrect index will crash the system. In general, users do +not need to use pointers, so one shouldn't get pointers pointing into space. +And, hopefully, you will get simpler code with less errors.

    +

    There are some exceptions to this. In particular, the C-like subscripts are not checked for validity. They give +faster access but with a lower level of safety.

    +

    Then there is the data() function which takes you to +the data array within a matrix. This takes you right inside the black +box. But this is what you have to use if you are writing, for example, a +new matrix factorisation, and require fast access to the data array. I have +tried to write code to simplify access to the interior of a rectangular matrix, +see file newmatrm.cpp, but I don't regard this as very successful, as yet, and +have not included it in the documentation. Ideally we should have improved +versions of this code for each of the major types of matrix. But, in reality, +most of my matrix factorisations are written in what is basically the C +language with very little C++.

    +

    So our box is not very black. You have a choice of how far you +penetrate. On the outside you have a good level of safety, but in some cases +efficiency is compromised a little. If you penetrate inside the box +safety is reduced but you can get better efficiency.

    +

    Some performance data

    +

    This section looks at the performance on newmat for simple sums, +comparing it with C code and with a simple array program. +(This is now very old data).

    +

    The following table lists the time (in seconds) for carrying out the +operations X=A+B;, X=A+B+C;, X=A+B+C+D;, X=A+B+C+D+E; where +X,A,B,C,D,E are of type ColumnVector, with a variety of programs. I am +using Microsoft VC++, version 6 in console mode under windows 2000 on a PC with +a 1 ghz Pentium III and 512 mbytes of memory.

    +
        length    iters. newmat      C C-res.  subs.  array
     X = A + B
    -         2   5000000   27.8    0.3    8.8    1.9    9.5
    -        20    500000    3.0    0.3    1.1    1.9    1.2
    -       200     50000    0.5    0.3    0.4    1.9    0.3
    -      2000      5000    0.4    0.3    0.4    2.0    1.0
    -     20000       500    4.5    4.5    4.5    6.7    4.4
    -    200000        50    5.2    4.7    5.5    5.8    5.2
    +         2   5000000   27.8    0.3    8.8    1.9    9.5 
    +        20    500000    3.0    0.3    1.1    1.9    1.2 
    +       200     50000    0.5    0.3    0.4    1.9    0.3 
    +      2000      5000    0.4    0.3    0.4    2.0    1.0 
    +     20000       500    4.5    4.5    4.5    6.7    4.4 
    +    200000        50    5.2    4.7    5.5    5.8    5.2 
     
     X = A + B + C
    -         2   5000000   36.6    0.4    8.9    2.5   12.2
    -        20    500000    4.0    0.4    1.2    2.5    1.6
    -       200     50000    0.8    0.3    0.5    2.5    0.5
    -      2000      5000    3.6    4.4    4.6    9.0    4.4
    -     20000       500    6.8    5.4    5.4    9.6    6.8
    -    200000        50    8.6    6.0    6.7    7.1    8.6
    +         2   5000000   36.6    0.4    8.9    2.5   12.2 
    +        20    500000    4.0    0.4    1.2    2.5    1.6 
    +       200     50000    0.8    0.3    0.5    2.5    0.5 
    +      2000      5000    3.6    4.4    4.6    9.0    4.4 
    +     20000       500    6.8    5.4    5.4    9.6    6.8 
    +    200000        50    8.6    6.0    6.7    7.1    8.6 
     
     X = A + B + C + D
    -         2   5000000   44.0    0.7    9.3    3.1   14.6
    -        20    500000    4.9    0.6    1.5    3.1    1.9
    -       200     50000    1.0    0.6    0.8    3.2    0.8
    -      2000      5000    5.6    6.6    6.8   11.5    5.9
    -     20000       500    9.0    6.7    6.8   11.0    8.5
    -    200000        50   11.9    7.1    7.9    9.5   12.0
    +         2   5000000   44.0    0.7    9.3    3.1   14.6 
    +        20    500000    4.9    0.6    1.5    3.1    1.9 
    +       200     50000    1.0    0.6    0.8    3.2    0.8 
    +      2000      5000    5.6    6.6    6.8   11.5    5.9 
    +     20000       500    9.0    6.7    6.8   11.0    8.5 
    +    200000        50   11.9    7.1    7.9    9.5   12.0 
     
     X = A + B + C + D + E
    -         2   5000000   50.6    1.0    9.5    3.8   17.1
    -        20    500000    5.7    0.8    1.7    3.9    2.4
    -       200     50000    1.3    0.9    1.0    3.9    1.0
    -      2000      5000    7.0    8.3    8.2   13.8    7.1
    -     20000       500   11.5    8.1    8.4   13.2   11.0
    -    200000        50   15.2    8.7    9.5   12.4   15.4
    +         2   5000000   50.6    1.0    9.5    3.8   17.1 
    +        20    500000    5.7    0.8    1.7    3.9    2.4 
    +       200     50000    1.3    0.9    1.0    3.9    1.0 
    +      2000      5000    7.0    8.3    8.2   13.8    7.1 
    +     20000       500   11.5    8.1    8.4   13.2   11.0 
    +    200000        50   15.2    8.7    9.5   12.4   15.4 
     
    -

    - I have graphed the results and - included rather more array lengths. -

    - -

    - The first column gives the lengths of the arrays, the second the number of - iterations and the remaining columns the total time required in seconds. - If the only thing that consumed time was the double precision addition - then the numbers within each block of the table would be the same. The - summation is repeated 5 times within each loop, for example: -

    -
    -   for (i=1; i<=m; ++i)
    +

    I have graphed the results +and included rather more array lengths.

    + +

    The first column gives the lengths of the arrays, the second the number of +iterations and the remaining columns the total time required in seconds. If the +only thing that consumed time was the double precision addition then the +numbers within each block of the table would be the same. The summation is +repeated 5 times within each loop, for example:

    +
       for (i=1; i<=m; ++i)
        {
           X1 = A1+B1+C1; X2 = A2+B2+C2; X3 = A3+B3+C3;
           X4 = A4+B4+C4; X5 = A5+B5+C5;
        }
    -

    - The column labelled newmat is using the standard newmat add. - The column labelled C uses the usual C method: - while (j1--) *x1++ = *a1++ + *b1++; . The following column also - includes an X.resize() in the outer loop to correspond to the - reassignment of memory that newmat would do. In the next column the - calculation is using the usual C style for loop and accessing the - elements using newmat subscripts such as A(i). The final - column is the time taken by a simple array package. This uses an - alternative method for avoiding temporaries and unnecessary copies that - does not involve runtime tests. It does its sums in blocks of 4 and copies - in blocks of 8 in the same way that newmat does. -

    -

    Here are my conclusions.

    -
      -
    • - Newmat does very badly for length 2 and doesn't do well for - length 20. There is a lot of code in newmat for determining which - sum algorithm to use and it is not surprising that this impacts on - performance for small lengths. However the array program is also - having difficulty with length 2 so it is unlikely that the problem could - be completely eliminated. -
    • -
    • - For arrays of length 2000 or longer newmat is doing about as well - as C and slightly better than C with resize in the X=A+B table. - For the other two tables it tends to be slower, but not dramatically so. -
    • -
    • - It is really important for fast processing with the Pentium III to stay - within the Pentium cache. -
    • -
    • - Addition using the newmat subscripts, while considerably slower - than the others, is still surprisingly good for the longer arrays. -
    • -
    • - The array program and newmat are similar for lengths 2000 - or higher (the longer times for the array program for the longest arrays - shown on the graph are probably a quirk of the timing program). -
    • -
    -

    - In summary: for the situation considered here, newmat is doing very - well for large ColumnVectors, even for sums with several terms, but not so - well for shorter ColumnVectors. -

    -

    5.2 Matrix vs array library

    -

    - next - skip - - up - start -

    -

    - The newmat library is for the manipulation of matrices, including - the standard operations such as multiplication as understood by numerical - analysts, engineers and mathematicians. -

    -

    - A matrix is a two dimensional array of numbers. However, very special - operations such as matrix multiplication are defined specifically for - matrices. This means that a matrix library, as I understand the - term, is different from a general array library. Here are some - contrasting properties. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    FeatureMatrix libraryArray library
    Expressions - Matrix expressions; * means matrix multiply; inverse - function - - Arithmetic operations, if supported, mean elementwise combination of - arrays -
    Element accessAccess to the elements of a matrix - High speed access to elements directly and perhaps with iterators -
    Elementary functionsFor example: determinant, traceMatrix multiplication as a function
    Advanced functionsFor example: eigenvalue analysis 
    Element typesReal and possibly complexWide range - real, integer, string etc
    TypesRectangular, symmetric, diagonal, etc - One, two and three dimensional arrays, at least -
    -

    - Both types of library need to support access to sub-matrices or - sub-arrays, have good efficiency and storage management, and graceful exit - for errors. In both cases, we probably need two versions, one optimised - for large matrices or arrays and one for small matrices or arrays. -

    -

    - It may be possible to amalgamate the two sets of requirements to some - extent. However newmat is definitely oriented towards the matrix - library set. -

    -

    5.3 Design questions

    -

    - next - skip - - up - start -

    -

    - Even within the bounds set by the requirements of a matrix library there - is a substantial opportunity for variation between what different matrix - packages might provide. It is not possible to build a matrix package that - will meet everyone's requirements. In many cases if you put in one - facility, you impose overheads on everyone using the package. This both in - storage required for the program and in efficiency. Likewise a package - that is optimised towards handling large matrices is likely to become less - efficient for very small matrices where the administration time for the - matrix may become significant compared with the time to carry out the - operations. It is better to provide a variety of packages (hopefully - compatible) so that most users can find one that meets their requirements. - This package is intended to be one of these packages; but not all of them. -

    -

    - Since my background is in statistical methods, this package is oriented - towards the kinds things you need for statistical analyses. -

    -

    Now looking at some specific questions.

    -

    What size of matrices?

    -

    - A matrix library may target small matrices (say 3 x 3), or medium sized - matrices, or very large matrices. -

    -

    - A library targeting very small matrices will seek to minimise - administration. A library for medium sized or very large matrices can - spend more time on administration in order to conserve space or optimise - the evaluation of expressions. A library for very large matrices will need - to pay special attention to storage and numerical properties. This library - is designed for medium sized matrices. This means it is worth introducing - some optimisations, but I don't have to worry about setting up some form - of virtual memory. -

    -

    Which matrix types?

    -

    - As well as the usual rectangular matrices, matrices occurring repeatedly - in numerical calculations are upper and lower triangular matrices, - symmetric matrices and diagonal matrices. This is particularly the case in - calculations involving least squares and eigenvalue calculations. So as a - first stage these were the types I decided to include. -

    -

    - It is also necessary to have types row vector and column vector. In a - matrix package, in contrast to an array package, it is - necessary to have both these types since they behave differently in matrix - expressions. The vector types can be derived for the rectangular matrix - type, so having them does not greatly increase the complexity of the - package. -

    -

    - The problem with having several matrix types is the number of versions of - the binary operators one needs. If one has 5 distinct matrix types then a - simple library will need 25 versions of each of the binary operators. In - fact, we can evade this problem, but at the cost of some complexity. -

    -

    What element types?

    -

    - Ideally we would allow element types double, float, complex and int, at - least. It might be reasonably easy, using templates or equivalent, to - provide a library which could handle a variety of element types. However, - as soon as one starts implementing the binary operators between matrices - with different element types, again one gets an explosion in the number of - operations one needs to consider. At the present time the compilers I deal - with are not up to handling this problem with templates. (Of course, when - I started writing newmat there were no templates). But even when - the compilers do meet the specifications of the draft standard, writing a - matrix package that allows for a variety of element types using the - template mechanism is going to be very difficult. I am inclined to use - templates in an array library but not in a matrix library. -

    -

    - Hence I decided to implement only one element type. But the user can - decide whether this is float or double. The package assumes elements are - of type Real. The user typedefs Real to float or double. -

    -

    - It might also be worth including symmetric and triangular matrices with - extra precision elements (double or long double) to be used for storage - only and with a minimum of operations defined. These would be used for - accumulating the results of sums of squares and product matrices or - multi-stage QR decompositions. -

    -

    Allow matrix expressions

    -

    - I want to be able to write matrix expressions the way I would on paper. So - if I want to multiply two matrices and then add the transpose of a third - one I can write something like X = A * B + C.t();. I want this - expression to be evaluated with close to the same efficiency as a - hand-coded version. This is not so much of a problem with expressions - including a multiply since the multiply will dominate the time. However, - it is not so easy to achieve with expressions with just + and - -. -

    -

    - A second requirement is that temporary matrices generated during the - evaluation of an expression are destroyed as quickly as possible. -

    -

    - A desirable feature is that a certain amount of intelligence be - displayed in the evaluation of an expression. For example, in the - expression X = A.i() * B; where i() denotes inverse, it - would be desirable if the inverse wasn't explicitly calculated. -

    -

    Naming convention

    -

    - How are classes and public member functions to be named? As a general rule - I have spelt identifiers out in full with individual words being - capitalised. For example UpperTriangularMatrix. If you don't like - this you can #define or typedef shorter names. This convention means you - can select an abbreviation scheme that makes sense to you. -

    -

    - Exceptions to the general rule are the functions for transpose and - inverse. To make matrix expressions more like the corresponding - mathematical formulae, I have used the single letter abbreviations, - t() and i(). -

    -

    - I am now switching to using lowercase for functions with individual words - separated by "_". This is following the convention in - the standard library and I think it looks neater. Class names will remain - with individual words being capitalised. -

    -

    Row and column index ranges

    -

    - In mathematical work matrix subscripts usually start at one. In C, array - subscripts start at zero. In Fortran, they start at one. Possibilities for - this package were to make them start at 0 or 1 or be arbitrary. -

    -

    - Alternatively one could specify an index set for indexing the rows - and columns of a matrix. One would be able to add or multiply matrices - only if the appropriate row and column index sets were identical. -

    -

    - In fact, I adopted the simpler convention of making the rows and columns - of a matrix be indexed by an integer starting at one, following the - traditional convention. In an earlier version of the package I had them - starting at zero, but even I was getting mixed up when trying to use this - earlier package. So I reverted to the more usual notation and started at - 1. -

    -

    Element access - method and checking

    -

    - We want to be able to use the notation A(i,j) to specify the - (i,j)-th element of a matrix. This is the way mathematicians - expect to address the elements of matrices. I consider the notation - A[i][j] totally alien. However I include this as an option to - help people converting from C. -

    -

    - There are two ways of working out the address of A(i,j). One is - using a dope vector which contains the first address of each row. - Alternatively you can calculate the address using the formula appropriate - for the structure of A. I use this second approach. It is - probably slower, but saves worrying about an extra bit of storage. -

    -

    - The other question is whether to check for i and j being - in range. I do carry out this check following years of experience with - both systems that do and systems that don't do this check. I would hope - that the routines I supply with this package will reduce your need to - access elements of matrices so speed of access is not a high priority. -

    -

    Use iterators

    -

    - Iterators are an alternative way of providing fast access to the elements - of an array or matrix when they are to be accessed sequentially. They need - to be customised for each type of matrix. I have not implemented iterators - in this package, although some iterator like functions are used internally - for some row and column functions. -

    -

    5.4 Data storage

    -

    - next - skip - - up - start -

    -

    The stack and heap

    -

    - To understand how newmat stores matrices you need to know a little - bit about the heap and stack. -

    -

    - The data values of variables or objects in a C++ program are stored in - either of two sections of memory called the stack and the - heap. Sometimes there is more than one heap to cater for - different sized variables. -

    -

    If you declare an automatic variable

    -
       int x;
    -

    - then the value of x is stored on the stack. As you declare - more variables the stack gets bigger. When you exit a block (i.e a section - of code delimited by curly brackets {...}) the memory used by the - automatic variables declared in the block is released and the - stack shrinks. -

    -

    When you declare a variable with new, for example,

    -
       int* y = new int;
    -

    - the pointer y is stored on the stack but the value it is - pointing to is stored on the heap. Memory on the heap is not - released until the program explicitly does this with a - delete statement -

    -
       delete y;
    -

    or the program exits.

    -

    - On the stack, variables and objects are is always added to the end - of the stack and are removed in the reverse order to that in which - they are added - that is the last on will be the first off. This is not - the case with the heap, where the variables and objects can be - removed in any order. So one can get alternating pieces of used and unused - memory. When a new variable or object is declared on the heap the - system needs to search for piece of unused memory large enough to hold it. - This means that storing on the heap will usually be a slower - process than storing on the stack. There is also likely to be waste - space on the heap because of gaps between the used blocks of memory - that are too small for the next object you want to store on the - heap. There is also the possibility of wasting space if you forget - to remove a variable or object on the heap even though you have - finished using it. However, the stack is usually limited to holding - small objects with size known at compile time. Large objects, objects - whose size you don't know at compile time, and objects that you want to - persist after the end of the block need to be stored on the heap. -

    -

    - In C++, the constructor/destructor system enables one to - build complicated objects such as matrices that behave as automatic - variables stored on the stack, so the programmer doesn't have to - worry about deleting them at the end of the block, but which really - utilise the heap for storing their data. -

    -

    Structure of matrix objects

    -

    - Each matrix object contains the basic information such as the number of - rows and columns, the amount of memory used, a status variable and a - pointer to the data array which is on the heap. So if you declare a matrix -

    -
       Matrix A(1000,1000);
    -

    - there is an small amount of memory used on the stack for storing the - numbers of rows and columns, the amount of  memory used, the status - variable and the pointer together with 1,000,000 Real locations - stored on the heap. When you exit the block in which A is declared, - the heap memory used by A is automatically returned to the system, - as well as the memory used on the stack. -

    -

    Of course, if you use new to declare a matrix

    -
       Matrix* B = new Matrix(1000,1000);
    -

    - both the information about the size and the actual data are stored on heap - and not deleted until the program exits or you do an explicit delete: -

    -
       delete B;
    -

    - If you carry out an assignment with = or << or do - a resize() the data array currently associated with a matrix is - destroyed and a new array generated. For example -

    -
    -   Matrix A(1000,1000);
    +

    The column labelled newmat is using the standard newmat add. The column labelled C uses the usual C method: while +(j1--) *x1++ = *a1++ + *b1++; . The following column also includes an +X.resize() in the outer loop to correspond to the reassignment of +memory that newmat would do. In the next column the calculation is using +the usual C style for loop +and accessing the elements using newmat subscripts such as +A(i). The final column is the time taken by a +simple array package. This uses an alternative method for avoiding temporaries +and unnecessary copies that does not involve runtime tests. It does its sums in blocks of 4 and copies in blocks of +8 in the same way that newmat does.

    +

    Here are my conclusions.

    +
      +
    • Newmat does very badly for length 2 and doesn't do well for +length 20. There is a lot of code in newmat for +determining which sum algorithm to use and it is not surprising that this +impacts on performance for small lengths. +However the array program is also having difficulty with length 2 so it +is unlikely that the problem could be completely eliminated.
    • +
    • For arrays of length 2000 or longer newmat is doing about as well as +C and slightly better than C with resize in the X=A+B table. For the +other two tables it tends to be slower, but not dramatically so.
    • +
    • It is really important for fast processing with the Pentium III to stay +within the Pentium cache.
    • +
    • Addition using the newmat subscripts, while considerably slower than +the others, is still surprisingly good for the longer arrays.
    • +
    • The array program and newmat are similar for +lengths 2000 or higher (the longer times for the array program for the longest +arrays shown on the graph are probably a quirk of the timing program).
    • +
    +

    In summary: for the situation considered here, newmat is doing very +well for large ColumnVectors, even for sums with several terms, but not so well +for shorter ColumnVectors.

    +

    5.2 Matrix vs array +library

    +

    next - skip - +up - start

    +

    The newmat library is for the manipulation of matrices, including the +standard operations such as multiplication as understood by numerical analysts, +engineers and mathematicians.

    +

    A matrix is a two dimensional array of numbers. However, very special +operations such as matrix multiplication are defined specifically for matrices. +This means that a matrix library, as I understand the term, is different +from a general array library. Here are some contrasting properties.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    FeatureMatrix +libraryArray +library
    ExpressionsMatrix expressions; +* means matrix multiply; inverse functionArithmetic operations, if +supported, mean elementwise combination of arrays
    Element accessAccess to the elements of a +matrixHigh speed access to elements +directly and perhaps with iterators
    Elementary functionsFor example: determinant, +traceMatrix multiplication as a +function
    Advanced functionsFor example: eigenvalue +analysis 
    Element typesReal and possibly +complexWide range - real, integer, string +etc
    TypesRectangular, symmetric, diagonal, +etcOne, two and three dimensional +arrays, at least
    +

    Both types of library need to support access to sub-matrices or sub-arrays, +have good efficiency and storage management, and graceful exit for errors. In +both cases, we probably need two versions, one optimised for large matrices or +arrays and one for small matrices or arrays.

    +

    It may be possible to amalgamate the two sets of requirements to some +extent. However newmat is definitely oriented towards the matrix library +set.

    +

    5.3 Design questions

    +

    next - skip - +up - start

    +

    Even within the bounds set by the requirements of a matrix library there is +a substantial opportunity for variation between what different matrix packages +might provide. It is not possible to build a matrix package that will meet +everyone's requirements. In many cases if you put in one facility, you impose +overheads on everyone using the package. This both in storage required for the +program and in efficiency. Likewise a package that is optimised towards +handling large matrices is likely to become less efficient for very small +matrices where the administration time for the matrix may become significant +compared with the time to carry out the operations. It is better to provide a +variety of packages (hopefully compatible) so that most users can find one that +meets their requirements. This package is intended to be one of these packages; +but not all of them.

    +

    Since my background is in statistical methods, this package is oriented +towards the kinds things you need for statistical analyses.

    +

    Now looking at some specific questions.

    +

    What size of matrices?

    +

    A matrix library may target small matrices (say 3 x 3), or medium sized +matrices, or very large matrices.

    +

    A library targeting very small matrices will seek to minimise +administration. A library for medium sized or very large matrices can spend +more time on administration in order to conserve space or optimise the +evaluation of expressions. A library for very large matrices will need to pay +special attention to storage and numerical properties. This library is designed +for medium sized matrices. This means it is worth introducing some +optimisations, but I don't have to worry about setting up some form of virtual +memory.

    +

    Which matrix types?

    +

    As well as the usual rectangular matrices, matrices occurring repeatedly in +numerical calculations are upper and lower triangular matrices, symmetric +matrices and diagonal matrices. This is particularly the case in calculations +involving least squares and eigenvalue calculations. So as a first stage these +were the types I decided to include.

    +

    It is also necessary to have types row vector and column vector. In a +matrix package, in contrast to an array package, it is necessary +to have both these types since they behave differently in matrix expressions. +The vector types can be derived for the rectangular matrix type, so having them +does not greatly increase the complexity of the package.

    +

    The problem with having several matrix types is the number of versions of +the binary operators one needs. If one has 5 distinct matrix types then a +simple library will need 25 versions of each of the binary operators. In fact, +we can evade this problem, but at the cost of some complexity.

    +

    What element types?

    +

    Ideally we would allow element types double, float, complex and int, at +least. It might be reasonably easy, using templates or equivalent, to provide a +library which could handle a variety of element types. However, as soon as one +starts implementing the binary operators between matrices with different +element types, again one gets an explosion in the number of operations one +needs to consider. At the present time the compilers I deal with are not up to +handling this problem with templates. (Of course, when I started writing +newmat there were no templates). But even when the compilers do meet the +specifications of the draft standard, writing a matrix package that allows for +a variety of element types using the template mechanism is going to be very +difficult. I am inclined to use templates in an array library but not in +a matrix library.

    +

    Hence I decided to implement only one element type. But the user can decide +whether this is float or double. The package assumes elements are of type Real. +The user typedefs Real to float or double.

    +

    It might also be worth including symmetric and triangular matrices with +extra precision elements (double or long double) to be used for storage only +and with a minimum of operations defined. These would be used for accumulating +the results of sums of squares and product matrices or multi-stage QR +decompositions.

    +

    Allow matrix expressions

    +

    I want to be able to write matrix expressions the way I would on paper. So +if I want to multiply two matrices and then add the transpose of a third one I +can write something like X = A * B + C.t();. I want this expression to +be evaluated with close to the same efficiency as a hand-coded version. This is +not so much of a problem with expressions including a multiply since the +multiply will dominate the time. However, it is not so easy to achieve with +expressions with just + and -.

    +

    A second requirement is that temporary matrices generated during the +evaluation of an expression are destroyed as quickly as possible.

    +

    A desirable feature is that a certain amount of intelligence be +displayed in the evaluation of an expression. For example, in the expression +X = A.i() * B; where i() denotes inverse, it would be +desirable if the inverse wasn't explicitly calculated.

    +

    Naming convention

    +

    How are classes and public member functions to be named? As a general rule I +have spelt identifiers out in full with individual words being capitalised. For +example UpperTriangularMatrix. If you don't like this you can #define or +typedef shorter names. This convention means you can select an abbreviation +scheme that makes sense to you.

    +

    Exceptions to the general rule are the functions for transpose and inverse. +To make matrix expressions more like the corresponding mathematical formulae, I +have used the single letter abbreviations, t() and i().

    +

    I am now switching to using lowercase for functions with individual +words separated by "_". This is following the convention in +the standard library and I think it looks neater. Class names will remain with +individual words being capitalised.

    +

    Row and column index ranges

    +

    In mathematical work matrix subscripts usually start at one. In C, array +subscripts start at zero. In Fortran, they start at one. Possibilities for this +package were to make them start at 0 or 1 or be arbitrary.

    +

    Alternatively one could specify an index set for indexing the rows +and columns of a matrix. One would be able to add or multiply matrices only if +the appropriate row and column index sets were identical.

    +

    In fact, I adopted the simpler convention of making the rows and columns of +a matrix be indexed by an integer starting at one, following the traditional +convention. In an earlier version of the package I had them starting at zero, +but even I was getting mixed up when trying to use this earlier package. So I +reverted to the more usual notation and started at 1.

    +

    Element access - method and checking

    +

    We want to be able to use the notation A(i,j) to specify the +(i,j)-th element of a matrix. This is the way mathematicians expect to +address the elements of matrices. I consider the notation A[i][j] +totally alien. However I include this as an option to help people converting +from C.

    +

    There are two ways of working out the address of A(i,j). One is +using a dope vector which contains the first address of each row. +Alternatively you can calculate the address using the formula appropriate for +the structure of A. I use this second approach. It is probably slower, +but saves worrying about an extra bit of storage.

    +

    The other question is whether to check for i and j being +in range. I do carry out this check following years of experience with both +systems that do and systems that don't do this check. I would hope that the +routines I supply with this package will reduce your need to access elements of +matrices so speed of access is not a high priority.

    +

    Use iterators

    +

    Iterators are an alternative way of providing fast access to the elements of +an array or matrix when they are to be accessed sequentially. They need to be +customised for each type of matrix. I have not implemented iterators in this +package, although some iterator like functions are used internally for some row +and column functions.

    +

    5.4 Data storage

    +

    next - skip - +up - start

    +

    The stack and heap

    +

    To understand how newmat stores matrices you need to know a little bit +about the heap and stack.

    +

    The data values of variables or objects in a C++ program are stored in either +of two sections of memory called the stack and the heap. Sometimes +there is more than one heap to cater for different sized variables.

    +

    If you declare an automatic variable

    +
       int x;
    +

    then the value of x is stored on the stack. As you declare more +variables the stack gets bigger. When you exit a block (i.e a section of code +delimited by curly brackets {...}) the memory used by the automatic +variables declared in the block is released and the stack shrinks.

    +

    When you declare a variable with new, for example,

    +
       int* y = new int;
    +

    the pointer y is stored on the stack but the value it is +pointing to is stored on the heap. Memory on the heap is not +released until the program explicitly does this with a delete statement

    +
       delete y;
    +

    or the program exits.

    +

    On the stack, variables and objects are is always added to the end of +the stack and are removed in the reverse order to that in which they are +added - that is the last on will be the first off. This is not the case with the +heap, where the variables and objects can be removed in any order. So one +can get alternating pieces of used and unused memory. When a new variable or +object is declared on the heap the system needs to search for piece of +unused memory large enough to hold it. This means that storing on the heap +will usually be a slower process than storing on the stack. There is also +likely to be waste space on the heap because of gaps between the used +blocks of memory that are too small for the next object you want to store on the +heap. There is also the possibility of wasting space if you forget to +remove a variable or object on the heap even though you have finished +using it. However, the stack is usually limited to holding small objects +with size known at compile time. Large objects, objects whose size you don't +know at compile time, and objects that you want to persist after the end of the +block need to be stored on the heap.

    +

    In C++, the constructor/destructor system enables one to build +complicated objects such as matrices that behave as automatic variables stored +on the stack, so the programmer doesn't have to worry about deleting them +at the end of the block, but which really utilise the heap for storing +their data.

    +

    Structure of matrix objects

    +

    Each matrix object contains the basic information such as the number of rows +and columns, the amount of memory used, a status variable and a pointer to the data array which is on +the heap. So if you declare a matrix

    +
       Matrix A(1000,1000);
    +

    there is an small amount of memory used on the stack for storing the numbers +of rows and columns, the amount of  memory used, the status variable and +the pointer together with 1,000,000 Real locations stored on the heap. +When you exit the block in which A is declared, the heap memory used by +A is automatically returned to the system, as well as the memory used on +the stack.

    +

    Of course, if you use new to declare a matrix

    +
       Matrix* B = new Matrix(1000,1000);
    +

    both the information about the size and the actual data are stored on heap +and not deleted until the program exits or you do an explicit delete:

    +
       delete B;
    +

    If you carry out an assignment with = or << or do a +resize() the data array currently associated with a matrix is destroyed and +a new array generated. For example

    +
       Matrix A(1000,1000);
        Matrix B(50, 50);
        ... put some values in B
        A = B;
    -

    - At the last step the heap memory associated with A is returned to - the system and a new block of heap memory is assigned to contain the new - values. This happens even if there is no change in the amount of memory - required. -

    -

    One block or several

    -

    - The elements of the matrix are stored as a single array. Alternatives - would have been to store each row as a separate array or a set of adjacent - rows as a separate array. The present solution simplifies the program but - limits the size of matrices in 16 bit PCs that have a 64k byte limit on - the size of arrays (I don't use the huge keyword). The large - arrays may also cause problems for memory management in smaller machines. - [The 16 bit PC problem has largely gone away but it was a problem when - much of newmat was written. Now, occasionally I run into the 32 bit - PC problem.] -

    -

    By row or by column or other

    -

    - In Fortran two dimensional arrays are stored by column. In most other - systems they are stored by row. I have followed this later convention. - This makes it easier to interface with other packages written in C but - harder to interface with those written in Fortran. This may have been a - wrong decision. Most work on the efficient manipulation of large matrices - is being done in Fortran. It would have been easier to use this work if I - had adopted the Fortran convention. -

    -

    - An alternative would be to store the elements by mid-sized rectangular - blocks. This might impose less strain on memory management when one needs - to access both rows and columns. -

    -

    Storage of symmetric matrices

    -

    - Symmetric matrices are stored as lower triangular matrices. The decision - was pretty arbitrary, but it does slightly simplify the Cholesky - decomposition program. -

    -

    - 5.5 Memory management - reference counting or status - variable? -

    -

    - next - skip - - up - start -

    -

    Consider the instruction

    -
    -   X = A + B + C;
    -
    - -

    - To evaluate this a simple program will add A to - B putting the total in a temporary T1. Then it will add - T1 to C creating another temporary T2 which - will be copied into X. T1 and T2 will sit - around till the end of the execution of the statement and perhaps of the - block. It would be faster if the program recognised that T1 was - temporary and stored the sum of T1 and C back into - T1 instead of creating T2 and then avoided the final - copy by just assigning the contents of T1 to X rather - than copying. In this case there will be no temporaries requiring - deletion. (More precisely there will be a header to be deleted but no - contents). -

    -

    For an instruction like

    -
    -   X = (A * B) + (C * D);
    -
    - -

    - we can't easily avoid one temporary being left over, so we would like this - temporary deleted as quickly as possible. -

    -

    - I provide the functionality for doing all this by attaching a status - variable to each matrix. This indicates if the matrix is temporary so that - its memory is available for recycling or deleting. Any matrix operation - checks the status variables of the matrices it is working with and - recycles or deletes any temporary memory. -

    -

    - An alternative or additional approach would be to use - reference counting and delayed copying - also known as - copy on write. If a program requests a matrix to be copied, the - copy is delayed until an instruction is executed which modifies the memory - of either the original matrix or the copy. If the original matrix is - deleted before either matrix is modified, in effect, the values of the - original matrix are transferred to the copy without any actual copying - taking place. This solves the difficult problem of returning an object - from a function without copying and saves the unnecessary copying in the - previous examples. -

    -

    - There are downsides to the delayed copying approach. Typically, for - delayed copying one uses a structure like the following: -

    -
    -   Matrix
    +

    At the last step the heap memory associated with A is returned to the +system and a new block of heap memory is assigned to contain the new values. +This happens even if there is no change in the amount of memory required.

    +

    One block or several

    +

    The elements of the matrix are stored as a single array. Alternatives would +have been to store each row as a separate array or a set of adjacent rows as a +separate array. The present solution simplifies the program but limits the size +of matrices in 16 bit PCs that have a 64k byte limit on the size of arrays (I +don't use the huge keyword). The large arrays may also cause problems +for memory management in smaller machines. [The 16 bit PC problem has largely +gone away but it was a problem when much of newmat was written. Now, +occasionally I run into the 32 bit PC problem.]

    +

    By row or by column or other

    +

    In Fortran two dimensional arrays are stored by column. In most other +systems they are stored by row. I have followed this later convention. This +makes it easier to interface with other packages written in C but harder to +interface with those written in Fortran. This may have been a wrong decision. +Most work on the efficient manipulation of large matrices is being done in +Fortran. It would have been easier to use this work if I had adopted the +Fortran convention.

    +

    An alternative would be to store the elements by mid-sized rectangular +blocks. This might impose less strain on memory management when one needs to +access both rows and columns.

    +

    Storage of symmetric matrices

    +

    Symmetric matrices are stored as lower triangular matrices. The decision was +pretty arbitrary, but it does slightly simplify the Cholesky decomposition +program.

    +

    5.5 Memory management - +reference counting or status variable?

    +

    next - skip - +up - start

    +

    Consider the instruction

    +
       X = A + B + C;
    +
    + +

    To evaluate this a simple program will add A to B putting +the total in a temporary T1. Then it will add T1 to +C creating another temporary T2 which will be copied into +X. T1 and T2 will sit around till the end of the +execution of the statement and perhaps of the block. It would be faster if the +program recognised that T1 was temporary and stored the sum of +T1 and C back into T1 instead of creating +T2 and then avoided the final copy by just assigning the contents of +T1 to X rather than copying. In this case there will be no +temporaries requiring deletion. (More precisely there will be a header to be +deleted but no contents).

    +

    For an instruction like

    +
       X = (A * B) + (C * D);
    +
    + +

    we can't easily avoid one temporary being left over, so we would like this +temporary deleted as quickly as possible.

    +

    I provide the functionality for doing all this by attaching a status +variable to each matrix. This indicates if the matrix is temporary so that its +memory is available for recycling or deleting. Any matrix operation checks the +status variables of the matrices it is working with and recycles or deletes any +temporary memory.

    +

    An alternative or additional approach would be to use reference counting +and delayed copying - also known as copy on write. If a program +requests a matrix to be copied, the copy is delayed until an instruction is +executed which modifies the memory of either the original matrix or the copy. +If the original matrix is deleted before either matrix is modified, in effect, +the values of the original matrix are transferred to the copy without any +actual copying taking place. This solves the difficult problem of returning an +object from a function without copying and saves the unnecessary copying in the +previous examples.

    +

    There are downsides to the delayed copying approach. Typically, for delayed +copying one uses a structure like the following:

    +
       Matrix
          |
          +------> Array Object
          |          |
    @@ -4991,210 +3661,169 @@ 

    | +------ Dimension information -

    - -

    - where the arrows denote a pointer to a data structure. If one wants to - access the Data array one will need to track through two pointers. - If one is going to write, one will have to check whether one needs to copy - first. This is not important when one is going to access the whole array, - say, for a add operation. But if one wants to access just a single - element, then it imposes a significant additional overhead on that - operation. Any subscript operation would need to check whether an update - was required - even read since it is hard for the compiler to tell whether - a subscript access is a read or write. -

    -

    - Some matrix libraries don't bother to do this. So if you write - A = B; and then modify an element of one of A or - B, then the same element of the other is also modified. I don't - think this is acceptable behaviour. -

    -

    - Delayed copy does not provide the additional functionality of my approach - but I suppose it would be possible to have both delayed copy and tagging - temporaries. -

    -

    - My approach does not automatically avoid all copying. In particular, you - need use a special technique to return a matrix from a function without - copying. -

    -

    - 5.6 Memory management - accessing contiguous - locations -

    -

    - next - skip - - up - start -

    -

    - Modern computers work faster if one accesses memory by running through - contiguous locations rather than by jumping around all over the place. - Newmat stores matrices by rows so that algorithms that - access memory by running along rows will tend to work faster than one that - runs down columns. A number of the algorithms used in Newmat were - developed before this was an issue and so are not as efficient as - possible. -

    -

    - I have gradually upgrading the algorithms to access memory by rows. The - following table shows the current status of this process. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    FunctionContiguous memory accessComment
    Add, subtractYes 
    MultiplyYes 
    ConcatenateYes 
    TransposeNo 
    Invert and solveYesMostly
    CholeskyYes 
    QRZ, QRZTYes 
    updateQRZ, updateQRZTPartially 
    SVDNo 
    JacobiNoNot an issue; used only for smaller matrices
    EigenvaluesNo 
    SortYesQuick-sort is naturally good
    FFT?Could be improved?
    -

    - This is now all rather out of date. With Pentiums, at least, the important - requirement for speed seems to be to minimise transfers between the RAM - memory and the on-chip memory. There isn't much you can do about add and - subtract, but there lots of possibilities for some of the other - operations. -

    -

    5.7 Evaluation of expressions - lazy evaluation

    -

    - next - skip - - up - start -

    -

    Consider the instruction

    -
    -   X = B - X;
    -
    - -

    - A simple program will subtract X from B, store the - result in a temporary T1 and copy T1 into X. It - would be faster if the program recognised that the result could be stored - directly into X. This would happen automatically if the program - could look at the instruction first and mark X as temporary. -

    -

    C programmers would expect to avoid the same problem with

    -
    -   X = X - B;
    -
    - -

    by using an operator -=

    -
    -   X -= B;
    -
    - -

    - However this is an unnatural notation for non C users and it may be nicer - to write X = X - B; and know that the program will carry out the - simplification. -

    -

    - Another example where this intelligent analysis of an instruction is - helpful is in -

    -
    -   X = A.i() * B;
    -
    - -

    - where i() denotes inverse. Numerical analysts know it is - inefficient to evaluate this expression by carrying out the inverse - operation and then the multiply. Yet it is a convenient way of writing the - instruction. It would be helpful if the program recognised this expression - and carried out the more appropriate approach. -

    -

    - I regard this interpretation of A.i() * B as just providing a - convenient notation. The objective is not primarily to correct the errors - of people who are unaware of the inefficiency of A.i() * B if - interpreted literally. -

    -

    - There is a third reason for the two-stage evaluation of expressions and - this is probably the most important one. In C++ it is quite hard to return - an expression from a function such as (*, + etc) without - a copy. This is particularly the case when an assignment (=) is - involved. The mechanism described here provides one way for avoiding this - in matrix expressions. -

    -

    - The C++ standard (section 12.8/15) allows the compiler to optimise away - the copy when returning an object from a function (but there will still be - one copy is an assignment (=) is involved). This - means special handling of returns from a function is less important when a - modern optimising compiler is being used.  -

    -

    - To carry out this intelligent analysis of an instruction matrix - expressions are evaluated in two stages. In the the first stage a tree - representation of the expression is formed. For example - (A+B)*C is represented by a tree -

    -
    
    +
    + +

    where the arrows denote a pointer to a data structure. If one wants to +access the Data array one will need to track through two pointers. If +one is going to write, one will have to check whether one needs to copy first. +This is not important when one is going to access the whole array, say, for a +add operation. But if one wants to access just a single element, then it +imposes a significant additional overhead on that operation. Any subscript +operation would need to check whether an update was required - even read since +it is hard for the compiler to tell whether a subscript access is a read or +write.

    +

    Some matrix libraries don't bother to do this. So if you write A = +B; and then modify an element of one of A or B, then the +same element of the other is also modified. I don't think this is acceptable +behaviour.

    +

    Delayed copy does not provide the additional functionality of my approach +but I suppose it would be possible to have both delayed copy and tagging +temporaries.

    +

    My approach does not automatically avoid all copying. In particular, you +need use a special technique to return a matrix from a function without +copying.

    +

    5.6 Memory management - +accessing contiguous locations

    +

    next - skip - +up - start

    +

    Modern computers work faster if one accesses memory by running through +contiguous locations rather than by jumping around all over the place. Newmat +stores matrices by rows so that algorithms that access +memory by running along rows will tend to work faster than one that runs down +columns. A number of the algorithms used in Newmat were developed before this +was an issue and so are not as efficient as possible.

    +

    I have gradually upgrading the algorithms to access memory by rows. The +following table shows the current status of this process.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    FunctionContiguous memory accessComment
    Add, subtractYes 
    MultiplyYes 
    ConcatenateYes 
    TransposeNo 
    Invert and solveYesMostly
    CholeskyYes 
    QRZ, QRZTYes 
    updateQRZ, updateQRZTPartially 
    SVDNo 
    JacobiNoNot an issue; used only for smaller matrices
    EigenvaluesNo 
    SortYesQuick-sort is naturally good
    FFT?Could be improved?
    +

    This is now all rather out of date. With Pentiums, at least, the important +requirement for speed seems to be to minimise transfers between the RAM memory +and the on-chip memory. There isn't much you can do about add and subtract, but +there lots of possibilities for some of the other operations.

    +

    5.7 Evaluation of expressions - +lazy evaluation

    +

    next - skip - +up - start

    +

    Consider the instruction

    +
       X = B - X;
    +
    + +

    A simple program will subtract X from B, store the result +in a temporary T1 and copy T1 into X. It would be +faster if the program recognised that the result could be stored directly into +X. This would happen automatically if the program could look at the +instruction first and mark X as temporary.

    +

    C programmers would expect to avoid the same problem with

    +
       X = X - B;
    +
    + +

    by using an operator -=

    +
       X -= B;
    +
    + +

    However this is an unnatural notation for non C users and it may be nicer to +write X = X - B; and know that the program will carry out the +simplification.

    +

    Another example where this intelligent analysis of an instruction is helpful +is in

    +
       X = A.i() * B;
    +
    + +

    where i() denotes inverse. Numerical analysts know it is +inefficient to evaluate this expression by carrying out the inverse operation +and then the multiply. Yet it is a convenient way of writing the instruction. +It would be helpful if the program recognised this expression and carried out +the more appropriate approach.

    +

    I regard this interpretation of A.i() * B as just providing a +convenient notation. The objective is not primarily to correct the errors of +people who are unaware of the inefficiency of A.i() * B if interpreted +literally.

    +

    There is a third reason for the two-stage evaluation of expressions and this +is probably the most important one. In C++ it is quite hard to return an +expression from a function such as (*, + etc) without a copy. +This is particularly the case when an assignment (=) is involved. The +mechanism described here provides one way for avoiding this in matrix +expressions.

    +

    The C++ standard (section 12.8/15) allows the compiler to optimise away the +copy when returning an object from a function (but there will still be one copy +is an assignment (=) is involved). This means special handling of returns from a +function is less important when a modern optimising compiler is being +used. 

    +

    To carry out this intelligent analysis of an instruction matrix +expressions are evaluated in two stages. In the the first stage a tree +representation of the expression is formed. For example (A+B)*C is +represented by a tree

    +
    
            *
           / \
          +   C
    @@ -5202,224 +3831,158 @@ 

    5.7 Evaluation of expressions - lazy evaluation

    A B
    -

    - Rather than adding A and B the + operator - yields an object of a class AddedMatrix which is just a pair of - pointers to A and B. Then the * operator yields - a MultipliedMatrix which is a pair of pointers to the - AddedMatrix and C. The tree is examined for any - simplifications and then evaluated recursively. -

    -

    - Further possibilities not yet included are to recognise - A.t()*A and A.t()+A as symmetric or to improve the - efficiency of evaluation of expressions like A+B+C, - A*B*C, A*B.t() (t() denotes transpose). -

    -

    - One of the disadvantages of the two-stage approach is that the types of - matrix expressions are determined at run-time. So the compiler will not - detect errors of the type -

    -
    -   Matrix M;
    +

    Rather than adding A and B the + operator yields +an object of a class AddedMatrix which is just a pair of pointers to +A and B. Then the * operator yields a +MultipliedMatrix which is a pair of pointers to the AddedMatrix +and C. The tree is examined for any simplifications and then evaluated +recursively.

    +

    Further possibilities not yet included are to recognise A.t()*A and +A.t()+A as symmetric or to improve the efficiency of evaluation of +expressions like A+B+C, A*B*C, A*B.t() (t() +denotes transpose).

    +

    One of the disadvantages of the two-stage approach is that the types of +matrix expressions are determined at run-time. So the compiler will not detect +errors of the type

    +
       Matrix M;
        DiagonalMatrix D;
        ....;
        D = M;
    -
    - -

    - We don't allow conversions using = when information would be - lost. Such errors will be detected when the statement is executed. -

    -

    - 5.8 How to overcome an explosion in number of - operations -

    -

    - next - skip - - up - start -

    -

    - The package attempts to solve the problem of the large number of versions - of the binary operations required when one has a variety of types. -

    -

    - With n types of matrices the binary operations will each require - n-squared separate algorithms. Some reduction in the number may be - possible by carrying out conversions. However, the situation rapidly - becomes impossible with more than 4 or 5 types. Doug Lea told me that it - was possible to avoid this problem. I don't know what his solution is. - Here's mine. -

    -

    - Each matrix type includes routines for extracting individual rows or - columns. I assume a row or column consists of a sequence of zeros, a - sequence of stored values and then another sequence of zeros. Only a - single algorithm is then required for each binary operation. The rows can - be located very quickly since most of the matrices are stored row by row. - Columns must be copied and so the access is somewhat slower. As far as - possible my algorithms access the matrices by row. -

    -

    - There is another approach. Each of the matrix types defined in this - package can be set up so both rows and columns have their elements at - equal intervals provided we are prepared to store the rows and columns in - up to three chunks. With such an approach one could write a single - "generic" algorithm for each of multiply and add. This would be - a reasonable alternative to my approach. -

    -

    - I provide several algorithms for operations like + . If one is adding two - matrices of the same type then there is no need to access the individual - rows or columns and a faster general algorithm is appropriate. -

    -

    - Generally the method works well. However symmetric matrices are not always - handled very efficiently (yet) since complete rows are not stored - explicitly. -

    -

    - The original version of the package did not use this access by row or - column method and provided the multitude of algorithms for the combination - of different matrix types. The code file length turned out to be just a - little longer than the present one when providing the same facilities with - 5 distinct types of matrices. It would have been very difficult to - increase the number of matrix types in the original version. Apparently 4 - to 5 types is about the break even point for switching to the approach - adopted in the present package. -

    -

    - However it must also be admitted that there is a substantial overhead in - the approach adopted in the present package for small matrices. The test - program developed for the original version of the package takes 30 to 50% - longer to run with the current version (though there may be some other - reasons for this). This is for matrices in the range 6x6 to 10x10. -

    -

    - To try to improve the situation a little I do provide an ordinary matrix - multiplication routine for the case when all the matrices involved are - rectangular. -

    -

    5.9 Destruction of temporaries

    -

    - next - skip - - up - start -

    -

    - Versions before version 5 of newmat did not work correctly with Gnu C++ - (version 5 or earlier). This was because the tree structure used to - represent a matrix expression was set up on the stack.  Early - versions of Gnu C++ destroyed temporary structures as soon as the function - that accesses them finished. To overcome this problem, there was an option - to store the temporaries forming the tree structure on the heap (created - with new) and to delete them explicitly. Now that the C++ standards - committee has said that temporary structures should not be destroyed - before a statement finishes, I have deleted this option. -

    -

    5.10 A calculus of matrix types

    -

    - next - skip - - up - start -

    -

    - The program needs to be able to work out the class of the result of a - matrix expression. This is to check that a conversion is legal or to - determine the class of an intermediate result. To assist with this, a - class MatrixType is defined. Operators +, -, *, - >= are defined to calculate the types of the results of - expressions or to check that conversions are legal. -

    -

    - Early versions of newmat stored the types of the results of - operations in a table. So, for example, if you multiplied an - UpperTriangularMatrix by a LowerTriangularMatrix, newmat would look - up the table and see that the result was of type Matrix. With this - approach the exploding number of operations problem - recurred although not as seriously as when code had to be written for each - pair of types. But there was always the suspicion that somewhere, there - was an error in one of those 9x9 tables, that would be very hard to find. - And the problem would get worse as additional matrix types or operators - were included. -

    -

    - The present version of newmat solves the problem by assigning - attributes such as diagonal or band or - upper triangular to each matrix type. Which attributes a matrix - type has, is stored as bits in an integer. As an example, the - DiagonalMatrix type has the bits corresponding to diagonal, - symmetric and band equal to 1. By looking at the attributes - of each of the operands of a binary operator, the program can work out the - attributes of the result of the operation with simple bitwise operations. - Hence it can deduce an appropriate type. The symmetric attribute is - a minor problem because symmetric * symmetric does not yield - symmetric unless both operands are diagonal. But otherwise - very simple code can be used to deduce the attributes of the result of a - binary operation. -

    -

    - Tables of the types resulting from the binary operators are output at the - beginning of the test program. -

    -

    5.11 Pointer arithmetic

    -

    - next - skip - - up - start -

    -

    Suppose you do something like

    -
    -   int* y = new int[100];
    +
    + +

    We don't allow conversions using = when information would be lost. +Such errors will be detected when the statement is executed.

    +

    5.8 How to overcome an +explosion in number of operations

    +

    next - skip - +up - start

    +

    The package attempts to solve the problem of the large number of versions of +the binary operations required when one has a variety of types.

    +

    With n types of matrices the binary operations will each require +n-squared separate algorithms. Some reduction in the number may be +possible by carrying out conversions. However, the situation rapidly becomes +impossible with more than 4 or 5 types. Doug Lea told me that it was possible +to avoid this problem. I don't know what his solution is. Here's mine.

    +

    Each matrix type includes routines for extracting individual rows or +columns. I assume a row or column consists of a sequence of zeros, a sequence +of stored values and then another sequence of zeros. Only a single algorithm is +then required for each binary operation. The rows can be located very quickly +since most of the matrices are stored row by row. Columns must be copied and so +the access is somewhat slower. As far as possible my algorithms access the +matrices by row.

    +

    There is another approach. Each of the matrix types defined in this package +can be set up so both rows and columns have their elements at equal intervals +provided we are prepared to store the rows and columns in up to three chunks. +With such an approach one could write a single "generic" algorithm +for each of multiply and add. This would be a reasonable alternative to my +approach.

    +

    I provide several algorithms for operations like + . If one is adding two +matrices of the same type then there is no need to access the individual rows +or columns and a faster general algorithm is appropriate.

    +

    Generally the method works well. However symmetric matrices are not always +handled very efficiently (yet) since complete rows are not stored explicitly. +

    +

    The original version of the package did not use this access by row or column +method and provided the multitude of algorithms for the combination of +different matrix types. The code file length turned out to be just a little +longer than the present one when providing the same facilities with 5 distinct +types of matrices. It would have been very difficult to increase the number of +matrix types in the original version. Apparently 4 to 5 types is about the +break even point for switching to the approach adopted in the present package. +

    +

    However it must also be admitted that there is a substantial overhead in the +approach adopted in the present package for small matrices. The test program +developed for the original version of the package takes 30 to 50% longer to run +with the current version (though there may be some other reasons for this). +This is for matrices in the range 6x6 to 10x10.

    +

    To try to improve the situation a little I do provide an ordinary matrix +multiplication routine for the case when all the matrices involved are +rectangular.

    +

    5.9 Destruction of +temporaries

    +

    next - skip - +up - start

    +

    Versions before version 5 of newmat did not work correctly with Gnu C++ +(version 5 or earlier). This was because the tree structure used to represent a +matrix expression was set up on the stack.  Early versions of Gnu C++ destroyed temporary structures as soon as the +function that accesses them finished. To overcome this problem, there was an +option to store the temporaries forming the tree structure on the heap (created +with new) and to delete them explicitly. Now that the C++ standards committee +has said that temporary structures should not be destroyed before a statement +finishes, I have deleted this option.

    +

    5.10 A calculus of matrix +types

    +

    next - skip - +up - start

    +

    The program needs to be able to work out the class of the result of a matrix +expression. This is to check that a conversion is legal or to determine the +class of an intermediate result. To assist with this, a class MatrixType is +defined. Operators +, -, *, >= are +defined to calculate the types of the results of expressions or to check that +conversions are legal.

    +

    Early versions of newmat stored the types of the results of +operations in a table. So, for example, if you multiplied an +UpperTriangularMatrix by a LowerTriangularMatrix, newmat would look up +the table and see that the result was of type Matrix. With this approach the +exploding number of operations problem recurred although +not as seriously as when code had to be written for each pair of types. But +there was always the suspicion that somewhere, there was an error in one of +those 9x9 tables, that would be very hard to find. And the problem would get +worse as additional matrix types or operators were included.

    +

    The present version of newmat solves the problem by assigning +attributes such as diagonal or band or upper +triangular to each matrix type. Which attributes a matrix type has, is +stored as bits in an integer. As an example, the DiagonalMatrix type has the +bits corresponding to diagonal, symmetric and band equal +to 1. By looking at the attributes of each of the operands of a binary +operator, the program can work out the attributes of the result of the +operation with simple bitwise operations. Hence it can deduce an appropriate +type. The symmetric attribute is a minor problem because +symmetric * symmetric does not yield symmetric unless both +operands are diagonal. But otherwise very simple code can be used to +deduce the attributes of the result of a binary operation.

    +

    Tables of the types resulting from the binary operators are output at the +beginning of the test program.

    +

    5.11 Pointer arithmetic

    +

    next - skip - +up - start

    +

    Suppose you do something like

    +
       int* y = new int[100];
        y += 200;          // y points to something outside the array
    -   // y is never accessed
    -
    - -

    - Then the standard says that the behaviour of the program is - undefined even if y is never accessed. (You are allowed to - calculate a pointer value one location beyond the end of the array). In - practice, a program like this does not cause any problems with any - compiler I have come across and no-one has reported any such problems to - me. -

    -

    - However, this error is detected by Borland's - Code Guard bound's checker and this makes it very difficult to use - this to use Code Guard to detect other problems since the output is - swamped by reports of this error. -

    -

    Now consider

    -
    -   int* y = new int[100];
    +   // y is never accessed
    +
    + +

    Then the standard says that the behaviour of the program is undefined +even if y is never accessed. (You are allowed to calculate a pointer +value one location beyond the end of the array). In practice, a program like +this does not cause any problems with any compiler I have come across and +no-one has reported any such problems to me.

    +

    However, this error is detected by Borland's Code Guard +bound's checker and this makes it very difficult to use this to use Code +Guard to detect other problems since the output is swamped by reports of +this error.

    +

    Now consider

    +
       int* y = new int[100];
        y += 200;          // y points to something outside the array
        y -= 150;          // y points to something inside the array
    -   // y is accessed
    -
    - -

    - Again this is not strictly correct but does not seem to cause a problem. - But it is much more doubtful than the previous example. -

    -

    - I removed most instances of the second version of the problem from - Newmat09. Hopefully the remainder of these instances were removed from - Newmat10. In addition, most instances of the first version of the problem - have also been fixed. -

    -

    - There is one exception. The interface to the - Numerical Recipes in C does still contain the second - version of the problem. This is inevitable because of the way Numerical - Recipes in C stores vectors and matrices. If you are running the - test program with a bounds checking program, edit - tmt.h to disable the testing of the NRIC interface. -

    -

    - The rule does does cause a problem for authors of matrix and - multidimensional array packages. If we want to run down a column of a - matrix we would like to do something like -

    -
    -   // set values of column 1
    +   // y is accessed
    +
    + +

    Again this is not strictly correct but does not seem to cause a problem. But +it is much more doubtful than the previous example.

    +

    I removed most instances of the second version of the problem from Newmat09. +Hopefully the remainder of these instances were removed from Newmat10. In addition, most instances of the first version of the +problem have also been fixed.

    +

    There is one exception. The interface to the Numerical +Recipes in C does still contain the second version of the problem. This is +inevitable because of the way Numerical Recipes in C stores vectors and +matrices. If you are running the test program with a +bounds checking program, edit tmt.h to disable the testing of the NRIC +interface.

    +

    The rule does does cause a problem for authors of matrix and +multidimensional array packages. If we want to run down a column of a matrix we +would like to do something like

    +
       // set values of column 1
        Matrix A;
        ... set dimensions and put values in A
        Real* a = A.data();               // points to first element
    @@ -5430,16 +3993,13 @@ 

    5.11 Pointer arithmetic

    *a = something to put in first element of row a += nc; // jump to next element of column } -
    +
    -

    - If the matrix has more than one column the last execution of - a += nc; will run off the end of the space allocated to the - matrix and we'll get a bounds error report. -

    -

    Instead we have to use a program like

    -
    -   // set values of column 1
    +

    If the matrix has more than one column the last execution of a += +nc; will run off the end of the space allocated to the matrix and we'll +get a bounds error report.

    +

    Instead we have to use a program like

    +
       // set values of column 1
        Matrix A;
        ... set dimensions and put values in A
        Real* a = A.data();               // points to first element
    @@ -5454,1604 +4014,1105 @@ 

    5.11 Pointer arithmetic

    a += nc; // jump to next element of column } } -
    - -

    - which is more complicated and consequently introduces more chance of - error. -

    -

    5.12 Error handling

    -

    - next - skip - - up - start -

    -

    - The library now does have a moderately graceful exit from errors. One can - use either the simulated exceptions or the compiler supported exceptions. - When newmat08 was released (in 1995), compiler exception handling in the - compilers I had access to was unreliable. I recommended you used my - simulated exceptions. In 1997 compiler supported exceptions seemed to work - on a variety of compilers - but not all compilers. This was still true in - 2001. One compiler company was still having problems in 2003 (not sure - about 2004). Try using the compiler supported exceptions if you have a - recent compiler, but if you are getting strange crashes or errors try - going back to my simulated exceptions. -

    -

    - The approach in the present library, attempting to simulate C++ - exceptions, is not completely satisfactory, but seems a good interim - solution for those who cannot use compiler supported exceptions. People - who don't want exceptions in any shape or form, can set the option to exit - the program if an exception is thrown. -

    -

    - The exception mechanism cannot clean-up objects explicitly created by new. - This must be explicitly carried out by the package writer or the package - user. I have not yet done this completely with the present package so - occasionally a little garbage may be left behind after an exception. I - don't think this is a big problem, but it is one that needs fixing. -

    -

    5.13 Sparse matrices

    -

    - next - skip - - up - start -

    -

    The library does not support sparse matrices.

    -

    - For sparse matrices there is going to be some kind of structure vector. It - is going to have to be calculated for the results of expressions in much - the same way that types are calculated. In addition, a whole new set of - row and column operations would have to be written. -

    -

    - Sparse matrices are important for people solving large sets of - differential equations as well as being important for statistical and - operational research applications. -

    -

    - But there are packages being developed specifically for sparse matrices - and these might present the best approach, at least where sparse matrices - are the main interest. -

    -

    5.14 Complex matrices

    -

    - next - skip - - up - start -

    -

    - The package does not yet support matrices with complex elements. There are - at least two approaches to including these. One is to have matrices with - complex elements. -

    -

    - This probably means making new versions of the basic row and column - operations for Real*Complex, Complex*Complex, Complex*Real and similarly - for + and -. This would be OK, except that if I also - want to do this for sparse matrices, then when you put these together, the - whole thing will get out of hand. -

    -

    - The alternative is to represent a Complex matrix by a pair of Real - matrices. One probably needs another level of decoding expressions but I - think it might still be simpler than the first approach. But there is - going to be a problem with accessing elements and it does not seem - possible to solve this in an entirely satisfactory way. -

    -

    - Complex matrices are used extensively by electrical engineers and - physicists and really should be fully supported in a comprehensive - package. -

    -

    - You can simulate most complex operations by representing - Z = X + iY by -

    -
    -    /  X   Y \
    -    \ -Y   X /
    -
    - -

    - Most matrix operations will simulate the corresponding complex operation, - when applied to this matrix. But, of course, this matrix is essentially - twice as big as you would need with a genuine complex matrix library. -

    - -

     

    - -

    6. Function summary

    - -

    - next - skip - - up - start -

    - -

    - 6.1 Member functions for matrices and matrix expressions
    - 6.2 Member functions for matrices
    - 6.3 Operators
    - 6.3 Global functions - newmat.h
    - 6.4 Global functions - newmatap.h
    - 6.5 Other classes - member functions -

    - -

    - This section lists member and global functions for matrices defined in - newmat.h. Where there are alternative names the lower-case - non-capitalised versions are the preferred ones. -

    - -

    - 6.1 Member functions for matrices and - matrix expressions -

    -

    - next - - skip - up - - start -

    -

    - Member functions for matrices and matrix expressions. These do not apply - to CroutMatrix and BandLUMatrix unless explicitly noted. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    - Unary operators -

    (see also operators)

    -
    .t()matrix transpose
    - .reverse()
    - .Reverse() -
    reverse order of elements (not band matrices)
    .i() - invert matrix or solve (also works with CroutMatrix and BandLUMatrix) -
    .sum_rows()sum elements in each row
    .sum_columns()sum elements in each column
    .sum_square_rows()sum squares of elements in each row
    .sum_square_columns()sum squares of elements in each column
    Change type - .as_row()
    - .AsRow() -
    interpret matrix body as a single row
    - .as_column()
    - .AsColumn() -
    interpret matrix body as a single column
    - .as_diagonal()
    - .AsDiagonal() -
    interpret matrix body as a diagonal matrix
    - .as_matrix()
    - .AsMatrix() -
    interpret matrix body as a rectangular matrix
    - .as_scalar()
    - .AsScalar() -
    convert 1x1 to Real
    Submatrices - .submatrix(int,int,int,int)
    - .SubMatrix(int,int,int,int) -
    submatrix
    - .sym_submatrix(int,int)
    - .SymSubMatrix(int,int) -
    submatrix with same row and column range
    - .row(int)
    - .Row(int) -
    select a row of a matrix
    - .rows(int,int)
    - .Rows(int,int) -
    select a range of rows of a matrix
    - .column(int)
    - .Column(int,int) -
    select a column of a matrix
    - .columns(int)
    - .Columns(int,int) -
    select a range of columns of a matrix
    - Scalar functions - maxima & minima -

    - (also global versions of maximum(), minimum(),  - maximum_absolute_value(), mimimum_absolute_value()) -

    -
    - .maximum_absolute_value()
    - .
    MaximumAbsoluteValue() -
    maximum absolute value of elements
    - .maximum_absolute_value1(int&)
    - .MaximumAbsoluteValue1(int&) -
    maximum absolute value, return location
    - .maximum_absolute_value2(int&,int&)
    - .MaximumAbsoluteValue2(int&,int&) -
    maximum absolute value, return location
    - .minimum_absolute_value()
    - .MinimumAbsoluteValue() -
    minimum absolute value of elements
    - .minimum_absolute_value1(int&)
    - .MinimumAbsoluteValue1(int&) -
    minimum absolute value, return location
    - .minimum_absolute_value2(int&,int&)
    - .MinimumAbsoluteValue2(int&,int&) -
    minimum absolute value, return location
    - .maximum()
    - .Maximum() -
    maximum value of elements
    - .maximum1(int&)
    - .Maximum1(int&) -
    maximum value, return location
    - .maximum2(int&,int&)
    - .Maximum2(int&,int&) -
    maximum value, return location
    - .minimum()
    - .Minimum() -
    minimum value of elements
    - .minimum1(int&)
    - .Minimum1(int&) -
    minimum value, return location
    - .minimum2(int&,int&)
    - .Minimum2(int&,int&) -
    minimum value, return location
    - Scalar functions - numerical -

    (also global versions of these functions)

    -
    - .log_determinant()
    - .LogDeterminant() -
    - natural logarithm of the determinant (also works with CroutMatrix and - BandLUMatrix) -
    - .determinant()
    - .Determinant() -
    - determinant (also works with CroutMatrix and BandLUMatrix) -
    - .sum_square()
    - .SumSquare() -
    sum of squares of elements
    - .norm_Frobenius()
    - .norm_frobenius()
    - .NormFrobenius() -
    square root of sum of squares of elements
    - .sum_absolute_value()
    - .SumAbsoluteValue() -
    sum of absolute values of elements
    - .sum()
    - .Sum() -
    sum of elements
    - .trace()
    - .Trace() -
    trace of a matrix
    - .norm1()
    - .Norm1() -
    - maximum of sum of absolute values of elements of a column -
    - .norm_infinity()
    - .NormInfinity() -
    - maximum of sum of absolute values of elements of a row -
    - Scalar functions - size and shape - - .bandwidth()
    - .BandWidth() -
    - bandwidth of matrix (also works with CroutMatrix and BandLUMatrix) -
    -

     

    -

    6.2 Member functions for matrices

    -

    - next - skip - - up - start -

    -

    - Member functions for matrices but not matrix expressions. These do not - apply to CroutMatrix and BandLUMatrix unless explicitly noted. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    - Element access -

    (see also operators)

    -
    .element(int,int)access element - subscripts start at 0
    .element(int)access element - subscripts start at 0
    Copying - .inject(const GeneralMatrix&)
    - .Inject(const GeneralMatrix&) -
    copy elements into a matrix
    .swap(Matrix&) - swap bodies of two matrices of same type (also global version, also - works with CroutMatrix and BandLUMatrix) -
    - Scalar functions - size and shape -

    (also work with CroutMatrix and BandLUMatrix)

    -
    - .type()
    - .Type() -
    type of a matrix
    - .nrows()
    - .Nrows() -
    number of rows
    - .ncols()
    - .Ncols() -
    number of columns
    - .size()
    - .Storage() -
    - number of stored elements (including unused elements in band matrices) -
    .size2()size of second array (BandLUMatrix only)
    - .data()
    - .Store() -
    pointer to stored elements
    .const_data()constant pointer to stored elements
    .const_data2() - constant pointer to second array (BandLUMatrix only) -
    .const_data_indx() - constant pointer to row swap array (CroutMatrix and BandLUMatrix only) -
    - Scalar functions - numerical - - .is_zero()
    - .IsZero() -
    - test all elements are exactly zero (also global version) -
    - .is_singular()
    - .IsSingular() -
    - test for exact singularity (CroutMatrix and BandLUMatrix only) -
    .even_exchanges() - true if there have been an even number of row exchanges (CroutMatrix - and BandLUMatrix only) -
    Memory management - .release()
    - .Release() -
    release memory after next operation
    - .release(int)
    - .Release(int) -
    release memory after specified number of operations
    - .release_and_delete()
    - .ReleaseAndDelete() -
    delete after next operation
    - .for_return()
    - .ForReturn() -
    - place in an envelope for efficient return from a function -
    Change dimensions - .resize(int)
    - .ReSize(int) -
    change the dimensions (vectors and square matrices)
    - .resize(int,int)
    - .ReSize(int,int) -
    - change the dimensions (non-square matrices, triangular band matrices - and symmetric band matrices) -
    - .resize(int,int,int)
    - .ReSize(int,int,int) -
    change the dimensions (band matrices)
    - .resize(const GeneralMatrix&)
    - .ReSize(const GeneralMatrix&) -
    change dimensions to match those of another matrix
    - .cleanup()
    - .CleanUp() -
    resize to 0x0
    .resize_keep(int) - change the dimensions, keep values (vectors and square matrices, not - band) -
    .resize_keep(int,int) - change the dimensions , keep values (non-square matrices) -
    -

     

    -

    6.3 Operators

    -

    - next - - skip - up - - start -

    -

    - Operators for matrices and matrix expressions. These do not apply to - CroutMatrix and BandLUMatrix unless explicitly noted. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    - Element access -

    (matrices only, not functions of a matrix)

    -
    ()access element - subscripts start at 1
    ()access element - subscripts start at 1
    [] - access element C style - subscripts start at zero; if - SETUP_C_SUBSCRIPTS is defined. -
    Unary operators-change sign of elements
    Binary operators+, +=add matrices
    -, -=subtract matrices
    *, *=matrix multiplication
    |, |=horizontal concatenation
    &, &=vertical stacking
    == - test for exact equality (also works with CroutMatrix and - BandLUMatrix) -
    != - test for inequality (i.e. not exact equality, also works with - CroutMatrix and BandLUMatrix) -
    - Matrix and scalar - +, +=add Real to matrix
    -, -= - subtract Real from matrix; subtract matrix from Real -
    *, *=multiply matrix by Real
    /, /=divide matrix by Real
    Copying= - copy matrix (error if there is loss of data,  also works - with CroutMatrix and BandLUMatrix) -
    =copy Real to all elements
    <<copy matrix (no error if there is loss of data)
    Enter values<<enter list of values into matrix
    - Output -

    (header in newmatio.h)

    -
    <<print matrix to file
    -

     

    - -

    6.4 Global functions - newmat.h

    -

    - next - - skip - up - - start -

    -

    - Operators for matrices and matrix expressions. These do not apply to - CroutMatrix and BandLUMatrix. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    - Binary operators -

    (see also operators)

    -
    - SP(const BaseMatrix&, const BaseMatrix&) - element-wise product of two matrices
    - KP(const BaseMatrix&, const BaseMatrix&) - Kronecker product of two matrices
    - crossproduct(const Matrix&, const Matrix&)
    - CrossProduct(const Matrix&, const Matrix&) -
    - cross product of two 3x1 or 1x3 matrices or vectors. -
    - crossproduct_rows(const Matrix&, const Matrix&)
    - CrossProductRows(const Matrix&, const Matrix&) -
    row-wise cross product
    - crossproduct_columns(const Matrix&, const Matrix&)
    - CrossProductColumns(const Matrix&, const Matrix&) -
    column-wise cross product
    Scalar functions - numerical - dotproduct(const Matrix&, const Matrix&)
    DotProduct(const Matrix&, const Matrix&) -
    dot product of two vectors
    - -

     

    - -

    6.5 Global functions - newmatap.h

    -

    - next - skip - - up - start -

    - -

    - Advanced operators for matrices and matrix expressions. These do not apply - to CroutMatrix and BandLUMatrix. -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Function groupfunction namedescription
    - QR transform - - QRZT(Matrix&, LowerTriangularMatrix&) - transposed version of QRZ transform
    - QRZT(const Matrix&, Matrix&, Matrix&) - - transposed version of QRZ transform - solve part -
    - QRZT(Matrix&, Matrix&, LowerTriangularMatrix&, - Matrix&) - both of previous two lines
    - QRZ(Matrix&, UpperTriangularMatrix&) - QRZ transform
    - QRZ(const Matrix&, Matrix&, Matrix&) - QRZ transform - solve part
    - QRZ(Matrix&, Matrix&, UpperTriangularMatrix&, - Matrix&) - both of previous two lines
    - updateQRZT(Matrix&, LowerTriangularMatrix&)
    - UpdateQRZT(Matrix&, LowerTriangularMatrix&) -
    - add extra columns to transposed version of QRZ transform -
    - updateQRZ(Matrix&, UpperTriangularMatrix&)
    - UpdateQRZ(Matrix&, UpperTriangularMatrix&) -
    add extra rows to QRZ transform
    - updateQRZ(const Matrix&, Matrix&, Matrix&)
    - UpdateQRZ(const Matrix&, Matrix&, Matrix&) -
    - combine the results of the solve parts of QRZ transforms on two blocks - of data -
    - updateQRZ(UpperTriangularMatrix&, - UpperTriangularMatrix&)
    - UpdateQRZ(UpperTriangularMatrix&, UpperTriangularMatrix&) -
    - combine the results of QRZ transforms on two blocks of data -
    - updateQRZ(const UpperTriangularMatrix&, Matrix&, - Matrix&)
    - UpdateQRZ(const UpperTriangularMatrix&, Matrix&, Matrix&) -
    - combine the results of the solve parts of QRZ transforms on two blocks - of data -
    - Extend orthonormal set - - extend_orthonormal(Matrix&, int) - extend a set of orthonormal columns
    - Cholesky decomposition - - Cholesky(const SymmetricMatrix&) - - Cholesky decomposition of symmetric matrix -
    - Cholesky(const SymmetricBandMatrix&) - - Cholesky decomposition of symmetric band matrix -
    - Update Cholesky decomposition - - update_Cholesky (UpperTriangularMatrix&, RowVector)
    - UpdateCholesky (UpperTriangularMatrix&, RowVector) -
    - add extra row to Cholesky/QR decomposition -
    - downdate_Cholesky (UpperTriangularMatrix&, RowVector)
    - DowndateCholesky (UpperTriangularMatrix&, RowVector) -
    - remove row from Cholesky/QR decomposition -
    - right_circular_update_Cholesky (UpperTriangularMatrix&, - int, int)
    - RightCircularUpdateCholesky (UpperTriangularMatrix&, int, - int) -
    - rearrange columns in Cholesky/QR decomposition -
    - left_circular_update_Cholesky (UpperTriangularMatrix&, int, - int)
    - LeftCircularUpdateCholesky (UpperTriangularMatrix&, int, - int) -
    - rearrange columns in Cholesky/QR decomposition -
    - Singular value decomposition - - SVD(const Matrix&, DiagonalMatrix&, Matrix&, - Matrix&, bool, bool) - - singular value decomposition - get U and V -
    - SVD(const Matrix&, DiagonalMatrix&) - - SVD decomposition - get just singular values -
    - SVD(const Matrix& A, DiagonalMatrix& D, Matrix&, - bool) - SVD decomposition - get U
    - Eigenvalue decomposition of a symmetric matrix - - Jacobi(const SymmetricMatrix&, DiagonalMatrix&) - - Jacobi eigenvalue decomposition - get only eigenvalues -
    - Jacobi(const SymmetricMatrix&, DiagonalMatrix&, - SymmetricMatrix&) - - Jacobi eigenvalue decomposition - get only eigenvalues -
    - Jacobi(const SymmetricMatrix&, DiagonalMatrix&, - Matrix&) - - Jacobi eigenvalue decomposition - get eigenvalues and eigenvectors -
    - Jacobi(const SymmetricMatrix&, DiagonalMatrix&, - SymmetricMatrix&, Matrix&, bool) - - Jacobi eigenvalue decomposition - get eigenvalues and eigenvectors -
    - eigenvalues(const SymmetricMatrix&, DiagonalMatrix&)
    - EigenValues(const SymmetricMatrix&, DiagonalMatrix&) -
    - Householder eigenvalue decomposition - get only eigenvalues -
    - eigenvalues(const SymmetricMatrix&, DiagonalMatrix&, - SymmetricMatrix&)
    - EigenValues(const SymmetricMatrix&, DiagonalMatrix&, - SymmetricMatrix&) -
    - Householder eigenvalue decomposition with back transform - get only - eigenvalues -
    - eigenvalues(const SymmetricMatrix&, DiagonalMatrix&, - Matrix&)
    - EigenValues(const SymmetricMatrix&, DiagonalMatrix&, - Matrix&) -
    - Householder eigenvalue decomposition - get eigenvalues and - eigenvectors -
    - Sorting - - sort_ascending(GeneralMatrix&)
    - SortAscending(GeneralMatrix&) -
    ascending sort
    - sort_descending(GeneralMatrix&)
    - SortDescending(GeneralMatrix&) -
    descending sort
    - Fast Fourier transform - - FFT(const ColumnVector&, const ColumnVector&, - ColumnVector&, ColumnVector&) - fast Fourier transform
    - FFTI(const ColumnVector&, const ColumnVector&, - ColumnVector&, ColumnVector&) - fast Fourier transform - inverse
    - RealFFT(const ColumnVector&, ColumnVector&, - ColumnVector&) - FFT of real vector
    - RealFFTI(const ColumnVector&, const ColumnVector&, - ColumnVector&) - FFT of real vector - inverse
    - FFT2(const Matrix& U, const Matrix& V, Matrix& X, - Matrix& Y) - two dimensional FFT
    - FFT2I(const Matrix& U, const Matrix& V, Matrix& X, - Matrix& Y) - two dimensional FFT - inverse
    - Fast trigonometric transform - - DCT_II(const ColumnVector&, ColumnVector&) - type II discrete cosine transform
    - DCT_II_inverse(const ColumnVector&, ColumnVector&) - - type II discrete cosine transform - inverse -
    - DST_II(const ColumnVector&, ColumnVector&) - type II discrete sine transform
    - DST_II_inverse(const ColumnVector&, ColumnVector&) - - type II discrete sine transform - inverse -
    - DCT(const ColumnVector&, ColumnVector&) - discrete cosine transform
    - DCT_inverse(const ColumnVector&, ColumnVector&) - discrete cosine transform - inverse
    - DST(const ColumnVector&, ColumnVector&) - discrete sine transform
    - DST_inverse(const ColumnVector&, ColumnVector&) - discrete sine transform - inverse
    - Helmert transform - Helmert(int, bool=false)return Helmert transform matrix
    - Helmert(const ColumnVector&, bool=false)
    - Helmert(const Matrix&, bool=false) -
    multiply by Helmert transform matrix
    Helmert(int, int, bool=false) - return column of Helmert transform matrix -
    - Helmert_transpose(const ColumnVector&, bool=false)
    - Helmert_transpose(const Matrix&, bool=false) -
    - multiply by transpose of Helmert transform matrix -
    - Helmert_transpose(const ColumnVector&, int, bool=false) - - multiply by transpose of Helmert transform matrix, return one element - of result -
    - -

     

    -

    6.6 Other classes - member functions

    -

    - next - skip - - up - start -

    - -

     

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Classfunction namedescription
    - LogAndSign - - .pow_eq(int)
    - .PowEq(int) -
    raise to a power
    - .change_sign()
    - .ChangeSign() -
    change sign
    - .log_value()
    - .LogValue() -
    - return the natural logarithm of the value -
    - .sign()
    - .Sign() -
    return the sign
    - .value()
    - .Value() -
    return the value (no log transform)
    - MatrixType - - .value()
    - .Value() -
    return the value (as character string)
    .is_diagonal()has diagonal attribute
    .is_symmetric()has symmetric attribute
    .is_band()has band attribute
    - MatrixBandWidth - - .upper()
    - .Upper() -
    return upper band width
    - .lower()
    - .Lower() -
    return lower bandwidth
    - SimpleIntArray - - .size()
    - .Size() -
    return size of array
    - .data()
    - .Data() -
    return a pointer to the data
    .const_data()return a constant pointer to the data
    - .resize()
    - .Resize() -
    change the size of an array
    - .resize_keep()
    - .resize(true)
    - .Resize(true) -
    - change the size of an array - keep the values -
    - .cleanup()
    - .CleanUp() -
    resize to zero
    - -

     

    - -

    7. Change history

    -

    - next - skip - - up - start -

    -

    Newmat11 - November, 2008:

    -

    - Remove work-arounds for older compilers, Borland Builder 6 and Open Watcom - compatibility, SquareMatrix, load from array of ints, crossproducts, - Cholesky and QRZ update functions, swap functions, FFT2, access to arrays - in traditional C functions, SimpleIntArray class, compatibility with - Numerical Recipes in C++, sum_rows(), sum_columns(), sum_squares_rows() - and sum_squares_columns() functions, extend_orthogonal function, - resize_keep function, speed-ups and bug-fixes, change to lower case for - functions, can copy CroutMatrix, BandLUMatrix, Helmert transform, - compatibility fix for G++ 4.1, start inserting comments for Doxygen, - SP_eq, scientific format for output, fix for 64 bits. -

    -

    Newmat10A - October, 2002, Newmat10B - January 2005:

    -

    - Fix error in Kronecker product; fixes for Intel and GCC3 compilers. -

    -

    Newmat10 - January, 2002:

    -

    - Improve compatibility with GCC, fix errors in FFT and GenericMatrix, - update simulated exceptions, maxima, minima, determinant, dot product and - Frobenius norm functions, update make files for CC and GCC, faster FFT, - A.ReSize(B), fix pointer arithmetic, << for - loading data into rows, IdentityMatrix, Kronecker product, sort singular - values. -

    -

    Newmat09 - September, 1997:

    -

    - Operator ==, !=, +=, -=, *=, - /=, |=, &=. Follow new rules for - for (int i; ... ) construct. Change Boolean, TRUE, FALSE to bool, - true, false. Change ReDimension to ReSize. SubMatrix allows zero rows and - columns. Scalar +, - or * matrix is OK. - Simplify simulated exceptions. Fix non-linear programs for AT&T - compilers. Dummy inequality operators. Improve internal row/column - operations. Improve matrix LU decomposition. Improve sort. Reverse - function. IsSingular function. Fast trig transforms. Namespace - definitions. -

    -

    Newmat08A - July, 1995:

    -

    Fix error in SVD.

    -

    Newmat08 - January, 1995:

    -

    - Corrections to improve compatibility with Gnu, Watcom. Concatenation of - matrices. Elementwise products. Option to use compilers supporting - exceptions. Correction to exception module to allow global declarations of - matrices. Fix problem with inverse of symmetric matrices. Fix - divide-by-zero problem in SVD. Include new QR routines. Sum function. - Non-linear optimisation. GenericMatrices. -

    -

    Newmat07 - January, 1993

    -

    - Minor corrections to improve compatibility with Zortech, Microsoft and - Gnu. Correction to exception module. Additional FFT functions. Some minor - increases in efficiency. Submatrices can now be used on RHS of =. Option - for allowing C type subscripts. Method for loading short lists of numbers. -

    -

    Newmat06 - December 1992:

    -

    - Added band matrices; 'real' changed to 'Real' (to avoid potential conflict - in complex class); Inject doesn't check for no loss of information; fixes - for AT&T C++ version 3.0; real(A) becomes A.AsScalar(); CopyToMatrix - becomes AsMatrix, etc; .c() is no longer required (to be deleted in next - version); option for version 2.1 or later. Suffix for include files - changed to .h; BOOL changed to Boolean (BOOL doesn't work in g++ v 2.0); - modifications to allow for compilers that destroy temporaries very - quickly; (Gnu users - see the section of compilers). Added CleanUp, - LinearEquationSolver, primitive version of exceptions. -

    -

    Newmat05 - June 1992:

    -

    For private release only

    -

    Newmat04 - December 1991:

    -

    Fix problem with G++1.40, some extra documentation

    -

    Newmat03 - November 1991:

    -

    - Col and Cols become Column and Columns. Added Sort, SVD, Jacobi, - Eigenvalues, FFT, real conversion of 1x1 matrix, - Numerical Recipes in C interface, output operations, various scalar - functions. Improved return from functions. Reorganised setting options in - "include.hxx". -

    -

    Newmat02 - July 1991:

    -

    - Version with matrix row/column operations and numerous additional - functions. -

    -

    Matrix - October 1990:

    -

    Early version of package.

    - -

     

    -

    8. Problem report form

    - -

    - next - skip - - up - start -

    - -

    - Copy and paste this to your editor; fill it out and email to robert - at statsresearch.co.nz -

    -

    - But first look in my web page - http://www.robertnz.net to see if - the bug has already been reported. -

    -
    - Version: ............... newmat11 (20 November 2008)
    +
    + +

    which is more complicated and consequently introduces more chance of error. +

    +

    5.12 Error handling +

    +

    next - skip - +up - start

    +

    The library now does have a moderately graceful exit from errors. One can +use either the simulated exceptions or the compiler supported exceptions. When +newmat08 was released (in 1995), compiler exception handling in the compilers I +had access to was unreliable. I recommended you used my simulated exceptions. +In 1997 compiler supported exceptions seemed to work on a variety of +compilers - but not all compilers. This was still true in 2001. One compiler +company was still having problems in 2003 (not sure about 2004). Try using the +compiler supported exceptions if you have a recent compiler, but if you are +getting strange crashes or errors try going back to my simulated exceptions.

    +

    The approach in the present library, attempting to simulate C++ exceptions, +is not completely satisfactory, but seems a good interim solution for those who +cannot use compiler supported exceptions. People who don't want exceptions in +any shape or form, can set the option to exit the program if an exception is +thrown.

    +

    The exception mechanism cannot clean-up objects explicitly created by new. +This must be explicitly carried out by the package writer or the package user. +I have not yet done this completely with the present package so occasionally a +little garbage may be left behind after an exception. I don't think this is a +big problem, but it is one that needs fixing.

    +

    5.13 Sparse matrices

    +

    next - skip - +up - start

    +

    The library does not support sparse matrices.

    +

    For sparse matrices there is going to be some kind of structure vector. It +is going to have to be calculated for the results of expressions in much the +same way that types are calculated. In addition, a whole new set of row and +column operations would have to be written.

    +

    Sparse matrices are important for people solving large sets of differential +equations as well as being important for statistical and operational research +applications.

    +

    But there are packages being developed specifically for sparse matrices and +these might present the best approach, at least where sparse matrices are the +main interest.

    +

    5.14 Complex matrices

    +

    next - skip - +up - start

    +

    The package does not yet support matrices with complex elements. There are +at least two approaches to including these. One is to have matrices with +complex elements.

    +

    This probably means making new versions of the basic row and column +operations for Real*Complex, Complex*Complex, Complex*Real and similarly for ++ and -. This would be OK, except that if I also want to do +this for sparse matrices, then when you put these together, the whole thing +will get out of hand.

    +

    The alternative is to represent a Complex matrix by a pair of Real matrices. +One probably needs another level of decoding expressions but I think it might +still be simpler than the first approach. But there is going to be a problem +with accessing elements and it does not seem possible to solve this in an +entirely satisfactory way.

    +

    Complex matrices are used extensively by electrical engineers and physicists +and really should be fully supported in a comprehensive package.

    +

    You can simulate most complex operations by representing Z = X + iY +by

    +
        /  X   Y \
    +    \ -Y   X / 
    +
    + +

    Most matrix operations will simulate the corresponding complex operation, +when applied to this matrix. But, of course, this matrix is essentially twice as big as you +would need with a genuine complex matrix library.

    + + +

     

    + + +

    6. Function summary

    + + +

    next - skip - +up - start

    + + +

    6.1 Member functions for matrices +and matrix expressions
    +6.2 Member functions for matrices
    +6.3 Operators
    +6.3 Global functions - newmat.h
    +6.4 Global functions - newmatap.h
    +6.5 Other classes - member functions

    + + +

    This section lists member and global functions for matrices defined in +newmat.h. Where there are alternative names the lower-case non-capitalised +versions are the preferred ones.

    + + +

    6.1 Member functions for matrices and matrix expressions

    +

    next - +skip - up - start

    +

    Member functions for matrices and matrix expressions. These do not apply to +CroutMatrix and BandLUMatrix +unless explicitly noted.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    Unary operators

    (see also + operators)

    .t()matrix transpose
    .reverse()
    + .Reverse()
    reverse order of elements (not band matrices)
    .i()invert matrix or solve (also works with CroutMatrix and BandLUMatrix)
    .sum_rows()sum elements in each row
    .sum_columns()sum elements in each column
    .sum_square_rows()sum squares of elements in each row
    .sum_square_columns()sum squares of elements in each column
    Change type.as_row()
    + .AsRow()
    interpret matrix body as a single row
    .as_column()
    + .AsColumn()
    interpret matrix body as a single column
    .as_diagonal()
    + .AsDiagonal()
    interpret matrix body as a diagonal matrix
    .as_matrix()
    + .AsMatrix()
    interpret matrix body as a rectangular matrix
    .as_scalar()
    + .AsScalar()
    convert 1x1 to Real
    Submatrices.submatrix(int,int,int,int)
    + .SubMatrix(int,int,int,int)
    submatrix
    .sym_submatrix(int,int)
    + .SymSubMatrix(int,int)
    submatrix with same row and column range
    .row(int)
    + .Row(int)
    select a row of a matrix
    .rows(int,int)
    + .Rows(int,int)
    select a range of rows of a matrix
    .column(int)
    + .Column(int,int)
    select a column of a matrix
    .columns(int)
    + .Columns(int,int)
    select a range of columns of a matrix
    Scalar functions - maxima & + minima

    (also global versions of maximum(), minimum(),  + maximum_absolute_value(), mimimum_absolute_value())

    .maximum_absolute_value()
    + .
    MaximumAbsoluteValue()
    maximum absolute value of elements
    .maximum_absolute_value1(int&)
    + .MaximumAbsoluteValue1(int&)
    maximum absolute value, return location
    .maximum_absolute_value2(int&,int&)
    + .MaximumAbsoluteValue2(int&,int&)
    maximum absolute value, return location
    .minimum_absolute_value()
    + .MinimumAbsoluteValue()
    minimum absolute value of elements
    .minimum_absolute_value1(int&)
    + .MinimumAbsoluteValue1(int&)
    minimum absolute value, return location
    .minimum_absolute_value2(int&,int&)
    + .MinimumAbsoluteValue2(int&,int&)
    minimum absolute value, return location
    .maximum()
    + .Maximum()
    maximum value of elements
    .maximum1(int&)
    + .Maximum1(int&)
    maximum value, return location
    .maximum2(int&,int&)
    + .Maximum2(int&,int&)
    maximum value, return location
    .minimum()
    + .Minimum()
    minimum value of elements
    .minimum1(int&)
    + .Minimum1(int&)
    minimum value, return location
    .minimum2(int&,int&)
    + .Minimum2(int&,int&)
    minimum value, return location
    Scalar functions - numerical

    + (also global versions of these functions)

    .log_determinant()
    + .LogDeterminant()
    natural logarithm of the determinant (also works with CroutMatrix and BandLUMatrix)
    .determinant()
    + .Determinant()
    determinant (also works with CroutMatrix and BandLUMatrix)
    .sum_square()
    + .SumSquare()
    sum of squares of elements
    .norm_Frobenius()
    + .norm_frobenius()
    + .NormFrobenius()
    square root of sum of squares of elements
    .sum_absolute_value()
    + .SumAbsoluteValue()
    sum of absolute values of elements
    .sum()
    + .Sum()
    sum of elements
    .trace()
    + .Trace()
    trace of a matrix
    .norm1()
    + .Norm1()
    maximum of sum of absolute values of elements of a column
    .norm_infinity()
    + .NormInfinity()
    maximum of sum of absolute values of elements of a row
    Scalar functions - size and shape.bandwidth()
    + .BandWidth()
    bandwidth of matrix (also works with CroutMatrix and BandLUMatrix)
    +

     

    +

    6.2 Member functions for matrices

    +

    next - skip - up - start

    +

    Member functions for matrices but not matrix expressions. These do not apply +to CroutMatrix and BandLUMatrix unless explicitly noted.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    Element access

    (see + also operators)

    .element(int,int)access element - subscripts start at 0
    .element(int)access element - subscripts start at 0
    Copying.inject(const GeneralMatrix&)
    + .Inject(const GeneralMatrix&)
    copy elements into a matrix
    .swap(Matrix&)swap bodies of two matrices of same type (also global + version, also works with CroutMatrix and BandLUMatrix)
    Scalar functions - size and + shape

    (also work with CroutMatrix and BandLUMatrix)

    .type()
    + .Type()
    type of a matrix
    .nrows()
    + .Nrows()
    number of rows
    .ncols()
    + .Ncols()
    number of columns
    .size()
    + .Storage()
    number of stored elements (including unused elements in band + matrices)
    .size2()size of second array (BandLUMatrix only)
    .data()
    + .Store()
    pointer to stored elements
    .const_data()constant pointer to stored elements
    .const_data2()constant pointer to second array (BandLUMatrix only)
    .const_data_indx()constant pointer to row swap array (CroutMatrix and BandLUMatrix + only)
    Scalar functions - numerical.is_zero()
    + .IsZero()
    test all elements are exactly zero (also global version)
    .is_singular()
    + .IsSingular()
    test for exact singularity (CroutMatrix and BandLUMatrix + only)
    .even_exchanges()true if there have been an even number of row exchanges (CroutMatrix and BandLUMatrix + only)
    Memory management.release()
    + .Release()
    release memory after next operation
    .release(int)
    + .Release(int)
    release memory after specified number of operations
    .release_and_delete()
    + .ReleaseAndDelete()
    delete after next operation
    .for_return()
    + .ForReturn()
    place in an envelope for efficient return from a function
    Change dimensions.resize(int)
    + .ReSize(int)
    change the dimensions (vectors and square matrices)
    .resize(int,int)
    + .ReSize(int,int)
    change the dimensions (non-square matrices, triangular band + matrices and symmetric band matrices)
    .resize(int,int,int)
    + .ReSize(int,int,int)
    change the dimensions (band matrices)
    .resize(const GeneralMatrix&)
    + .ReSize(const GeneralMatrix&)
    change dimensions to match those of another matrix
    .cleanup()
    + .CleanUp()
    resize to 0x0
    .resize_keep(int)change the dimensions, keep values (vectors and square matrices, + not band)
    .resize_keep(int,int)change the dimensions , keep values (non-square matrices)
    +

     

    +

    6.3 Operators

    +

    next - +skip - up - start

    +

    Operators for matrices and matrix expressions. These do not apply to CroutMatrix and BandLUMatrix +unless explicitly noted.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    Element access

    + (matrices only, not functions of a matrix)

    ()access element - subscripts start at 1
    ()access element - subscripts start at 1
    []access element C style - subscripts start at zero; if + SETUP_C_SUBSCRIPTS is defined.
    Unary operators-change sign of elements
    Binary operators+, +=add matrices
    -, -=subtract matrices
    *, *=matrix multiplication
    |, |=horizontal concatenation
    &, &=vertical stacking
    ==test for exact equality (also works with CroutMatrix and BandLUMatrix)
    !=test for inequality (i.e. not exact equality, also works with CroutMatrix and BandLUMatrix)
    Matrix and scalar+, +=add Real to matrix
    -, -=subtract Real from matrix; subtract matrix from Real
    *, *=multiply matrix by Real
    /, /=divide matrix by Real
    Copying=copy matrix (error if there is loss of data,  also works with CroutMatrix and BandLUMatrix)
    =copy Real + to all elements
    <<copy matrix (no error if there is loss of data)
    Enter values<<enter list of values into matrix
    Output

    (header in newmatio.h)

    <<print matrix to file
    +

     

    + +

    6.4 Global functions - newmat.h

    +

    next - +skip - +up - start

    +

    Operators for matrices and matrix expressions. These do not apply to CroutMatrix and BandLUMatrix.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    Binary operators

    (see + also operators)

    SP(const BaseMatrix&, const BaseMatrix&)element-wise product of two matrices
    KP(const BaseMatrix&, const BaseMatrix&)Kronecker product of two matrices
    crossproduct(const Matrix&, const Matrix&)
    + CrossProduct(const Matrix&, const Matrix&)
    cross product of two 3x1 or 1x3 matrices or vectors.
    crossproduct_rows(const Matrix&, const Matrix&)
    + CrossProductRows(const Matrix&, const Matrix&)
    row-wise cross product
    crossproduct_columns(const Matrix&, const Matrix&)
    + CrossProductColumns(const Matrix&, const Matrix&)
    column-wise cross product
    Scalar functions - numericaldotproduct(const Matrix&, const Matrix&)
    +
    DotProduct(const Matrix&, const Matrix&)
    dot product of two vectors
    + +

     

    + + +

    6.5 Global functions - newmatap.h

    +

    next - skip - +up - start

    + +

    Advanced operators for matrices and matrix expressions. These do not apply to CroutMatrix and BandLUMatrix.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Function groupfunction namedescription
    QR transformQRZT(Matrix&, LowerTriangularMatrix&)transposed version of QRZ transform
    QRZT(const Matrix&, Matrix&, Matrix&)transposed version of QRZ transform - solve part
    QRZT(Matrix&, Matrix&, LowerTriangularMatrix&, Matrix&)both of previous two lines
    QRZ(Matrix&, UpperTriangularMatrix&)QRZ transform
    QRZ(const Matrix&, Matrix&, Matrix&)QRZ transform - solve part
    QRZ(Matrix&, Matrix&, UpperTriangularMatrix&, Matrix&)both of previous two lines
    updateQRZT(Matrix&, LowerTriangularMatrix&)
    + UpdateQRZT(Matrix&, LowerTriangularMatrix&)
    add extra columns to transposed version of QRZ + transform
    updateQRZ(Matrix&, UpperTriangularMatrix&)
    + UpdateQRZ(Matrix&, UpperTriangularMatrix&)
    add extra rows to QRZ transform
    updateQRZ(const Matrix&, Matrix&, Matrix&)
    + UpdateQRZ(const Matrix&, Matrix&, Matrix&)
    combine the results of the solve parts of QRZ + transforms on two blocks of data
    updateQRZ(UpperTriangularMatrix&, UpperTriangularMatrix&)
    + UpdateQRZ(UpperTriangularMatrix&, UpperTriangularMatrix&)
    combine the results of QRZ transforms on two + blocks of data
    updateQRZ(const UpperTriangularMatrix&, Matrix&, Matrix&)
    + UpdateQRZ(const UpperTriangularMatrix&, Matrix&, Matrix&)
    combine the results of the solve parts of QRZ + transforms on two blocks of data
    Extend orthonormal setextend_orthonormal(Matrix&, int)extend a set of orthonormal columns
    Cholesky + decompositionCholesky(const SymmetricMatrix&)Cholesky decomposition of symmetric matrix
    Cholesky(const SymmetricBandMatrix&)Cholesky decomposition of symmetric band matrix
    Update Cholesky + decompositionupdate_Cholesky (UpperTriangularMatrix&, + RowVector)
    + UpdateCholesky (UpperTriangularMatrix&, + RowVector)
    add extra row to Cholesky/QR decomposition
    downdate_Cholesky (UpperTriangularMatrix&, + RowVector)
    + DowndateCholesky (UpperTriangularMatrix&, + RowVector)
    remove row from Cholesky/QR decomposition
    right_circular_update_Cholesky (UpperTriangularMatrix&, + int, int)
    + RightCircularUpdateCholesky (UpperTriangularMatrix&, + int, int)
    rearrange columns in Cholesky/QR decomposition
    left_circular_update_Cholesky (UpperTriangularMatrix&, + int, int)
    + LeftCircularUpdateCholesky (UpperTriangularMatrix&, + int, int)
    rearrange columns in Cholesky/QR decomposition
    Singular value + decompositionSVD(const Matrix&, DiagonalMatrix&, + Matrix&, Matrix&, bool, bool)singular value decomposition - get U and V
    SVD(const Matrix&, DiagonalMatrix&)SVD decomposition - get just singular values
    SVD(const Matrix& A, DiagonalMatrix& D, + Matrix&, bool)SVD decomposition - get U
    Eigenvalue + decomposition of a symmetric matrixJacobi(const SymmetricMatrix&, + DiagonalMatrix&)Jacobi eigenvalue decomposition - get only eigenvalues
    Jacobi(const SymmetricMatrix&, + DiagonalMatrix&, SymmetricMatrix&)Jacobi eigenvalue decomposition - get only + eigenvalues
    Jacobi(const SymmetricMatrix&, + DiagonalMatrix&, Matrix&)Jacobi eigenvalue decomposition - get + eigenvalues and eigenvectors
    Jacobi(const SymmetricMatrix&, + DiagonalMatrix&, SymmetricMatrix&, Matrix&, bool)Jacobi eigenvalue decomposition - get + eigenvalues and eigenvectors
    eigenvalues(const SymmetricMatrix&, + DiagonalMatrix&)
    + EigenValues(const SymmetricMatrix&, + DiagonalMatrix&)
    Householder eigenvalue decomposition - get only + eigenvalues
    eigenvalues(const SymmetricMatrix&, + DiagonalMatrix&, SymmetricMatrix&)
    + EigenValues(const SymmetricMatrix&, + DiagonalMatrix&, SymmetricMatrix&)
    Householder eigenvalue decomposition with back + transform - get only eigenvalues
    eigenvalues(const SymmetricMatrix&, + DiagonalMatrix&, Matrix&)
    + EigenValues(const SymmetricMatrix&, + DiagonalMatrix&, Matrix&)
    Householder eigenvalue decomposition - get + eigenvalues and eigenvectors
    Sortingsort_ascending(GeneralMatrix&)
    + SortAscending(GeneralMatrix&)
    ascending sort
    sort_descending(GeneralMatrix&)
    + SortDescending(GeneralMatrix&)
    descending sort
    Fast Fourier + transformFFT(const ColumnVector&, const + ColumnVector&, ColumnVector&, ColumnVector&)fast Fourier transform
    FFTI(const ColumnVector&, const + ColumnVector&, ColumnVector&, ColumnVector&)fast Fourier transform - inverse
    RealFFT(const ColumnVector&, ColumnVector&, + ColumnVector&)FFT of real vector
    RealFFTI(const ColumnVector&, const + ColumnVector&, ColumnVector&)FFT of real vector - inverse
    FFT2(const Matrix& U, const Matrix& V, + Matrix& X, Matrix& Y)two dimensional FFT
    FFT2I(const Matrix& U, const Matrix& V, + Matrix& X, Matrix& Y)two dimensional FFT - inverse
    Fast + trigonometric transformDCT_II(const ColumnVector&, ColumnVector&)type II discrete cosine transform
    DCT_II_inverse(const ColumnVector&, + ColumnVector&)type II discrete cosine transform - inverse
    DST_II(const ColumnVector&, ColumnVector&)type II discrete sine transform
    DST_II_inverse(const ColumnVector&, + ColumnVector&)type II discrete sine transform - inverse
    DCT(const ColumnVector&, ColumnVector&)discrete cosine transform
    DCT_inverse(const ColumnVector&, + ColumnVector&)discrete cosine transform - inverse
    DST(const ColumnVector&, ColumnVector&)discrete sine transform
    DST_inverse(const ColumnVector&, + ColumnVector&)discrete sine transform - inverse
    + Helmert transformHelmert(int, bool=false)return Helmert transform matrix
    Helmert(const ColumnVector&, bool=false)
    + Helmert(const Matrix&, bool=false)
    multiply by Helmert transform matrix
    Helmert(int, int, bool=false)return column of Helmert transform matrix
    Helmert_transpose(const ColumnVector&, bool=false)
    + Helmert_transpose(const Matrix&, bool=false)
    multiply by transpose of Helmert transform + matrix
    Helmert_transpose(const ColumnVector&, int, bool=false)multiply by transpose of Helmert transform + matrix, return one element of result
    + +

     

    +

    6.6 Other classes - member functions

    +

    next - skip - +up - start

    + +

     

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Classfunction namedescription
    LogAndSign.pow_eq(int)
    + .PowEq(int)
    raise to a power
    .change_sign()
    + .ChangeSign()
    change sign
    .log_value()
    + .LogValue()
    return the natural logarithm of the value
    .sign()
    + .Sign()
    return the sign
    .value()
    + .Value()
    return the value (no log transform)
    MatrixType.value()
    + .Value()
    return the value (as character string)
    .is_diagonal()has diagonal attribute
    .is_symmetric() has symmetric attribute
    .is_band()has band attribute
    MatrixBandWidth.upper()
    + .Upper()
    return upper band width
    .lower()
    + .Lower()
    return lower bandwidth
    SimpleIntArray.size()
    + .Size()
    return size of array
    .data()
    + .Data()
    return a pointer to the data
    .const_data()return a constant pointer to the data
    .resize()
    + .Resize()
    change the size of an array
    .resize_keep()
    + .resize(true)
    + .Resize(true)
    change the size of an array - keep the values
    .cleanup()
    + .CleanUp()
    resize to zero
    + + +

     

    + + +

    7. Change history

    +

    next - skip - +up - start

    +

    Newmat11 - November, 2008:

    +

    Remove work-arounds for older compilers, Borland Builder 6 and +Open Watcom compatibility, SquareMatrix, +load from array of ints, crossproducts, Cholesky and QRZ update functions, swap +functions, FFT2, access to arrays in traditional C functions, SimpleIntArray +class, compatibility with Numerical Recipes in C++, sum_rows(), sum_columns(), sum_squares_rows() and +sum_squares_columns() functions, extend_orthogonal function, resize_keep +function, speed-ups and +bug-fixes, change to lower case for functions, can copy CroutMatrix, +BandLUMatrix, Helmert transform, compatibility fix for G++ 4.1, start inserting +comments for Doxygen, SP_eq, scientific format for output, fix for 64 bits.

    +

    Newmat10A - October, 2002, Newmat10B - January 2005:

    +

    Fix error in Kronecker product; fixes for Intel and GCC3 +compilers.

    +

    Newmat10 - January, 2002:

    +

    Improve compatibility with GCC, fix errors in FFT and +GenericMatrix, update simulated exceptions, maxima, minima, determinant, dot +product and Frobenius norm functions, update make files for CC and GCC, faster +FFT, A.ReSize(B), fix pointer arithmetic, << for loading +data into rows, IdentityMatrix, Kronecker product, sort singular values.

    +

    Newmat09 - September, 1997:

    +

    Operator ==, !=, +=, -=, +*=, /=, |=, &=. Follow new rules for +for (int i; ... ) construct. Change Boolean, TRUE, FALSE to bool, true, +false. Change ReDimension to ReSize. SubMatrix allows zero rows and columns. +Scalar +, - or * matrix is OK. Simplify simulated +exceptions. Fix non-linear programs for AT&T compilers. Dummy inequality +operators. Improve internal row/column operations. Improve matrix LU +decomposition. Improve sort. Reverse function. IsSingular function. Fast trig +transforms. Namespace definitions.

    +

    Newmat08A - July, 1995:

    +

    Fix error in SVD.

    +

    Newmat08 - January, 1995:

    +

    Corrections to improve compatibility with Gnu, Watcom. +Concatenation of matrices. Elementwise products. Option to use compilers +supporting exceptions. Correction to exception module to allow global +declarations of matrices. Fix problem with inverse of symmetric matrices. Fix +divide-by-zero problem in SVD. Include new QR routines. Sum function. +Non-linear optimisation. GenericMatrices.

    +

    Newmat07 - January, 1993

    +

    Minor corrections to improve compatibility with Zortech, +Microsoft and Gnu. Correction to exception module. Additional FFT functions. +Some minor increases in efficiency. Submatrices can now be used on RHS of =. +Option for allowing C type subscripts. Method for loading short lists of +numbers.

    +

    Newmat06 - December 1992:

    +

    Added band matrices; 'real' changed to 'Real' (to avoid +potential conflict in complex class); Inject doesn't check for no loss of +information; fixes for AT&T C++ version 3.0; real(A) becomes A.AsScalar(); +CopyToMatrix becomes AsMatrix, etc; .c() is no longer required (to be deleted +in next version); option for version 2.1 or later. Suffix for include files +changed to .h; BOOL changed to Boolean (BOOL doesn't work in g++ v 2.0); +modifications to allow for compilers that destroy temporaries very quickly; +(Gnu users - see the section of compilers). Added CleanUp, +LinearEquationSolver, primitive version of exceptions.

    +

    Newmat05 - June 1992:

    +

    For private release only

    +

    Newmat04 - December 1991:

    +

    Fix problem with G++1.40, some extra documentation +

    +

    Newmat03 - November 1991:

    +

    Col and Cols become Column and Columns. Added Sort, SVD, +Jacobi, Eigenvalues, FFT, real conversion of 1x1 matrix, Numerical Recipes +in C interface, output operations, various scalar functions. Improved +return from functions. Reorganised setting options in "include.hxx". +

    +

    Newmat02 - July 1991:

    +

    Version with matrix row/column operations and numerous +additional functions.

    +

    Matrix - October 1990:

    +

    Early version of package.

    + +

     

    +

    8. Problem report form +

    + +

    next - skip - up - +start

    + +

    Copy and paste this to your editor; fill it out and email to robert at statsresearch.co.nz

    +

    But first look in my web page +http://www.robertnz.net to see if the bug has +already been reported.

    +
     Version: ............... newmat11 (20 November 2008)
      Your email address: ....
      Today's date: ..........
      Your machine: ..........
    @@ -7063,25 +5124,22 @@ 

    8. Problem report form

    -
    +
    -
    ------------------------------------------------------------
    -
    +
    -----------------------------------------------------------
    +
    + +

     

    -

     

    - -

     

    -

    - return to top
    - return to online documentation page -

    -

     

    -

     

    -

     

    -

     

    -

     

    -

     

    -

     

    - - +

     

    +

    return to top
    +return to online documentation page

    +

     

    +

     

    +

     

    +

     

    +

     

    +

     

    +

     

    + + \ No newline at end of file diff --git a/extern/newmat/nm_b55.mak b/extern/newmat/nm_b55.mak index 98911c2..c7c4503 100644 --- a/extern/newmat/nm_b55.mak +++ b/extern/newmat/nm_b55.mak @@ -14,7 +14,7 @@ CC = bcc32 -W- -v- -H- -3 -N -Og -Oi -Ov -f -I$(INCLUDEPATH) .cpp.obj: $(CC) -c {$< } -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -231,3 +231,4 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_b56.mak b/extern/newmat/nm_b56.mak index 0a372d3..8414f19 100644 --- a/extern/newmat/nm_b56.mak +++ b/extern/newmat/nm_b56.mak @@ -14,7 +14,7 @@ CC = bcc32 -W- -v- -H- -6 -Og -Oi -Ov -I$(INCLUDEPATH) .cpp.obj: $(CC) -c {$< } -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -231,3 +231,4 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_cc.mak b/extern/newmat/nm_cc.mak index 84e7800..cb3a735 100644 --- a/extern/newmat/nm_cc.mak +++ b/extern/newmat/nm_cc.mak @@ -10,11 +10,11 @@ PRE = ./ .cpp.o: rm -f $*.cxx - ln $*.cpp $*.cxx + ln $*.cpp $*.cxx $(CXX) $(CXXFLAGS) -c $*.cxx - rm $*.cxx + rm $*.cxx -everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch +everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch newmat_lobj = newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o newmat6.o newmat7.o newmat8.o newmatex.o bandmat.o submat.o myexcept.o cholesky.o evalue.o fft.o hholder.o jacobi.o newfft.o sort.o svd.o nm_misc.o newmatrm.o newmat9.o @@ -214,3 +214,4 @@ sl_ex.txx: sl_ex garch.txx: garch $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_ex1.cpp b/extern/newmat/nm_ex1.cpp index 28b7d66..05bb45c 100644 --- a/extern/newmat/nm_ex1.cpp +++ b/extern/newmat/nm_ex1.cpp @@ -11,7 +11,7 @@ // should not be required for this example // included because it seems to help MS VC6 // when you have namespace turned on - + #include "newmatio.h" // newmat headers including output functions #ifdef use_namespace @@ -25,7 +25,7 @@ int my_main() // called by main() // declare a matrix Matrix X(4,4); - + // load values row by row X.row(1) << 3.7 << -2.1 << 7.4 << -1.0; X.row(2) << 4.1 << 0.0 << 3.9 << 4.0; @@ -35,16 +35,16 @@ int my_main() // called by main() // print the matrix cout << "Matrix X" << endl; cout << setw(15) << setprecision(8) << X << endl; - + // calculate its inverse and print it Matrix Y = X.i(); cout << "Inverse of X" << endl; cout << setw(15) << setprecision(8) << Y << endl; - + // multiply X by its inverse and print the result (should be near identity) cout << "X * inverse of X" << endl; cout << setw(15) << setprecision(8) << (X * Y) << endl; - + return 0; } @@ -60,3 +60,4 @@ int main() } ///@} + diff --git a/extern/newmat/nm_ex1.txt b/extern/newmat/nm_ex1.txt index 1ba448a..53eab14 100644 --- a/extern/newmat/nm_ex1.txt +++ b/extern/newmat/nm_ex1.txt @@ -1,17 +1,18 @@ Matrix X - 3.70000000 -2.10000000 7.40000000 -1.00000000 - 4.10000000 0.00000000 3.90000000 4.00000000 - -2.50000000 1.90000000 -0.40000000 7.30000000 - 1.50000000 9.80000000 -2.10000000 1.10000000 + 3.70000000 -2.10000000 7.40000000 -1.00000000 + 4.10000000 0.00000000 3.90000000 4.00000000 + -2.50000000 1.90000000 -0.40000000 7.30000000 + 1.50000000 9.80000000 -2.10000000 1.10000000 Inverse of X - -0.15613535 0.27856000 -0.17406776 0.00029026 - 0.07956310 -0.08691703 0.04180094 0.11098579 - 0.22744144 -0.14910111 0.10868682 0.02766552 - -0.06171667 0.10984958 0.07244980 -0.02727139 + -0.15613535 0.27856000 -0.17406776 0.00029026 + 0.07956310 -0.08691703 0.04180094 0.11098579 + 0.22744144 -0.14910111 0.10868682 0.02766552 + -0.06171667 0.10984958 0.07244980 -0.02727139 X * inverse of X - 1.00000000 -0.00000000 0.00000000 0.00000000 - 0.00000000 1.00000000 0.00000000 0.00000000 - -0.00000000 -0.00000000 1.00000000 -0.00000000 - -0.00000000 0.00000000 0.00000000 1.00000000 + 1.00000000 -0.00000000 0.00000000 0.00000000 + 0.00000000 1.00000000 0.00000000 0.00000000 + -0.00000000 -0.00000000 1.00000000 -0.00000000 + -0.00000000 0.00000000 0.00000000 1.00000000 + diff --git a/extern/newmat/nm_ex2.cpp b/extern/newmat/nm_ex2.cpp index 339e822..d0887a8 100644 --- a/extern/newmat/nm_ex2.cpp +++ b/extern/newmat/nm_ex2.cpp @@ -12,7 +12,7 @@ /// /// The dimensions of this matrix are not large enough for there to be numerical /// problems but we will be able to see that wide range of values of the -/// eigenvalues. +/// eigenvalues. #define WANT_STREAM // include iostream and iomanipulators @@ -27,13 +27,13 @@ using namespace RBD_LIBRARIES; int my_main() // called by main() { Tracer tr("my_main "); // for tracking exceptions - + int n = 7; // this is the order we will work with int i, j; // declare a matrix SymmetricMatrix H(n); - + // load values for Hilbert matrix for (i = 1; i <= n; ++i) for (j = 1; j <= i; ++j) H(i, j) = 1.0 / (i + j - 1); @@ -41,7 +41,7 @@ int my_main() // called by main() // print the matrix cout << "SymmetricMatrix H" << endl; cout << setw(10) << setprecision(7) << H << endl; - + // calculate its eigenvalues and eigenvectors and print them Matrix U; DiagonalMatrix D; eigenvalues(H, D, U); @@ -51,13 +51,13 @@ int my_main() // called by main() cout << setw(10) << setprecision(7) << U << endl; // check orthogonality - cout << "U * U.t() (should be near identity)" << endl; + cout << "U * U.t() (should be near identity)" << endl; cout << setw(10) << setprecision(7) << (U * U.t()) << endl; - + // check decomposition - cout << "U * D * U.t() (should be near H)" << endl; + cout << "U * D * U.t() (should be near H)" << endl; cout << setw(10) << setprecision(7) << (U * D * U.t()) << endl; - + return 0; } diff --git a/extern/newmat/nm_ex2.txt b/extern/newmat/nm_ex2.txt index ed50a87..fb98822 100644 --- a/extern/newmat/nm_ex2.txt +++ b/extern/newmat/nm_ex2.txt @@ -1,44 +1,45 @@ SymmetricMatrix H - 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 - 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 - 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 - 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 - 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 - 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 - 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 + 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 + 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 + 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 + 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 + 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 + 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 + 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 Eigenvalues of H - 0.00000000349390 - 0.00000048567634 - 0.00002938636815 - 0.00100858761077 - 0.02128975490833 - 0.27192019814935 - 1.66088533892693 + 0.00000000349390 + 0.00000048567634 + 0.00002938636815 + 0.00100858761077 + 0.02128975490833 + 0.27192019814935 + 1.66088533892693 Eigenvector matrix, U - 0.0002451 -0.0024687 0.0159939 -0.0751873 0.2608426 0.6232385 -0.7332256 --0.0098386 0.0617968 -0.2279023 0.5267775 -0.6705585 -0.1630715 -0.4363592 - 0.0951956 -0.3486749 0.6287534 -0.4256562 -0.2953295 -0.3215141 -0.3197791 --0.3713200 0.6446867 -0.2003656 -0.4616761 0.0230466 -0.3573674 -0.2548856 - 0.6825295 -0.1743885 -0.4970150 -0.1711955 0.2336876 -0.3570683 -0.2128441 --0.5910349 -0.5436283 -0.1848709 0.1826645 0.3678759 -0.3445700 -0.1831431 - 0.1944058 0.3647422 0.4807560 0.5097549 0.4523486 -0.3281347 -0.1609397 + 0.0002451 -0.0024687 0.0159939 -0.0751873 0.2608426 0.6232385 -0.7332256 +-0.0098386 0.0617968 -0.2279023 0.5267775 -0.6705585 -0.1630715 -0.4363592 + 0.0951956 -0.3486749 0.6287534 -0.4256562 -0.2953295 -0.3215141 -0.3197791 +-0.3713200 0.6446867 -0.2003656 -0.4616761 0.0230466 -0.3573674 -0.2548856 + 0.6825295 -0.1743885 -0.4970150 -0.1711955 0.2336876 -0.3570683 -0.2128441 +-0.5910349 -0.5436283 -0.1848709 0.1826645 0.3678759 -0.3445700 -0.1831431 + 0.1944058 0.3647422 0.4807560 0.5097549 0.4523486 -0.3281347 -0.1609397 U * U.t() (should be near identity) - 1.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 -0.0000000 0.0000000 --0.0000000 1.0000000 0.0000000 -0.0000000 -0.0000000 -0.0000000 0.0000000 --0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 -0.0000000 -0.0000000 - 0.0000000 -0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 --0.0000000 -0.0000000 0.0000000 0.0000000 1.0000000 -0.0000000 0.0000000 --0.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 1.0000000 0.0000000 - 0.0000000 0.0000000 -0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 + 1.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 -0.0000000 0.0000000 +-0.0000000 1.0000000 0.0000000 -0.0000000 -0.0000000 -0.0000000 0.0000000 +-0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 -0.0000000 -0.0000000 + 0.0000000 -0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 +-0.0000000 -0.0000000 0.0000000 0.0000000 1.0000000 -0.0000000 0.0000000 +-0.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 1.0000000 0.0000000 + 0.0000000 0.0000000 -0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 U * D * U.t() (should be near H) - 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 - 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 - 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 - 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 - 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 - 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 - 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 + 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 + 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 + 0.3333333 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 + 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 + 0.2000000 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 + 0.1666667 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 + 0.1428571 0.1250000 0.1111111 0.1000000 0.0909091 0.0833333 0.0769231 + diff --git a/extern/newmat/nm_ex3.cpp b/extern/newmat/nm_ex3.cpp index a5fb9ed..8c3309f 100644 --- a/extern/newmat/nm_ex3.cpp +++ b/extern/newmat/nm_ex3.cpp @@ -28,24 +28,24 @@ int my_main() // called by main() cout << "Minimum " << FloatingPointPrecision::Minimum() << endl; cout << "LnMinimum " << FloatingPointPrecision::LnMinimum() << endl; cout << endl; - + ColumnVector values(5), sel_values(4); - + values(1) = sel_values(1) = FloatingPointPrecision::Epsilon(); values(2) = FloatingPointPrecision::Maximum(); values(3) = sel_values(2) = FloatingPointPrecision::LnMaximum(); values(4) = sel_values(3) = FloatingPointPrecision::Minimum(); values(5) = sel_values(4) = FloatingPointPrecision::LnMinimum(); - + cout << "Load values into a ColumnVector and print in scientific format" << endl << endl; cout << "Values in scientific format" << endl; cout << setw(15) << setprecision(5) << scientific << values << endl; - + cout << "Print in fixed format" << endl << endl; cout << "Selected values in fixed format (omit Maximum)" << endl; cout << setw(15) << setprecision(5) << fixed << sel_values << endl; - + cout << "Test Epsilon" << endl << endl; Real x = 1.0 + FloatingPointPrecision::Epsilon(); cout << "This value should be non-zero" << endl; @@ -56,7 +56,7 @@ int my_main() // called by main() cout << "(1.0 + Epsilon / 2) - 1.0" << setw(15) << setprecision(5) << scientific << (Real)(x - 1.0) << endl; cout << endl; - + cout << "Test Minimum" << endl << endl; cout << "This value should be non-zero" << endl; cout << "Minimum " << setw(15) << setprecision(5) << @@ -70,11 +70,11 @@ int my_main() // called by main() cout << "Minimum * Epsilon / 2.0 " << setw(15) << setprecision(5) << scientific << x << endl; cout << endl; - + cout << "Test LnMaximum and LnMinimum" << endl << endl; x = exp(FloatingPointPrecision::LnMaximum()); cout << "This should print a value close to Maximum" << endl; - cout << "Fails with some compilers - needs fixing" << endl; + cout << "Fails with some compilers - needs fixing" << endl; cout << "exp(LnMaximum) " << setw(15) << setprecision(5) << scientific << x << endl; x = exp(FloatingPointPrecision::LnMinimum()); @@ -82,9 +82,9 @@ int my_main() // called by main() cout << "exp(LnMinimum) " << setw(15) << setprecision(5) << scientific << x << endl; cout << endl; - - - + + + return 0; } @@ -100,3 +100,4 @@ int main() } ///@} + diff --git a/extern/newmat/nm_ex3.txt b/extern/newmat/nm_ex3.txt index 73b95fe..6bb79ff 100644 --- a/extern/newmat/nm_ex3.txt +++ b/extern/newmat/nm_ex3.txt @@ -10,19 +10,19 @@ LnMinimum -708.396 Load values into a ColumnVector and print in scientific format Values in scientific format - 2.22045e-016 - 1.79769e+308 - 7.09783e+002 - 2.22507e-308 - -7.08396e+002 + 2.22045e-016 + 1.79769e+308 + 7.09783e+002 + 2.22507e-308 + -7.08396e+002 Print in fixed format Selected values in fixed format (omit Maximum) - 0.00000 - 709.78271 - 0.00000 - -708.39642 + 0.00000 + 709.78271 + 0.00000 + -708.39642 Test Epsilon @@ -47,3 +47,4 @@ Fails with some compilers - needs fixing exp(LnMaximum) 1.79769e+308 This should print a value close to Minimum, not zero exp(LnMinimum) 2.22507e-308 + diff --git a/extern/newmat/nm_gnu.mak b/extern/newmat/nm_gnu.mak index 7441f0b..aca0335 100644 --- a/extern/newmat/nm_gnu.mak +++ b/extern/newmat/nm_gnu.mak @@ -9,7 +9,7 @@ MINOR = 0 %.o: %.cpp $(CXX) $(CXXFLAGS) -c $*.cpp -everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch +everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch newmat_lobj = newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o newmat6.o newmat7.o newmat8.o newmatex.o bandmat.o submat.o myexcept.o cholesky.o evalue.o fft.o hholder.o jacobi.o newfft.o sort.o svd.o nm_misc.o newmatrm.o newmat9.o @@ -209,3 +209,4 @@ sl_ex.txx: sl_ex garch.txx: garch $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_i10.mak b/extern/newmat/nm_i10.mak index 08b476e..6fcf660 100644 --- a/extern/newmat/nm_i10.mak +++ b/extern/newmat/nm_i10.mak @@ -1,5 +1,5 @@ -conlibs = +conlibs = DIFF = sdiff PRE = @@ -9,7 +9,7 @@ PRE = .cpp.obj: icl -c -GX -GR -Ge -GS -Qprec -Qprec_div -nologo -Qlong_double $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,3 +208,4 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_i8.mak b/extern/newmat/nm_i8.mak index f8a0602..30b36ba 100644 --- a/extern/newmat/nm_i8.mak +++ b/extern/newmat/nm_i8.mak @@ -9,7 +9,7 @@ PRE = .cpp.obj: icl -c -GX -GR -Ge -GS -Qprec -Qprec_div -nologo -Qlong_double $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,3 +208,4 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_il8.mak b/extern/newmat/nm_il8.mak index c5f49d5..4d17412 100644 --- a/extern/newmat/nm_il8.mak +++ b/extern/newmat/nm_il8.mak @@ -9,7 +9,7 @@ MINOR = 0 %.o: %.cpp $(CXX) $(CXXFLAGS) -c $*.cpp -everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch +everything: tmt example nm_ex1 nm_ex2 nm_ex3 test_exc nl_ex sl_ex garch newmat_lobj = newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o newmat6.o newmat7.o newmat8.o newmatex.o bandmat.o submat.o myexcept.o cholesky.o evalue.o fft.o hholder.o jacobi.o newfft.o sort.o svd.o nm_misc.o newmatrm.o newmat9.o @@ -209,3 +209,4 @@ sl_ex.txx: sl_ex garch.txx: garch $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_m6.mak b/extern/newmat/nm_m6.mak index 036d432..97931f3 100644 --- a/extern/newmat/nm_m6.mak +++ b/extern/newmat/nm_m6.mak @@ -9,7 +9,7 @@ PRE = .cpp.obj: cl -c -W3 -Ox -GX $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,3 +208,4 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_m8.mak b/extern/newmat/nm_m8.mak index a56efa3..5b29da9 100644 --- a/extern/newmat/nm_m8.mak +++ b/extern/newmat/nm_m8.mak @@ -9,7 +9,7 @@ PRE = .cpp.obj: cl -c -W3 -Ox -EHsc $*.cpp -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -208,3 +208,4 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/nm_misc.cpp b/extern/newmat/nm_misc.cpp index 10116d2..611aaad 100644 --- a/extern/newmat/nm_misc.cpp +++ b/extern/newmat/nm_misc.cpp @@ -27,7 +27,7 @@ ReturnMatrix Helmert(int n, bool full) Tracer et("Helmert "); if (n <= 0) Throw(ProgramException("Dimension <= 0 ")); Matrix H; - + if (full) H.resize(n,n); else H.resize(n-1,n); H = 0.0; for (int i = 1; i < n; ++i) @@ -37,7 +37,7 @@ ReturnMatrix Helmert(int n, bool full) } if (full) { H.row(n) = 1.0 / sqrt((Real)n); } H.release(); return H.for_return(); -} +} @@ -55,7 +55,7 @@ ReturnMatrix Helmert(const ColumnVector& X, bool full) { sum += X(i); Y(i) = (i * X(i+1) - sum) / sqrt((Real)i * (i+1)); } if (full) { sum += X(n); Y(n) = sum / sqrt((Real)n); } Y.release(); return Y.for_return(); -} +} // same as above for X a ColumnVector, length n, element j = 1; otherwise 0 ReturnMatrix Helmert(int n, int j, bool full) @@ -71,7 +71,7 @@ ReturnMatrix Helmert(int n, int j, bool full) for (int i = j; i < n; ++i) Y(i) = - 1.0 / sqrt((Real)i * (i+1)); if (full) Y(n) = 1.0 / sqrt((Real)n); Y.release(); return Y.for_return(); -} +} ReturnMatrix Helmert_transpose(const ColumnVector& Y, bool full) { diff --git a/extern/newmat/nm_ow.mak b/extern/newmat/nm_ow.mak index 6c3af9a..0e69d23 100644 --- a/extern/newmat/nm_ow.mak +++ b/extern/newmat/nm_ow.mak @@ -8,7 +8,7 @@ PRE = -everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe +everything: tmt.exe example.exe nm_ex1.exe nm_ex2.exe nm_ex3.exe test_exc.exe nl_ex.exe sl_ex.exe garch.exe newmat_lobj = newmat1.obj newmat2.obj newmat3.obj newmat4.obj newmat5.obj newmat6.obj newmat7.obj newmat8.obj newmatex.obj bandmat.obj submat.obj myexcept.obj cholesky.obj evalue.obj fft.obj hholder.obj jacobi.obj newfft.obj sort.obj svd.obj nm_misc.obj newmatrm.obj newmat9.obj @@ -209,3 +209,4 @@ sl_ex.txx: sl_ex.exe garch.txx: garch.exe $(PRE)garch > garch.txx $(DIFF) garch.txt garch.txx + diff --git a/extern/newmat/precisio.h b/extern/newmat/precisio.h index e22a1e3..141e155 100644 --- a/extern/newmat/precisio.h +++ b/extern/newmat/precisio.h @@ -25,7 +25,7 @@ namespace NEWMAT { #endif using namespace std; - + /// Floating point precision. class FloatingPointPrecision { @@ -52,7 +52,7 @@ class FloatingPointPrecision { return (Real)log(Maximum()); } static Real Minimum() // minimum positive value - { return numeric_limits::min(); } + { return numeric_limits::min(); } static int MinimumDecimalExponent() // minimum decimal exponent { return numeric_limits::min_exponent10; } diff --git a/extern/newmat/rbd.css b/extern/newmat/rbd.css index 5aaf4fb..d512592 100644 --- a/extern/newmat/rbd.css +++ b/extern/newmat/rbd.css @@ -1,80 +1,20 @@ /* Style sheet - if you are saving my html files, please also save this file as rbd.css */ -h1 { - font-family: Arial, Helvetica, sans-serif; - font-size: 20pt; - color: maroon; -} -h2 { - font-family: Arial, Helvetica, sans-serif; - font-size: 16pt; - color: maroon; -} -h3 { - font-family: Arial, Helvetica, sans-serif; - font-size: 14pt; - color: maroon; -} -h4 { - font-family: Arial, Helvetica, sans-serif; - font-size: 12pt; - color: maroon; -} -body { - font-family: "Times New Roman", Times, serif; - background-color: white; -} -body.gray { - font-family: "Times New Roman", Times, serif; - background-color: #cccccc; -} -p { - font-family: "Times New Roman", Times, serif; - margin-top: 8; - margin-bottom: 8; -} -p.small { - font-family: "Times New Roman", Times, serif; - font-size: 10pt; - margin-top: 8; - margin-bottom: 8; -} -ul { - line-height: 100%; - margin-top: 2; - margin-bottom: 2; -} -li { - margin-top: 2; - margin-bottom: 2; - font-size: 10pt; -} -tt { - font-family: "Courier New", Courier, monospaced; - font-size: 10pt; -} -pre { - font-family: "Courier New", Courier, monospaced; - font-size: 10pt; -} -pre.small { - font-family: "Courier New", Courier, monospaced; - font-size: 8pt; -} -hr { - color: maroon; -} -a:link { - color: blue; -} -a:visited { - color: green; -} -a:active { - color: red; -} -table { - font-size: 10pt; -} -.question { - color: navy; -} +h1 { font-family: Arial, Helvetica, sans-serif; font-size: 20pt; color: maroon } +h2 { font-family: Arial, Helvetica, sans-serif; font-size: 16pt; color: maroon } +h3 { font-family: Arial, Helvetica, sans-serif; font-size: 14pt; color: maroon } +h4 { font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: maroon } +body { font-family: "Times New Roman", Times, serif; background-color: white } +body.gray { font-family: "Times New Roman", Times, serif; background-color: #CCCCCC } +p { font-family: "Times New Roman", Times, serif; margin-top: 8; margin-bottom: 8 } +p.small { font-family: "Times New Roman", Times, serif; font-size: 10pt; margin-top: 8; margin-bottom: 8 } +ul { line-height: 100%; margin-top: 2; margin-bottom: 2 } +li { margin-top: 2; margin-bottom: 2; font-size: 10pt } +tt { font-family: "Courier New", Courier, monospaced; font-size: 10pt } +pre { font-family: "Courier New", Courier, monospaced; font-size: 10pt } +pre.small { font-family: "Courier New", Courier, monospaced; font-size: 8pt } +hr { color: maroon } +a:link { color: blue } +a:visited { color: green } +a:active { color: red } +table { font-size: 10pt } +.question { color: navy; } \ No newline at end of file diff --git a/extern/newmat/readme.txt b/extern/newmat/readme.txt index f6aad1b..0293c78 100644 --- a/extern/newmat/readme.txt +++ b/extern/newmat/readme.txt @@ -8,3 +8,5 @@ Documentation is in nm11.htm. This library is freeware. See the documentation for details. To contact the author please email robert@statsresearch.co.nz + + diff --git a/extern/newmat/sl_ex.cpp b/extern/newmat/sl_ex.cpp index 599f3a3..485b6e2 100644 --- a/extern/newmat/sl_ex.cpp +++ b/extern/newmat/sl_ex.cpp @@ -3,7 +3,7 @@ /// \file sl_ex.cpp /// Test one-dimensional solve function. -/// This is an example of the use of solution to find the cube root of +/// This is an example of the use of solution to find the cube root of /// the integers -10 to 10 /// /// you will need to compile and link solution.cpp and my_except.cpp @@ -50,7 +50,7 @@ int main() } CatchAll { - cout << "\nProgram fails - exception generated\n\n"; + cout << "\nProgram fails - exception generated\n\n"; } return 0; } diff --git a/extern/newmat/solution.h b/extern/newmat/solution.h index cfcbb61..b752e18 100644 --- a/extern/newmat/solution.h +++ b/extern/newmat/solution.h @@ -96,3 +96,4 @@ class OneDimSolve ///@} + diff --git a/extern/newmat/submat.cpp b/extern/newmat/submat.cpp index 2074f5c..f3cc95d 100644 --- a/extern/newmat/submat.cpp +++ b/extern/newmat/submat.cpp @@ -256,7 +256,7 @@ void GetSubMatrix::operator+=(const BaseMatrix& bmx) SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate(); if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) Throw(IncompatibleDimensionsException()); - if (gm->type().is_symmetric() && + if (gm->type().is_symmetric() && ( ! gmx->type().is_symmetric() || row_skip != col_skip) ) Throw(ProgramException("Illegal operation on symmetric")); MatrixRow mrx(gmx, LoadOnEntry); @@ -289,7 +289,7 @@ void GetSubMatrix::SP_eq(const BaseMatrix& bmx) SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate(); if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) Throw(IncompatibleDimensionsException()); - if (gm->type().is_symmetric() && + if (gm->type().is_symmetric() && ( ! gmx->type().is_symmetric() || row_skip != col_skip) ) Throw(ProgramException("Illegal operation on symmetric")); MatrixRow mrx(gmx, LoadOnEntry); @@ -321,7 +321,7 @@ void GetSubMatrix::operator-=(const BaseMatrix& bmx) SetUpLHS(); gmx = ((BaseMatrix&)bmx).Evaluate(); if (row_number != gmx->Nrows() || col_number != gmx->Ncols()) Throw(IncompatibleDimensionsException()); - if (gm->type().is_symmetric() && + if (gm->type().is_symmetric() && ( ! gmx->type().is_symmetric() || row_skip != col_skip) ) Throw(ProgramException("Illegal operation on symmetric")); MatrixRow mrx(gmx, LoadOnEntry); @@ -398,3 +398,4 @@ void GetSubMatrix::operator*=(Real r) #endif ///@} + diff --git a/extern/newmat/test_exc.txt b/extern/newmat/test_exc.txt index a836b35..a0be211 100644 --- a/extern/newmat/test_exc.txt +++ b/extern/newmat/test_exc.txt @@ -34,7 +34,7 @@ Illegal conversion An exception has been thrown Logic error:- detected by Newmat: Illegal Conversion -MatrixTypes = Rect ; UT +MatrixTypes = Rect ; UT Trace: Block C; Test. @@ -207,3 +207,4 @@ compilers - see documentation) Checking for lost memory (large block): 9191360 9191360 - ok Checking for lost memory (small block): 9191360 9191360 - ok + diff --git a/extern/newmat/tmt.cpp b/extern/newmat/tmt.cpp index db25ce9..3b4af85 100644 --- a/extern/newmat/tmt.cpp +++ b/extern/newmat/tmt.cpp @@ -194,21 +194,21 @@ void FillWithValues(MultWithCarry&MWC, Matrix& M) for (int i = 1; i <= nr; ++i) for (int j = 1; j <= nc; ++ j) M(i, j) = MWC.Next(); } - + void FillWithValues(MultWithCarry&MWC, UpperTriangularMatrix& M) { int nr = M.nrows(); for (int i = 1; i <= nr; ++i) for (int j = i; j <= nr; ++ j) M(i, j) = MWC.Next(); } - + void FillWithValues(MultWithCarry&MWC, LowerTriangularMatrix& M) { int nr = M.nrows(); for (int i = 1; i <= nr; ++i) for (int j = 1; j <= i; ++ j) M(i, j) = MWC.Next(); } - + void FillWithValues(MultWithCarry&MWC, DiagonalMatrix& M) { int nr = M.nrows(); @@ -222,8 +222,8 @@ void FillWithValues(MultWithCarry&MWC, SymmetricMatrix& M) for (int i = 1; i <= nr; ++i) for (int j = 1; j <= i; ++ j) M(i, j) = MWC.Next(); } - - + + #ifdef use_namespace } @@ -271,8 +271,8 @@ int main() TestTypeAdd(); TestTypeMult(); TestTypeConcat(); TestTypeSP(); TestTypeKP(); TestTypeOrder(); - - Try { + + Try { trymat1(); trymat2(); trymat3(); @@ -554,3 +554,6 @@ time_lapse::~time_lapse() ///@} + + + diff --git a/extern/newmat/tmt.h b/extern/newmat/tmt.h index d930545..4233d6d 100644 --- a/extern/newmat/tmt.h +++ b/extern/newmat/tmt.h @@ -38,11 +38,11 @@ class MultWithCarry }; // fill a matrix with values from the MultWithCarry random number generator -void FillWithValues(MultWithCarry& MWC, Matrix& M); -void FillWithValues(MultWithCarry& MWC, UpperTriangularMatrix& M); -void FillWithValues(MultWithCarry& MWC, LowerTriangularMatrix& M); -void FillWithValues(MultWithCarry& MWC, DiagonalMatrix& M); -void FillWithValues(MultWithCarry& MWC, SymmetricMatrix& M); +void FillWithValues(MultWithCarry& MWC, Matrix& M); +void FillWithValues(MultWithCarry& MWC, UpperTriangularMatrix& M); +void FillWithValues(MultWithCarry& MWC, LowerTriangularMatrix& M); +void FillWithValues(MultWithCarry& MWC, DiagonalMatrix& M); +void FillWithValues(MultWithCarry& MWC, SymmetricMatrix& M); void Print(const Matrix& X); diff --git a/extern/newmat/tmt.txt b/extern/newmat/tmt.txt index 5017be0..76a79f7 100644 --- a/extern/newmat/tmt.txt +++ b/extern/newmat/tmt.txt @@ -4,97 +4,97 @@ Now print a real number: 3.14159 Matrix type: Rect (1, 8) -0 0 0 0 0 0 0 1 - -+ UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ -LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Sym Squ Squ Rect Squ Sym Squ Sym Sym Squ Squ Squ Sym Squ -Skew Squ Squ Rect Squ Squ Skew Squ Squ Squ Squ Squ Squ Skew -Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band -Ident UT LT Rect Squ Sym Squ Diag Ident Band UpBnd LwBnd SmBnd Band -Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band -SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd - -* UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ -LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Sym Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Skew Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ -Diag UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band -Ident UT LT Rect Squ Squ Squ Diag Ident Band UpBnd LwBnd Band Band -Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -SmBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -SkBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band - -| UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -LT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Sym Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Skew Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Diag Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Ident Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Band Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -UpBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -LwBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -SmBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -SkBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect - -SP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Diag UT UT UT UT Diag Diag UpBnd UpBnd Diag UpBnd UpBnd -LT Diag LT LT LT LT LT Diag Diag LwBnd Diag LwBnd LwBnd LwBnd -Rect UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band -Squ UT LT Squ Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band -Sym UT LT Squ Squ Sym Skew Diag Diag Band UpBnd LwBnd SmBnd SkBnd -Skew UT LT Squ Squ Skew Sym ????? ????? Band UpBnd LwBnd SkBnd SmBnd -Diag Diag Diag Diag Diag Diag ????? Diag Diag Diag Diag Diag Diag ????? -Ident Diag Diag Diag Diag Diag ????? Diag Ident Diag Diag Diag Diag ????? -Band UpBnd LwBnd Band Band Band Band Diag Diag Band UpBnd LwBnd Band Band -UpBnd UpBnd Diag UpBnd UpBnd UpBnd UpBnd Diag Diag UpBnd UpBnd Diag UpBnd UpBnd -LwBnd Diag LwBnd LwBnd LwBnd LwBnd LwBnd Diag Diag LwBnd Diag LwBnd LwBnd LwBnd -SmBnd UpBnd LwBnd Band Band SmBnd SkBnd Diag Diag Band UpBnd LwBnd SmBnd SkBnd -SkBnd UpBnd LwBnd Band Band SkBnd SmBnd ????? ????? Band UpBnd LwBnd SkBnd SmBnd - -KP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LT Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect -Squ Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -Sym Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band -Skew Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd -Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band -Ident UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band -Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band -UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band -LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band -SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band -SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd - ->= UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd -UT Yes No Yes Yes No No No No No No No No No -LT No Yes Yes Yes No No No No No No No No No -Rect No No Yes Yes No No No No No No No No No -Squ No No Yes Yes No No No No No No No No No -Sym No No Yes Yes Yes No No No No No No No No -Skew No No Yes Yes No Yes No No No No No No No -Diag Yes Yes Yes Yes Yes No Yes No Yes Yes Yes Yes No -Ident Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes No -Band No No Yes Yes No No No No Yes No No No No -UpBnd Yes No Yes Yes No No No No Yes Yes No No No -LwBnd No Yes Yes Yes No No No No Yes No Yes No No -SmBnd No No Yes Yes Yes No No No Yes No No Yes No -SkBnd No No Yes Yes No Yes No No Yes No No No Yes +0 0 0 0 0 0 0 1 + ++ UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ +LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Sym Squ Squ Rect Squ Sym Squ Sym Sym Squ Squ Squ Sym Squ +Skew Squ Squ Rect Squ Squ Skew Squ Squ Squ Squ Squ Squ Skew +Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band +Ident UT LT Rect Squ Sym Squ Diag Ident Band UpBnd LwBnd SmBnd Band +Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band +SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd + +* UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Squ Rect Squ Squ Squ UT UT Squ UT Squ Squ Squ +LT Squ LT Rect Squ Squ Squ LT LT Squ Squ LT Squ Squ +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Sym Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Skew Squ Squ Rect Squ Squ Squ Squ Squ Squ Squ Squ Squ Squ +Diag UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band +Ident UT LT Rect Squ Squ Squ Diag Ident Band UpBnd LwBnd Band Band +Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +SmBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +SkBnd Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band + +| UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +LT Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Sym Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Skew Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Diag Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Ident Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Band Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +UpBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +LwBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +SmBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +SkBnd Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect + +SP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Diag UT UT UT UT Diag Diag UpBnd UpBnd Diag UpBnd UpBnd +LT Diag LT LT LT LT LT Diag Diag LwBnd Diag LwBnd LwBnd LwBnd +Rect UT LT Rect Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band +Squ UT LT Squ Squ Squ Squ Diag Diag Band UpBnd LwBnd Band Band +Sym UT LT Squ Squ Sym Skew Diag Diag Band UpBnd LwBnd SmBnd SkBnd +Skew UT LT Squ Squ Skew Sym ????? ????? Band UpBnd LwBnd SkBnd SmBnd +Diag Diag Diag Diag Diag Diag ????? Diag Diag Diag Diag Diag Diag ????? +Ident Diag Diag Diag Diag Diag ????? Diag Ident Diag Diag Diag Diag ????? +Band UpBnd LwBnd Band Band Band Band Diag Diag Band UpBnd LwBnd Band Band +UpBnd UpBnd Diag UpBnd UpBnd UpBnd UpBnd Diag Diag UpBnd UpBnd Diag UpBnd UpBnd +LwBnd Diag LwBnd LwBnd LwBnd LwBnd LwBnd Diag Diag LwBnd Diag LwBnd LwBnd LwBnd +SmBnd UpBnd LwBnd Band Band SmBnd SkBnd Diag Diag Band UpBnd LwBnd SmBnd SkBnd +SkBnd UpBnd LwBnd Band Band SkBnd SmBnd ????? ????? Band UpBnd LwBnd SkBnd SmBnd + +KP UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LT Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect Rect +Squ Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +Sym Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band +Skew Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd +Diag UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band +Ident UT LT Rect Squ Sym Squ Diag Diag Band UpBnd LwBnd SmBnd Band +Band Squ Squ Rect Squ Squ Squ Band Band Band Band Band Band Band +UpBnd UT Squ Rect Squ Squ Squ UpBnd UpBnd Band UpBnd Band Band Band +LwBnd Squ LT Rect Squ Squ Squ LwBnd LwBnd Band Band LwBnd Band Band +SmBnd Squ Squ Rect Squ Sym Squ SmBnd SmBnd Band Band Band SmBnd Band +SkBnd Squ Squ Rect Squ Squ Skew Band Band Band Band Band Band SkBnd + +>= UT LT Rect Squ Sym Skew Diag Ident Band UpBnd LwBnd SmBnd SkBnd +UT Yes No Yes Yes No No No No No No No No No +LT No Yes Yes Yes No No No No No No No No No +Rect No No Yes Yes No No No No No No No No No +Squ No No Yes Yes No No No No No No No No No +Sym No No Yes Yes Yes No No No No No No No No +Skew No No Yes Yes No Yes No No No No No No No +Diag Yes Yes Yes Yes Yes No Yes No Yes Yes Yes Yes No +Ident Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes No +Band No No Yes Yes No No No No Yes No No No No +UpBnd Yes No Yes Yes No No No No Yes Yes No No No +LwBnd No Yes Yes Yes No No No No Yes No Yes No No +SmBnd No No Yes Yes Yes No No No Yes No No Yes No +SkBnd No No Yes Yes No Yes No No Yes No No No Yes * First test of Matrix package @@ -6591,3 +6591,4 @@ Number of matrices tested = 1604 Number of non-zero matrices (should be 1) = 1 Elapsed (processor) time = 0.36 seconds + diff --git a/extern/newmat/tmt1.cpp b/extern/newmat/tmt1.cpp index 054b5db..80d76de 100644 --- a/extern/newmat/tmt1.cpp +++ b/extern/newmat/tmt1.cpp @@ -137,15 +137,15 @@ void trymat1() Matrix M1X = BM1; Matrix M2X = BM2; Matrix MX = BM; MX -= M1X + M2X; Print(MX); MX = BM1; MX += BM2; MX -= M1X; MX -= M2X; Print(MX); - SymmetricBandMatrix SM1; SM1 << BM1 * BM1.t(); + SymmetricBandMatrix SM1; SM1 << BM1 * BM1.t(); SymmetricBandMatrix SM2; SM2 << BM2 * BM2.t(); SM1 *= 5.5; M1X *= M1X.t(); M1X *= 5.5; M2X *= M2X.t(); SM1 -= SM2; M1 = SM1 - M1X + M2X; Print(M1); - M1 = BM1; BM1 *= SM1; M1 = M1 * SM1 - BM1; Print(M1); - M1 = BM1; BM1 -= SM1; M1 = M1 - SM1 - BM1; Print(M1); - M1 = BM1; BM1 += SM1; M1 = M1 + SM1 - BM1; Print(M1); - + M1 = BM1; BM1 *= SM1; M1 = M1 * SM1 - BM1; Print(M1); + M1 = BM1; BM1 -= SM1; M1 = M1 - SM1 - BM1; Print(M1); + M1 = BM1; BM1 += SM1; M1 = M1 + SM1 - BM1; Print(M1); + } { Tracer et1("Stage 6"); @@ -271,16 +271,16 @@ void trymat1() ColumnVector cv(10); for (int i = 1; i <= 10; ++i) cv(i) = mwc.Next(); cv *= 100.0; - cv(1) -= 6.27874; - cv(2) -= 42.1718; - cv(3) -= 80.2854; - cv(4) -= 12.961; - cv(5) -= 17.7499; - cv(6) -= 13.2657; - cv(7) -= 50.4923; - cv(8) -= 26.095; - cv(9) -= 57.9147; - cv(10) -= 30.1778; + cv(1) -= 6.27874; + cv(2) -= 42.1718; + cv(3) -= 80.2854; + cv(4) -= 12.961; + cv(5) -= 17.7499; + cv(6) -= 13.2657; + cv(7) -= 50.4923; + cv(8) -= 26.095; + cv(9) -= 57.9147; + cv(10) -= 30.1778; Clean(cv, 0.0001); Print(cv); } diff --git a/extern/newmat/tmt2.cpp b/extern/newmat/tmt2.cpp index c435e67..443aea7 100644 --- a/extern/newmat/tmt2.cpp +++ b/extern/newmat/tmt2.cpp @@ -285,7 +285,7 @@ void trymat2() I.ReSize(3); J.ReSize(3); K = I * J; N = K - I; Print(N); K << D; N = K - D; Print(N); } - + // test add integer { Matrix X(2,3); @@ -296,15 +296,15 @@ void trymat2() X += (-10); X -= Y; Print(X); - + // also test f suffix X << 5.25f << 7.75f << 1.25f << 9.00f << 1.00f << 2.50f; X -= Y; Print(X); - + } - - + + // cout << "\nEnd of second test\n"; diff --git a/extern/newmat/tmt4.cpp b/extern/newmat/tmt4.cpp index fed955b..d2ed96b 100644 --- a/extern/newmat/tmt4.cpp +++ b/extern/newmat/tmt4.cpp @@ -157,7 +157,7 @@ void trymat4() D1(1) = 18; D1(2) = 23; D1(3) = 31; D1(4) = 17; D1 -= D; Print(D1); } - + { Tracer et1("Stage 8"); // test swap functions @@ -173,13 +173,13 @@ void trymat4() D = A - B1; Print(D); Print(A); // now should be zero D.ReSize(1,2); D(1,1) = a; D(1,2) = b; Print(D); - + A.ReSize(20,20); FillWithValues(MWC, A); - + UpperTriangularMatrix UA; UA << A; UpperTriangularMatrix UA1 = UA; UpperTriangularMatrix UB; swap(UA, UB); Print(UA); UB -= UA1; Print(UB); - + LowerTriangularMatrix LA; LA << A; LowerTriangularMatrix LA1 = LA; LowerTriangularMatrix LB; swap(LB, LA); Print(LA); LB -= LA1; Print(LB); @@ -187,63 +187,63 @@ void trymat4() SymmetricMatrix SA; SA << A; SymmetricMatrix SA1 = SA; SymmetricMatrix SB; swap(SA, SB); Print(SA); SB -= SA1; Print(SB); - + DiagonalMatrix DA; DA << A; DiagonalMatrix DA1 = DA; DiagonalMatrix DB; swap(DB, DA); Print(DA); DB -= DA1; Print(DB); - + RowVector RVA = A.Row(1); RowVector RVA1 = RVA; RowVector RVB; swap(RVB, RVA); Print(RVA); RVB -= RVA1; Print(RVB); - + ColumnVector CVA = A.Column(1); ColumnVector CVA1 = CVA; ColumnVector CVB; swap(CVA, CVB); Print(CVA); CVB -= CVA1; Print(CVB); - + BandMatrix BA(20, 7, 4); BA.Inject(A); BandMatrix BA1 = BA; BandMatrix BB; swap(BA, BB); D = BA; Print(D); BB -= BA1; D = BB; Print(D); - + LowerBandMatrix LBA(20, 6); LBA.Inject(A); LowerBandMatrix LBA1 = LBA; LowerBandMatrix LBB; swap(LBB, LBA); D = LBA; Print(D); LBB -= LBA1; D = LBB; Print(D); - + UpperBandMatrix UBA(20, 9); UBA.Inject(A); UpperBandMatrix UBA1 = UBA; UpperBandMatrix UBB; swap(UBA, UBB); D = UBA; Print(D); UBB -= UBA1; D = UBB; Print(D); - + SymmetricBandMatrix SBA(20, 4); SBA.Inject(A); SymmetricBandMatrix SBA1 = SBA; SymmetricBandMatrix SBB; - + swap(SBB, SBA); D = SBA; Print(D); SBB -= SBA1; D = SBB; Print(D); - + B.ReSize(10,10); FillWithValues(MWC, B); - + CroutMatrix CA = A; IdentityMatrix IA(20); CroutMatrix CB = B; IdentityMatrix IB(10); swap(CA, CB); swap(IA, IB); D = CA.i() * B - IA; Clean(D,0.00000001); Print(D); D = CB.i() * A - IB; Clean(D,0.00000001); Print(D); - + BA.ReSize(20, 5, 7); BA.Inject(A); BandLUMatrix BLUA = BA; BB.ReSize(10, 3, 4); BB.Inject(B); BandLUMatrix BLUB = BB; swap(BLUA, BLUB); D = BLUA.i() * BB - IA; Clean(D,0.00000001); Print(D); D = BLUB.i() * BA - IB; Clean(D,0.00000001); Print(D); - + SBA.ReSize(20, 5); SBA.Inject(A); BandLUMatrix SBLUA = SBA; SBB.ReSize(10, 3); SBB.Inject(B); BandLUMatrix SBLUB = SBB; swap(SBLUA, SBLUB); D = SBLUA.i() * SBB - IA; Clean(D,0.00000001); Print(D); D = SBLUB.i() * SBA - IB; Clean(D,0.00000001); Print(D); - + UA << A; GenericMatrix GUA = UA; GenericMatrix GB = B; swap(GUA, GB); D = GB - UA; Print(D); D = B - GUA; Print(D); - + } // cout << "\nEnd of fourth test\n"; diff --git a/extern/newmat/tmt6.cpp b/extern/newmat/tmt6.cpp index f8423b7..8defa2a 100644 --- a/extern/newmat/tmt6.cpp +++ b/extern/newmat/tmt6.cpp @@ -79,7 +79,7 @@ void trymat6() for (i=1;i<=6;i++) for (j=i;j<=6;j++) S(i,j)=i*i+2.0+j; Matrix MD=D; Matrix ML=L; Matrix MU=U; Matrix MS=S; Matrix M(6,6); - for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; + for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; { Tracer et1("Stage 1"); Print(Matrix(MS+(-MS))); diff --git a/extern/newmat/tmt7.cpp b/extern/newmat/tmt7.cpp index 4ece58c..c4e43fa 100644 --- a/extern/newmat/tmt7.cpp +++ b/extern/newmat/tmt7.cpp @@ -29,7 +29,7 @@ void c_matrix_multiply(int p, int q, int r, c[i][k] = sum; } } - + void trymat7() @@ -50,7 +50,7 @@ void trymat7() Matrix MD=D; Matrix ML=L; Matrix MU=U; Matrix MS=S; Matrix M(6,6); - for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; + for (i=1;i<=6;i++) for (j=1;j<=6;j++) M(i,j)=i*j+i*i-10.0; { Tracer et1("Stage 1"); Print(Matrix((S-M)-(MS-M))); @@ -99,7 +99,7 @@ void trymat7() CV << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75; D << 2 << 6 <<3 << 8 << -4 << 17.5 << 2 << 1 << -2 << 5 << 3.75; X = CV.AsDiagonal(); X = X-D; Print(X); - SymmetricBandMatrix SB1(11,7); SB1 = 5; + SymmetricBandMatrix SB1(11,7); SB1 = 5; SymmetricBandMatrix SB2 = SB1 + D; X.ReSize(11,11); X=0; for (i=1;i<=11;i++) for (j=1;j<=11;j++) @@ -145,12 +145,12 @@ void trymat7() for (i = 0; i < 5; i++) if (F[i] != 0) Test(9)=1; Print(Test); } - + { // testing RealStarStar Tracer et("Stage 6"); MultWithCarry MWC; - + Matrix A(10, 12), B(12, 15), C(10, 15); FillWithValues(MWC, A); FillWithValues(MWC, B); ConstRealStarStar a(A); @@ -165,13 +165,13 @@ void trymat7() ConstRealStarStar(A),ConstRealStarStar(B),RealStarStar(C)); X = C - A * B; Clean(X,0.00000001); Print(X); } - + { // testing resize_keep Tracer et("Stage 7"); Matrix X, Y; MultWithCarry MWC; - + X.resize(20,35); FillWithValues(MWC, X); Matrix M(20,35); M = X; X = M.submatrix(1,15,1,25); @@ -181,14 +181,14 @@ void trymat7() M.resize_keep(29,27); Y -= M; Print(Y); M.resize_keep(0,5); M.resize_keep(10,10); Print(M); M.resize_keep(15,0); M.resize_keep(10,10); Print(M); - + X.resize(20,35); FillWithValues(MWC, X); M = X; M.resize_keep(38,17); Y.resize(38,17); Y = 0; Y.submatrix(1,20,1,17) = X.submatrix(1,20,1,17); Y -= M; Print(Y); - + X.resize(40,12); FillWithValues(MWC, X); M = X; M.resize_keep(38,17); @@ -207,23 +207,23 @@ void trymat7() nM.resize_keep(29,27); Y -= nM; Print(Y); nM.resize_keep(0,5); nM.resize_keep(10,10); Print(nM); nM.resize_keep(15,0); nM.resize_keep(10,10); Print(nM); - + X.resize(20,35); FillWithValues(MWC, X); nM = X; nM.resize_keep(38,17); Y.resize(38,17); Y = 0; Y.submatrix(1,20,1,17) = X.submatrix(1,20,1,17); Y -= nM; Print(Y); - + X.resize(40,12); FillWithValues(MWC, X); nM = X; nM.resize_keep(38,17); Y.resize(38,17); Y = 0; Y.submatrix(1,38,1,12) = X.submatrix(1,38,1,12); - Y -= nM; Print(Y); - -#endif + Y -= nM; Print(Y); +#endif + X.resize(20,20); FillWithValues(MWC, X); SquareMatrix SQM(20); SQM << X; X = SQM.sym_submatrix(1,13); @@ -232,7 +232,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; SQM.resize_keep(23,23); Y -= SQM; Print(Y); SQM.resize_keep(0); SQM.resize_keep(50); Print(SQM); - + X.resize(20,20); FillWithValues(MWC, X); SymmetricMatrix SM(20); SM << X; X = SM.sym_submatrix(1,13); @@ -241,7 +241,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; SM.resize_keep(23); Y -= SM; Print(Y); SM.resize_keep(0); SM.resize_keep(50); Print(SM); - + X.resize(20,20); FillWithValues(MWC, X); LowerTriangularMatrix LT(20); LT << X; X = LT.sym_submatrix(1,13); @@ -250,7 +250,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; LT.resize_keep(23); Y -= LT; Print(Y); LT.resize_keep(0); LT.resize_keep(50); Print(LT); - + X.resize(20,20); FillWithValues(MWC, X); UpperTriangularMatrix UT(20); UT << X; X = UT.sym_submatrix(1,13); @@ -259,7 +259,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; UT.resize_keep(23); Y -= UT; Print(Y); UT.resize_keep(0); UT.resize_keep(50); Print(UT); - + X.resize(20,20); FillWithValues(MWC, X); DiagonalMatrix DM(20); DM << X; X = DM.sym_submatrix(1,13); @@ -268,7 +268,7 @@ void trymat7() Y.resize(23,23); Y = 0; Y.sym_submatrix(1,13) = X; DM.resize_keep(23); Y -= DM; Print(Y); DM.resize_keep(0); DM.resize_keep(50); Print(DM); - + X.resize(1,20); FillWithValues(MWC, X); RowVector RV(20); RV << X; X = RV.columns(1,13); @@ -277,7 +277,7 @@ void trymat7() Y.resize(1,23); Y = 0; Y.columns(1,13) = X; RV.resize_keep(1,23); Y -= RV; Print(Y); RV.resize_keep(0); RV.resize_keep(50); Print(RV); - + X.resize(20,1); FillWithValues(MWC, X); ColumnVector CV(20); CV << X; X = CV.rows(1,13); @@ -286,9 +286,9 @@ void trymat7() Y.resize(23,1); Y = 0; Y.rows(1,13) = X; CV.resize_keep(23,1); Y -= CV; Print(Y); CV.resize_keep(0); CV.resize_keep(50); Print(CV); - - - } + + + } // cout << "\nEnd of seventh test\n"; diff --git a/extern/newmat/tmt8.cpp b/extern/newmat/tmt8.cpp index f369e05..60b5a16 100644 --- a/extern/newmat/tmt8.cpp +++ b/extern/newmat/tmt8.cpp @@ -145,7 +145,7 @@ void trymat8() M.ReSize(MX); DCR( D.nric(), C.nric(), 5, R.nric(), 9, M.nric() ); M -= MX; Print(M); - + // test swap nricMatrix A(3,4); nricMatrix B(4,5); A.Row(1) << 2 << 7 << 3 << 6; @@ -164,7 +164,7 @@ void trymat8() for (int k = 1; k <= 4; ++k) X.nric()[i][j] += A1.nric()[i][k] * B1.nric()[k][j]; } - X1 -= X; Print(X1); + X1 -= X; Print(X1); } #endif { diff --git a/extern/newmat/tmt9.cpp b/extern/newmat/tmt9.cpp index fc4fd4c..bef4636 100644 --- a/extern/newmat/tmt9.cpp +++ b/extern/newmat/tmt9.cpp @@ -41,7 +41,7 @@ void trymat9() { Tracer et1("Stage 2"); Matrix DXE = D.i() * X * E; - DXE = E.i() * DXE.t() * D - X.t(); Clean(DXE, 0.00000001); Print(DXE); + DXE = E.i() * DXE.t() * D - X.t(); Clean(DXE, 0.00000001); Print(DXE); E=D; for (i=1;i<=7;i++) E(i,i)=i*3+1; } DiagonalMatrix F=D; @@ -216,7 +216,7 @@ void trymat9() { Tracer et1("Stage 8"); - // test copying CroutMatrix and BandLUMatrix - see also tmtd.cpp + // test copying CroutMatrix and BandLUMatrix - see also tmtd.cpp MultWithCarry MWC; SymmetricBandMatrix SBM(50, 10); for (int i = 1; i <= 50; ++i) for (int j = 1; j <= i; ++j) @@ -241,7 +241,7 @@ void trymat9() { Tracer et1("Stage 9"); - // do it again odd matrix size + // do it again odd matrix size MultWithCarry MWC; SymmetricBandMatrix SBM(51, 10); for (int i = 1; i <= 51; ++i) for (int j = 1; j <= i; ++j) @@ -263,7 +263,7 @@ void trymat9() D(4) = z.sign() - x.sign(); Clean(D,0.00000001); Print(D); } - + { Tracer et1("Stage 10"); // testing equal again @@ -280,12 +280,12 @@ void trymat9() B *= 3; A = B; X = A.i() * B - IdentityMatrix(10); Clean(X,0.00000001); Print(X); - } - - - - - + } + + + + + // cout << "\nEnd of ninth test\n"; } diff --git a/extern/newmat/tmtc.cpp b/extern/newmat/tmtc.cpp index 2d48595..a88f4f8 100644 --- a/extern/newmat/tmtc.cpp +++ b/extern/newmat/tmtc.cpp @@ -184,7 +184,7 @@ void trymatc() { RowVector RV = 5 * M1.Row(i); M.Row(i) -= RV; } M += M1; Print(M); - + } { @@ -205,13 +205,13 @@ void trymatc() nricMatrix N2 = N; nricMatrix Y = N; Print(Y); Y = N1 - N2; Print(Y); - + N = M1 / 2; N1 = N * 2; N.Release(); N2 = N * 2; Y = N; Print(N); Y = (N1 - M1) | (N2 - M1); Print(Y); #endif } - + { Tracer et("Stage 13"); // test sum of squares of rows or columns @@ -272,9 +272,9 @@ void trymatc() A1.ReSize(10,0); X.ReSize(10,1); X = 0; X -= A1.sum_square_rows(); Clean(X, 0.00000000000001); Print(X); X.ReSize(1,0); X -= A1.sum_square_columns(); Clean(X, 0.00000000000001); Print(X); - + } - + { Tracer et("Stage 14"); // test extend orthonormal @@ -289,7 +289,7 @@ void trymatc() // Check orthogonality X = A.t() * A - IdentityMatrix(5); Clean(X, 0.000000001); Print(X); - // Try orthonality extend + // Try orthonality extend SquareMatrix A1(20); A1.Columns(1,5) = A; extend_orthonormal(A1,5); @@ -297,10 +297,10 @@ void trymatc() X = A - A1.Columns(1,5); Print(X); // Check orthogonality X = A1.t() * A1 - IdentityMatrix(20); - Clean(X, 0.000000001); Print(X); + Clean(X, 0.000000001); Print(X); X = A1 * A1.t() - IdentityMatrix(20); Clean(X, 0.000000001); Print(X); - // Test with smaller number of columns + // Test with smaller number of columns Matrix A2(20,15); A2.Columns(1,5) = A; extend_orthonormal(A2,5); @@ -333,7 +333,7 @@ void trymatc() B -= A; Clean(B, 0.000000001); Print(B); } - + { Tracer et("Stage 16"); // test sum of rows or columns @@ -396,9 +396,9 @@ void trymatc() A1.ReSize(10,0); X.ReSize(10,1); X = 0; X -= A1.sum_rows(); Print(X); X.ReSize(1,0); X -= A1.sum_columns(); Print(X); - + } - + { Tracer et("Stage 17"); // SP_eq on submatrices @@ -408,20 +408,20 @@ void trymatc() Matrix X = A; X.submatrix(5,21,3,13).SP_eq(B); Matrix Y = A; Y.submatrix(5,21,3,13) = SP(Y.submatrix(5,21,3,13),B); Y -= X; Print(Y); - + UpperTriangularMatrix UT(33); FillWithValues(mwc, UT); UpperTriangularMatrix UTX = UT; UTX.submatrix(5,21,3,13).SP_eq(B); Y = UT; Y.submatrix(5,21,3,13) = SP(Y.submatrix(5,21,3,13),B); Y -= UTX; Print(Y); - + UT.resize(10); FillWithValues(mwc, UT); X = A; X.submatrix(5,14,3,12).SP_eq(UT); Y = A; Y.submatrix(5,14,3,12) = SP(Y.submatrix(5,14,3,12),UT); Y -= X; Print(Y); - + SymmetricMatrix SM(30), SM1(10); FillWithValues(mwc, SM); FillWithValues(mwc, SM1); SymmetricMatrix SMX = SM; @@ -429,12 +429,12 @@ void trymatc() //SMX.sym_submatrix(5,14) += SM1; //Y = SM; Y.submatrix(5,14,5,14) = Y.submatrix(5,14,5,14) + SM1; //Y -= SMX; Print(Y); - + SMX = SM; SMX.submatrix(5,14,5,14).SP_eq(SM1); Y = SM; Y.submatrix(5,14,5,14) = SP(Y.submatrix(5,14,5,14),SM1); Y -= SMX; Print(Y); - + BandMatrix BM(50, 10, 12); X.resize(50,50); FillWithValues(mwc, X); BM.inject(X); X = BM; @@ -449,17 +449,17 @@ void trymatc() BM.submatrix(2,8,4,13).SP_eq(B); X.submatrix(2,8,4,13) = SP(X.submatrix(2,8,4,13), B); X -= BM; Print(X); - + X.resize(50,50); FillWithValues(mwc, X); BM.inject(X); X = BM; B.resize(21, 23); FillWithValues(mwc, B); BM.submatrix(2,22,4,26).SP_eq(B); X.submatrix(2,22,4,26) = SP(X.submatrix(2,22,4,26), B); X -= BM; Print(X); - + } - - { + + { Tracer et("Stage 18"); // += real on submatrices of symmetric matrices // these don't work either @@ -470,27 +470,27 @@ void trymatc() //SMX.sym_submatrix(7,11) += 5; //Matrix X = SM; X.sym_submatrix(7,11) += 5; //X -= SMX; Print(X); - + } - + { Tracer et("Stage 19"); // SQ_eq on matrices MultWithCarry mwc; - + Matrix X(10,13), Y(10,13); FillWithValues(mwc, X); FillWithValues(mwc, Y); Matrix Z = X; Z.SP_eq(Y); Z -= SP(X, Y); Print(Z); - + Z = X; Z.SP_eq(2 * Y); Z -= 2 * SP(X, Y); Print(Z); - + Z = X; Z.SP_eq(Z); Z -= SP(X, X); Print(Z); - + GenericMatrix GX = X, GY = Y; test_SP_eq(GX, GY); test_SP_eq(GX, GX); - + X.resize(17,17); Y.resize(17,17); FillWithValues(mwc, X); FillWithValues(mwc, Y); UpperTriangularMatrix UT; UT << Y; @@ -504,28 +504,28 @@ void trymatc() UpperTriangularMatrix UX(19), UY(19); FillWithValues(mwc, UX); FillWithValues(mwc, UY); - + GX = UX; GY = UY; test_SP_eq(GX, GY); test_SP_eq(GX, GY.t()); UpperTriangularMatrix UZ = UX; UZ.SP_eq(UY); UZ -= SP(UX, UY); Print(UZ); - + UZ = UX; UZ.SP_eq(2 * UY); UZ -= 2 * SP(UX, UY); Print(UZ); - + UT << UY; LT << UY; D << UY; UpperTriangularMatrix UZUT = UX; UZUT.SP_eq(UT); UpperTriangularMatrix UZLT = UX; UZLT.SP_eq(LT); UpperTriangularMatrix UZD = UX; UZD.SP_eq(D); Z = UZUT + UZLT - UZD - SP(UX, UY); Clean(Z, 0.000000001); Print(Z); - + SymmetricMatrix SM(13), SM1(13), SMX, SM2; FillWithValues(mwc, SM); FillWithValues(mwc, SM1); SMX = SP(SM, SM1); SM2 = SM; SM2.SP_eq(SM1); SM2 -= SMX; Print(SM2); GX = SM; GY = SM1; test_SP_eq(GX, GY); - + X.resize(13,13); FillWithValues(mwc, X); Z = SP(X,SM); SM2 = SM; X.SP_eq(SM); X -= Z; Print(X); @@ -533,7 +533,7 @@ void trymatc() FillWithValues(mwc, X); GX = X; GY = SM; test_SP_eq(GX, GY); GX = SM; GY = X; test_SP_eq(GX, GY); - + BandMatrix BMX(13, 5,9); BMX.inject(X); SymmetricBandMatrix SBM(13,6); SBM.inject(SM); GX = BMX; GY = SBM; test_SP_eq(GX, GY); @@ -542,11 +542,11 @@ void trymatc() BandMatrix BMX2 = SBM; GX = BMX; GY = BMX2; test_SP_eq(GX, GY); BMX1 = BMX; BMX1.SP_eq(BMX2); Z = BMX1 - SP(BMX,BMX2); Print(Z); - - + + } - - + + // cout << "\nEnd of twelfth test\n"; } diff --git a/extern/newmat/tmtd.cpp b/extern/newmat/tmtd.cpp index 6ff3cd7..edf574e 100644 --- a/extern/newmat/tmtd.cpp +++ b/extern/newmat/tmtd.cpp @@ -137,9 +137,9 @@ void QRZ_checkT(Matrix& X, Matrix& Y, UpperTriangularMatrix& U, Matrix& M) Matrix XT = X.t(), YT = Y.t(), MT, BX; LowerTriangularMatrix L; QRZ(X, Y, U, M); QRZT(XT, YT, L, MT); - BX = U - L.t(); Clean(BX, 0.000000001); Print(BX); - BX = M - MT.t(); Clean(BX, 0.000000001); Print(BX); -} + BX = U - L.t(); Clean(BX, 0.000000001); Print(BX); + BX = M - MT.t(); Clean(BX, 0.000000001); Print(BX); +} @@ -289,7 +289,7 @@ void trymatd() M = A * Cholesky(B); M = M * M.t() - A * B * A; Clean(M, 0.000000001); Print(M); } - + { Tracer et1("Stage 6"); int N=49; @@ -334,8 +334,8 @@ void trymatd() D(6) = B1.nrows(); D(7) = B1.ncols(); D(8) = B1.size(); Clean(C, 0.000000001); Print(C); // see if we get an implicit invert - B1 = -A; - D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change + B1 = -A; + D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change C = -A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // check for_return @@ -368,7 +368,7 @@ void trymatd() const int* i2 = B2.const_data_indx(); D(25) = (d != d1 ? 0 : 1) + (d1 == d2 ? 0 : 1) + (i != i1 ? 0 : 1) + (i1 == i2 ? 0 : 1); - + Clean(D, 0.000000001); Print(D); } @@ -403,8 +403,8 @@ void trymatd() D(6) = B1.nrows(); D(7) = B1.ncols(); D(8) = B1.size(); Clean(C, 0.000000001); Print(C); // see if we get an implicit invert - B1 = -A; - D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change + B1 = -A; + D(9) = determinant(B1) / x + 1; // odd number of rows - sign will change C = -A * Inverter2(B1) - IdentityMatrix(7); Clean(C, 0.000000001); Print(C); // check for_return @@ -471,7 +471,7 @@ void trymatd() QRZ(X, U2); Matrix Diff = U1 - U2; Clean(Diff, 0.000000001); Print(Diff); - // Try adding new row to X and updating triangular matrix + // Try adding new row to X and updating triangular matrix RowVector NewRow(10); for (j = 1; j <= 10; ++j) NewRow(j) = 2.0 * (mwc.Next() - 0.5); UpdateCholesky(U2, NewRow); @@ -492,7 +492,7 @@ void trymatd() CircularShift(X, 1,6); CircularShift(X, 6,10); } - + { Tracer et1("Stage 10"); // Try updating QRZ, QRZT decomposition @@ -507,9 +507,9 @@ void trymatd() tuqrz2.Reset(); tuqrz2.ClearRow(5); tuqrz2.ClearRow(6); tuqrz2.DoTest(); tuqrz2.Reset(); tuqrz2.ClearRow(15); tuqrz2.DoTest(); TestUpdateQRZ tuqrz3(5, 0, 10, 0); tuqrz3.DoTest(); - + } - + { Tracer et1("Stage 11"); // combining three decompositions @@ -537,14 +537,14 @@ void trymatd() fix_signs(U3); BX = U - U3; Clean(BX, 0.000000001); Print(BX); - + // same again with some columns set to zero FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(1,8) = 0; X2.columns(5,13) = 0; - X3.columns(10,20) = 0; + X3.columns(10,20) = 0; X = X1 & X2 & X3; Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); QRZ(X2, Y2, U2, M2); @@ -560,14 +560,14 @@ void trymatd() fix_signs(U3); BX = U - U3; Clean(BX, 0.000000001); Print(BX); - + // same again with some duplicate columns FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(4,5) = X1.columns(1,2); X2.columns(7,12) = X2.columns(1,6); - X3.columns(11,20) = X3.columns(1,10); + X3.columns(11,20) = X3.columns(1,10); X = X1 & X2 & X3; Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); QRZ(X2, Y2, U2, M2); @@ -583,9 +583,9 @@ void trymatd() fix_signs(U3); BX = U - U3; Clean(BX, 0.000000001); Print(BX); - - - + + + // Try with incremental update FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); @@ -608,7 +608,7 @@ void trymatd() FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(1,8) = 0; X2.columns(5,13) = 0; - X3.columns(10,20) = 0; + X3.columns(10,20) = 0; X = X1 & X2 & X3, Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); UpdateQRZ(X2, U1); UpdateQRZ(X2, Y2, M1); @@ -620,15 +620,15 @@ void trymatd() fix_signs(U1); BX = U - U1; Clean(BX, 0.000000001); Print(BX); - - + + // same again with some duplicate columns FillWithValues(MWC, X1); FillWithValues(MWC, Y1); FillWithValues(MWC, X2); FillWithValues(MWC, Y2); FillWithValues(MWC, X3); FillWithValues(MWC, Y3); X1.columns(4,5) = X1.columns(1,2); X2.columns(7,12) = X2.columns(1,6); - X3.columns(11,20) = X3.columns(1,10); + X3.columns(11,20) = X3.columns(1,10); X = X1 & X2 & X3, Y = Y1 & Y2 & Y3; QRZ(X1, Y1, U1, M1); UpdateQRZ(X2, U1); UpdateQRZ(X2, Y2, M1); @@ -640,7 +640,7 @@ void trymatd() fix_signs(U1); BX = U - U1; Clean(BX, 0.000000001); Print(BX); - + // Try with incremental update using QRZT LowerTriangularMatrix L, L1; X1.resize(21, 90); X2.resize(21, 250); X3.resize(21, 113); @@ -662,7 +662,7 @@ void trymatd() FillWithValues(MWC, X3); X1.rows(1,8) = 0; X2.rows(5,13) = 0; - X3.rows(10,21) = 0; + X3.rows(10,21) = 0; X = X1 | X2 | X3; QRZT(X1, L1); UpdateQRZT(X2, L1); @@ -671,15 +671,15 @@ void trymatd() fix_signs(L1); BX = L - L1; Clean(BX, 0.000000001); Print(BX); - - + + // same again with some duplicate columns FillWithValues(MWC, X1); FillWithValues(MWC, X2); FillWithValues(MWC, X3); X1.columns(4,5) = X1.columns(1,2); X2.columns(7,12) = X2.columns(1,6); - X3.columns(12,21) = X3.columns(1,10); + X3.columns(12,21) = X3.columns(1,10); X = X1 | X2 | X3; QRZT(X1, L1); UpdateQRZT(X2, L1); @@ -688,9 +688,9 @@ void trymatd() fix_signs(L1); BX = L - L1; Clean(BX, 0.000000001); Print(BX); - } - - + } + + // cout << "\nEnd of Thirteenth test\n"; } @@ -764,6 +764,6 @@ void fix_signs(LowerTriangularMatrix& L) L.column(i) = -L.column(i); } } - + ///@} diff --git a/extern/newmat/tmte.cpp b/extern/newmat/tmte.cpp index 215e50a..c3e46ad 100644 --- a/extern/newmat/tmte.cpp +++ b/extern/newmat/tmte.cpp @@ -502,7 +502,7 @@ void trymate() Clean(X, 0.000000001); Print(X); Y = V * V.t() - IdentityMatrix(2); Clean(Y, 0.000000001); Print(Y); - + } diff --git a/extern/newmat/tmtf.cpp b/extern/newmat/tmtf.cpp index 8ddd640..57d21c2 100644 --- a/extern/newmat/tmtf.cpp +++ b/extern/newmat/tmtf.cpp @@ -303,7 +303,7 @@ static void test9(int m, int n) Clean(X,0.000000001); Clean(Y,0.000000001); Print(X); Print(Y); FFT2I(X1, Y1, X1, Y1); X1 -= A; Y1 -= B; - Clean(X1,0.000000001); Clean(Y1,0.000000001); Print(X1); Print(Y1); + Clean(X1,0.000000001); Clean(Y1,0.000000001); Print(X1); Print(Y1); } @@ -367,7 +367,7 @@ void trymatf() test9(1,16); test9(16,1); test9(4,3); test9(4,4); test9(4,5); test9(5,3); - + // now do the same thing all over again forcing use of old FFT FFT_Controller::OnlyOldFFT = true; @@ -417,7 +417,7 @@ void trymatf() // compare DCT, DST and slow versions test8(2); test8(26); test8(32); test8(18); - + // compare FFT2 with slow version // don't redo these diff --git a/extern/newmat/tmth.cpp b/extern/newmat/tmth.cpp index ef77cbd..0d3100e 100644 --- a/extern/newmat/tmth.cpp +++ b/extern/newmat/tmth.cpp @@ -766,7 +766,7 @@ void trymath() RV(2) = BM.BandWidth().Upper(); Print(RV); } - + { // Helmert multiplies Tracer et1("Stage 9"); @@ -779,22 +779,22 @@ void trymath() Matrix H = Helmert(9); H -= Y.t(); Clean(H,0.000000001); Print(H); Matrix Z = Helmert(Y) - I; Clean(Z,0.000000001); Print(Z); - + Matrix A(9, 8); for (i = 1; i <= 9; ++i) for (j = 1; j <= 8; ++j) A(i, j) = Helmert_transpose(X.column(j), i); - A -= Y; Clean(A,0.000000001); Print(A); - + A -= Y; Clean(A,0.000000001); Print(A); + X = I; Y = Helmert_transpose(X, true); H = Helmert(8, true); H -= Y.t(); Clean(H,0.000000001); Print(H); Z = Helmert(Y, true) - I; Clean(Z,0.000000001); Print(Z); - + A.resize(8, 8); for (i = 1; i <= 8; ++i) for (j = 1; j <= 8; ++j) A(i, j) = Helmert_transpose(X.column(j), i, true); - A -= Y; Clean(A,0.000000001); Print(A); + A -= Y; Clean(A,0.000000001); Print(A); @@ -804,7 +804,7 @@ void trymath() H = Helmert(9, true); H -= Y; Clean(H,0.000000001); Print(H); Z = Helmert_transpose(Y, true) - I; Clean(Z,0.000000001); Print(Z); - + A.ReSize(9, 9); for (i = 1; i <= 9; ++i) A.Column(i) = Helmert(9, i, true); A -= Y; Clean(A,0.000000001); Print(A); @@ -813,10 +813,10 @@ void trymath() A.ReSize(8, 9); for (i = 1; i <= 9; ++i) A.Column(i) = Helmert(9, i); A -= Y; Clean(A,0.000000001); Print(A); - + ColumnVector Twos(100); Twos = 2; ColumnVector CV = Helmert(Twos); Clean(CV,0.000000001); Print(CV); - + X.resize(25,30); FillWithValues(MCW, X); Y = Helmert(X); @@ -824,7 +824,7 @@ void trymath() Clean(Z,0.000000001); Print(Z); Z = Helmert(X,true).row(25) - X.sum_columns() / 5.0; Clean(Z,0.000000001); Print(Z); - + I.resize(15); X = I; Z = Helmert_transpose(X, true) - Helmert(X, true).t(); @@ -832,15 +832,15 @@ void trymath() I.resize(14); Y = I; Z = Helmert(X) - Helmert_transpose(Y).t(); Clean(Z,0.000000001); Print(Z); - - - + + + } - - - - - + + + + + // cout << "\nEnd of Seventeenth test\n"; } diff --git a/extern/newmat/tmti.cpp b/extern/newmat/tmti.cpp index 577e3e1..c74057e 100644 --- a/extern/newmat/tmti.cpp +++ b/extern/newmat/tmti.cpp @@ -237,3 +237,4 @@ void trymati() ///@} + diff --git a/extern/newmat/tmtj.cpp b/extern/newmat/tmtj.cpp index 8e5a997..9463f0e 100644 --- a/extern/newmat/tmtj.cpp +++ b/extern/newmat/tmtj.cpp @@ -142,7 +142,7 @@ void trymatj() SymmetricBandMatrix SB(7,3); SymmetricMatrix S; S << (B+B.t()); SB.Inject(S); A = BA; S = SB; - Matrix X; + Matrix X; X = SP(BA,SB); X=X-SP(A,S); Print(X); X = SP(BA*2,SB); X=X-SP(A,S*2); Print(X); X = SP(BA,SB/4); X=X-SP(A/4,S); Print(X); diff --git a/extern/newmat/tmtk.cpp b/extern/newmat/tmtk.cpp index f1db617..4a57bc2 100644 --- a/extern/newmat/tmtk.cpp +++ b/extern/newmat/tmtk.cpp @@ -61,7 +61,7 @@ void trymatk() A1.CleanUp(); B1.CleanUp(); cout << "LowerTriangularMatrix\n"; - LowerTriangularMatrix A2(35), B2(35); + LowerTriangularMatrix A2(35), B2(35); for (i=0; i<35; i++) for (j=0; j<=i; j++) { A2[i][j] = i+100*j; B2(i+1,j+1) = i+100*j; } X = A2 - B2; Print(X); Y = X; @@ -176,7 +176,7 @@ void trymatk() } Print(X); Print(Y); Aa.CleanUp(); Ba.CleanUp(); - + // test special constructors used in Numerical Recipes for C++ Real a[] = {1.2, 5.6, 7.9, 3.8, 4.5, 1.3, 5.2, 9.9, 2.1, 4.7, 0.0, 1.6 }; diff --git a/extern/newmat/tmtm.cpp b/extern/newmat/tmtm.cpp index 9e103d6..057a28c 100644 --- a/extern/newmat/tmtm.cpp +++ b/extern/newmat/tmtm.cpp @@ -264,7 +264,7 @@ void trymatm() M = AB; C -= M; Print(C); C << M; C += -M; Print(C); - + } @@ -272,3 +272,8 @@ void trymatm() ///@} + + + + +