Basic usage of boost. multi_array (2), boostscopedarray

Source: Internet
Author: User

Basic usage of boost. multi_array (2), boostscopedarray

// Made by David su33 // # include "stdafx. h "# include <boost/config. hpp> # include <boost/multi_array/extent_gen.hpp> # include <boost/multi_array.hpp> # include <boost/pool. hpp> # include <boost/pool/pool_alloc.hpp> # include <boost/array. hpp> # include <boost/lambda. hpp> # include <boost/assign. hpp> # include <boost/typeof. hpp> # include <iostream> # include <cassert> # include <vector> # in Clude <algorithm> using namespace std; typedef boost: pair <double> FastPoolAllocator; typedef boost: multi_array <double, 3, struct> Multi3Array; void mult_array_access (Multi3Array & mult3 ); void show_dims (Multi3Array & mult3); void sub_view (Multi3Array & mult3); template <class T> bool check_ptr (T & v1, T & v2); void test_multi_array () {// using namespace boost; // You can also set the storage sequence of dimensions. // Multi3Array Mult3Array (boost: multi_array_types: extent_gen: extents () [3] [4] [5]); // Multi3Array mult3Array (boost :: extents [3] [4] [5]); // Right Usage // Why cannot I directly write boost: detail: multi_array: extent_gen <3> extentgen3 = boost :: detail: multi_array: extent_gen <0> () [3] [4] [5]; // Multi3Array mult3Array (extentgen3); // Right Usage //??? // The relation of operator order cannot be written, because the operator order of () is high, so // boost: detail: multi_array: extent_gen <0> () [...], [...] no first parsing // Multi3Array mult3Array (boost: detail: multi_array: extent_gen <0> () [3] [4] [5]); // Error UsageMulti3Array mult3Array (boost: detail: multi_array: extent_gen <0> () [3] [4] [5]); // Right Usageint nDims = mult3Array. num_dimensions (); assert (mult3Array. num_dimensions () = 3); assert (mult3Array. num_elements () = 3*4 * 5); int sz = mult3Array. size (); // boost: array <unsigned, 3> dimArray = {3, 4, 5}; Multi3Array mutl3Array2 (dimArray); assert (mutl3Array2. num_elements () = mult3Array. num_elements (); mult_array_access (mult3Array); show_dims (mult3Array); sub_view (mult3Array);} void mult_array_access (Multi3Array & mult3) {boost: array <long, 3> idx = {0, 0, 0}; assert (mult3 [0] [0] [0] = mult3 (idx )); mult3 [0] [0] [0] = 100; assert (mult3 (idx) = 100); int I = 0; double * pData = mult3.data (); std: for_each (pData, pData + mult3.num _ elements (), boost: lambda: _ 1 = boost: lambda: var (I) ++); I = 0; // reset I = 0; boost: array <int, 3> idx3; assert (mult3 [0] [0] [0] = 0 ); for (int x = 0; x <3; ++ x) {for (int y = 0; y <4; ++ y) {for (int z = 0; z <5; ++ z) {idx3 = boost: assign: list_of (x) (y) (z); assert (mult3 (idx3) = I ++) ;}}}cout <"test passed" <endl ;} Void show_dims (Multi3Array & mult3) {typedef Multi3Array: size_type MSizeType; for (int I = 0; I <mult3.num _ dimensions (); ++ I) {std :: cout <"Dims [" <I <"]" <"=" <mult3.shape () [I] <endl ;} const MSizeType * oldShape = mult3.shape (); vector <MSizeType> v3 (3, 0); std: copy (oldShape, oldShape + mult3.num _ dimensions (), v3.begin ()); boost: array <int, 3> arr3 = {1, 1, 4}; // mult3.reshape (arr3); // shape must keep size consta Nt, if size is same, use this; mult3.resize (arr3); // if multi_array's num_numbers () is not same use this; for (int I = 0; I <mult3.num _ dimensions (); ++ I) {assert (mult3.shape () [I] = arr3 [I]);} // BOOST_AUTO (shapeList, mult3.shape (); const MSizeType * shapeList = mult3.shape (); cout <* mult3.shape () <endl; // reset to old for testingmult3.resize (v3 ); // right usage // mult3.resize (oldShape); // error usage // You cannot directly assign values like this. Otherwise, the following error is reported. // The cause is that the value passed in by resize will be checked by the container. // h: \ boost \ boost_1_56_0 \ boost \ concept_check.hpp (1061 ): error C2825: 'C': must be a class or namespace when followed by ':' // 1> h: \ boost \ boost_000056_0 \ boost \ concept_check.hpp (1040 ): see reference to class template instantiation 'boost :: collection <C> 'being compiled // 1> with // 1> [// 1> C = const unsigned int * // 1>] // 1> h: \ boost \ boost_000056_0 \ boost \ concept \ Detail \ has_constraints.hpp (42): see reference to class template instantiation 'boost :: collectionConcept <C> 'being compiled // 1> with // 1> [// 1> C = const unsigned int * // 1>] // 1> h: \ boost \ boost_000056_0 \ boost \ concept \ detail \ msvc. hpp (58): see reference to class template instantiation 'boost: concepts :: not_satisfied <Model> 'being compiled // 1> with // 1> [// 1> Model = boost: CollectionConcept <const u Nsigned int *> // 1>] // 1> h: \ boost \ boost_000056_0 \ boost \ concept_check.hpp (51): see reference to class template instantiation 'boost: concepts :: require <Model> 'being compiled // 1> with // 1> [// 1> Model = boost :: collectionConcept <const unsigned int *> // 1>] // 1> h: \ boost \ boost_000056_0 \ boost \ multi_array.hpp (386): see reference to function template instantiation 'void boost:: function_requires <boost: C OllectionConcept <C> (Model *) 'being compiled // 1> with // 1> [// 1> C = const unsigned int *, // 1> Model = boost: CollectionConcept <const unsigned int *> // 1>] // 1> h: \ boost_dev_spaces \ boost \ boost1 \ boost1.cpp (116 ): see reference to function template instantiation 'boost: multi_array <T, NumDims, Allocator> & boost: multi_array <T, NumDims, Allocator> :: resize <const unsigned int *> (const ExtentList &) 'being Compiled // 1> with // 1> [// 1> T = double, // 1> NumDims = 3, // 1> Allocator = FastPoolAllocator, // 1> ExtentList = const unsigned int * // 1>] // 1> h: \ boost \ boost_1_56_0 \ boost \ concept_check.hpp (1061): error C2039: 'value _ type': is not a member of ''global namespace ''// 1> h: \ boost \ boost_1_56_0 \ boost \ concept_check.hpp (1061): error C2146: syntax error: missing '; 'before identifier' value _ type' // 1> h: \ boost \ Boost_000056_0 \ boost \ concept_check.hpp (1061): error C2602: 'boost: Collection <C >:: value_type 'is not a member of a base class of 'boost :: collection <C> '// 1> with // 1> [// 1> C = const unsigned int * // 1>] // 1> h: \ boost \ boost_000056_0 \ boost \ concept_check.hpp (1061): see declaration of 'boost: Collection <C> :: value_type '// 1> with // 1> [// 1> C = const unsigned int * // 1>] // 1> h: \ boost \ boost_1_56_0 \ boost \ Concept_check.hpp (1061): error C2868: 'boost: Collection <C >:: value_type ': illegal syntax for using-declaration; expected qualified-name // 1> with // 1> [// 1> C = const unsigned int * // 1>]} // ====== IsSame ============== template <class T, class U> struct MIsSame; template <class T, class U> struct MIsSame {BOOST_STATIC_CONSTANT (bool, value = false) ;}; template <class T> struct MIsSame <T, t> {BOOST_STATIC_CONSTANT (Bool, value = true) ;}; // ======== StaticAssert ====== template <bool> struct MStaticAssert; template <> struct MStaticAssert <true >{}; // ==== StaticAssertMarco ====#define MSTATIC_ASSERT_MARCO (Cond) \ do {\ MStaticAssert <Cond> sa; \ sa = sa; \} while (0) // when the macro is defined and divided into multiple rows, \ must be followed by no separator or annotation // for disable warning 4101, unreferenced local variable // do {} while (0) for user to add last ';' // # define SUB_ARRAYVIEWvoid sub_view (Multi3Array & mult3) {// # if defined (_ MSC_VER) // # pragma message ("XXX") control information output display // # if defined (SUB_ARRAYVIEW) // # pragma message ("SUB_ARRAYVIEW is Defined! ") // # Endif # define SUB_ARRAYVIEW (x) \ typedef Multi3Array: array_view <x >:: type ArrayView # x; SUB_ARRAYVIEW (3); SUB_ARRAYVIEW (2 ); SUB_ARRAYVIEW (1); // three IndexRange statements: typedef Multi3Array: index_range IndexRange; typedef boost: multi_array_types: index_range IndexRangeType; typedef boost: detail: multi_array :: index_range <ptrdiff_t, unsigned> IndexRangeType2; // bool isOK = MIsSame <IndexRange, IndexRangeType >:: value; assign (MIsSame <IndexRange, IndexRangeType >:: value )); // MSTATIC_ASSERT_MARCO (MIsSame <int, double >:: value); // The compiled MSTATIC_ASSERT_MARCO (MIsSame <IndexRangeType, IndexRangeType2 >:: value )); // aggregate (MIsSame <int, IndexRangeType2 >:: value); // The compiled typedef Multi3Array: size_type MSizeType; vector <MSizeType> v (mult3.num _ dimensions (), 0); copy (mult3.shape (), mult3.shape () + mult3.num _ dimensions (), v. begin (); copy (v. begin (), v. end (), std: ostream_iterator <MSizeType> (cout, ";"); cout <endl; // The obtained subview is the original reference for accessing ArrayView3 aview3 = mult3 [boost: indices [IndexRange ()] [IndexRange (1, 2)] [IndexRange (3, (5)]; const MSizeType * theShape = aview3.shape (); cout <"mult3-shape:"; copy (mult3.shape (), mult3.shape () + mult3.num _ dimensions (), std:: ostream_iterator <int> (std: cout); cout <endl; cout <"aview3-shape:"; copy (aview3.shape (), aview3.shape () + mult3.num _ dimensions (), std: ostream_iterator <int> (std: cout); cout <endl; // ArrayView cannot modify the shape size. // This location requires an index. // aview3 [0] [1] [3] should not be written. The starting offset {0, 1, 3} aview3 [0] [0] [0] = 10; assert (mult3 [0] [1] [3] = 10 ); mult3 [0] [1] [3] = 1000; assert (aview3 [0] [0] [0] = 1000); // boost :: array <MSizeType, 3> idx3 = {0, 0, 0}; boost: array <MSizeType, 3> idx32 = {0, 1, 3}; aview3 (idx3) = 10; assert (mult3 (idx32) = 10); mult3 (idx32) = 1000; assert (aview3 (idx3) = 1000); // obtain the 2D view, the first index is always 0ArrayView2 aview21 = mult3 [boost: indices [0] [IndexRange (1, 2)] [IndexRange (3, 5)]; arrayView2 aview22 = mult3 [boost: indices [1] [IndexRange (1, 2)] [IndexRange (3, 5)]; ArrayView2 aview23 = mult3 [boost :: indices [2] [IndexRange (1, 2)] [IndexRange (3, 5)]; assert (2 = aview21.num _ dimensions ()); assert (2 = aview22.num _ dimensions (); assert (2 = aview23.num _ dimensions ()); // 2 = 2 is bool // 2 = (true/false) Cause error // assert (2 = 2 = 2 = 2 ); // must be falseint xoffset = 1, yoffset = 3; boost: array <MSizeType, 2> idx2 = {0, 0}; boost: array <MSizeType, 3> idx21 = {0, 0 + xoffset, 0 + yoffset}; boost: array <MSizeType, 3> idx22 = {1, 0 + xoffset, 0 + yoffset }; boost: array <MSizeType, 3> idx23 = {2, 0 + xoffset, 0 + yoffset}; check_ptr (aview21 (idx2), mult3 (idx21 )); check_ptr (aview22 (idx2), mult3 (idx22); check_ptr (aview23 (idx2), mult3 (idx23 )); cout <"sub-view test all passed" <endl; # undef SUB_ARRAYVIEW} template <class T> bool check_ptr (T & v1, T & v2) {assert (v1 = v2); return (& v1 = & v2);} int _ tmain (int argc, _ TCHAR * argv []) {test_multi_array (); getchar (); return 0 ;}


2, 4-D usage in real life

In real life? Do you want to raise flowers? There are other plans.

2, 4-D amine salt is a selective and Efficient Organic herbicide, which has the similar effect of plant growth hormone. It can suck into the plant and transmit it to other parts. Low concentration can effectively stimulate growth, it can be used as a plant growth regulator; if it is high, it can inhibit growth. If it is higher, it can cause malformed and lethal growth of plants. As the herbicide used after the bud, the photosynthetic plants of the single leaf are very sensitive to the stress resistance of the plant. This selectivity is used, it can be used in the field of rice and wheat grass crops to prevent the removal of Broad-leaf weeds.

If we want to promote the growth of the double leaf plants, we can apply 10-100ppm (different plants require different concentrations). If we want to remove the double leaf weeds, we can apply 500ppm-(same as above ), it can inhibit its growth and germination or distortion, and promote the growth of single leaf. When it reaches a high concentration of 2000ppm-, it will kill many double leaf plants, however, single-leaf plants cannot be guaranteed.

Ppm indicates the unit of concentration used for dilution of pesticides or fertilizers with a small amount of pesticides or fertilizers during the prevention and treatment of pests and diseases in agricultural production activities. It is usually called "one thousandth X ". Currently, in most sci-tech journals, ppm is no longer used, instead of "‰", which is converted into ‰: 1ppm = 0.001 ‰.

But at the same time, he also has a dangerous side:

1. Health Hazards
Infiltration pathway: inhalation, food intake, percutaneous absorption.
Health hazards: It may be harmful to the body if it can be imported, ingested, or absorbed by the skin. Stimulation of eyes and skin, and repeated exposure to liver and heart damage. Can cause convulsions.

Ii. Environmental Behavior
Hazardous features: open fire, high heat and combustible. Decomposition by high heat, releases irritating hydrogen chloride gas.
Combustion (decomposition) Products: carbon monoxide, carbon dioxide, chloride.

Conclusion: If you want to use it in your home, you can avoid it. The side effects are too large. If you want to use it in a field, greenhouse, or outdoors, I think it's okay, but you need to analyze the specific plants, you can consult the relevant persons and never try it on your own to avoid the loss.

What is the usage of the secret of Medieval 2?

In the game, press ~, Call up the console and enter the following content to activate relevant functions (please enter the correct name, such as family and city ):
1. Increase the urban population:
<> City name and quantity
Add_population <settlement name> <number>

2. assign any feature of a faction to a general:
<> Role name, feature name, and level
Give_trait <character> <trait> <level number>

3. Automatically build the construction production queue in the city: -------------------------------------------------------------- I personally think it is very useful.
Complete the building in the waiting column. <> it is the city name.
Process_cq <settlement name>
For example, I want to build a building in London. First, you can arrange up to six building points at a time.
Press '(next to 1)
Enter process_cq London and then press the shuttle bus. (There is a space between cq and London)
In this way, the first building is ready. Press the primary key and the above password will come out again (you do not need to repeat it again ).
It is sequentially created.

4. Get the specified amount of money:
Add_money <number>

5. open/close the fog of war
Toggle_fow

6. Press the Auto Retaliate button to automatically win the next battle.
Enter the name of the attacker and defender in the battle field <>.
Auto_win <attacker | defender>

7. Add troops in the city ---------------------------------------------------------------------------- to possess any troops immediately. We recommend that you !!!
Create_unit settlement/charactername unit_ID amount exp/armour/weapon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.