boostorg / multi_array Goto Github PK
View Code? Open in Web Editor NEWBoost.org multi_array module
Home Page: http://boost.org/libs/multi_array
Boost.org multi_array module
Home Page: http://boost.org/libs/multi_array
Using multi_array, MSVC (VS 2019, VS 2022) emits the following warnings (using Boost release 1.82.0, but current code in the repo includes the same global variable and argument name):
`C:\lo\build\workdir\UnpackedTarball\boost\boost/multi_array/multi_array_ref.hpp(615): warning C4459: declaration of 'extents' hides global declaration
C:\lo\build\workdir\UnpackedTarball\boost\boost/multi_array/base.hpp(69): note: see declaration of 'boost::anonymous-namespace'::extents'
This prevents warning-free builds, or requires pollution of the code with pragmas. Would it be possible to rename the constructor argument name?
When I use boost::multi_array
with boost::fortran_storage_order()
, and I want to .resize
by only the latest (rightmost) dimension, the current implementation is a nested N
function call (std::copy
), one by dimension.
The same functionality can be reached with one std::copy
on the storage.
This minimal example shows the problem:
https://godbolt.org/z/GWbxcM14h
Hello, this is a copy of my email I sent to the boost-users mailing list, as it might improve visibility.
I'd love to be able to use multi_array with classes that do not have a default constructor. At the moment, this is impossible, as both the constructor and resize functions only take extents as arguments (and possibly some other options), but no value_type, as for example std::vector does. Thus, trying to store objects without a default constructor in a multi_array results in hard compiler errors, with no workaround that I know of.
This happens to me fairly often, as I use multi_array to organize sets of complex objects. If there is a technical reason why this is not possible, I would also be happy to learn it.
... or at least make its members protected to allow a subclass to do so.
swap
would be substantially the same as the current resize
method.
Background: I use a subclass of multi_array
in order to resize during assignment to get around the most dagnerous multi_array pitfall. This works, but I'd also like to fix another longstanding inefficiency ( #24 ) while I'm at it. Unfortunately the private
data members make it impossible to fix in my subclass (barring a type-punning hack).
The following program:
#include "boost/multi_array.hpp"
using Emax = boost::multi_array<double, 7>;
int main() {
Emax emax(boost::extents[40][30][50][5][5][5][5]);
return 0;
}
when run under valgrind gives the following warnings:
==20786== Memcheck, a memory error detector
==20786== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==20786== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==20786== Command: ./test_arr
==20786==
==20786== Warning: set address range perms: large range [0x5171040, 0x16f8b340) (undefined)
==20786== Warning: set address range perms: large range [0x5171028, 0x16f8b358) (noaccess)
==20786==
==20786== HEAP SUMMARY:
==20786== in use at exit: 0 bytes in 0 blocks
==20786== total heap usage: 2 allocs, 2 frees, 300,072,704 bytes allocated
==20786==
==20786== All heap blocks were freed -- no leaks are possible
==20786==
==20786== For lists of detected and suppressed errors, rerun with: -s
==20786== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
versions are:
gcc version 8.3.1 20190223 (Red Hat 8.3.1-2) (GCC)
valgrind-3.15.0
The bug described in https://svn.boost.org/trac10/ticket/6554 seems to return. I tried the example from this bug in godbolt: https://godbolt.org/z/4vMf8oo4q and it fails to compile. The code I used is:
#include <boost/multi_array.hpp>
struct data
{
int value;
};
typedef boost::multi_array<data, 2> array_type;
int main() {
array_type a(boost::extents[4][5]);
// ERROR: Cannot compile this line
a.begin()->begin()->value = 7;
// Compiles successfully
(*a.begin()->begin()).value = 5;
return 0;
}
All versions of boost on godbolt (1.64 to 1.79) seem to be affected.
I am trying to use multi_arrays in a CUDA GPU project and NVCC is unable to compile it.
NVCC version is 12.3 (error also occurs with other versions)
Boost version is 1.84.0 (error also occurs with other versions)
I used the following command to compile:
nvcc -o C:/_repro/output.exe C:/_repro/main.cu -IC:/boost_1_84_0
I am using the following code (main.cu):
#include <boost/multi_array.hpp>
int main()
{
boost::multi_array<int, 3> my_arr;
return 0;
}
I get the following errors:
C:/boost_1_84_0\boost/multi_array/base.hpp(408): error C2988: unrecognizable template declaration/definition
C:/boost_1_84_0\boost/multi_array/base.hpp(408): error C2143: syntax error: missing ')' before '<'
C:/boost_1_84_0\boost/multi_array/base.hpp(408): error C2143: syntax error: missing ';' before '<'
C:/boost_1_84_0\boost/multi_array/base.hpp(408): error C2238: unexpected token(s) preceding ';'
C:/boost_1_84_0\boost/multi_array/base.hpp(408): error C2059: syntax error: '<'
C:/boost_1_84_0\boost/multi_array/base.hpp(414): error C2059: syntax error: ')'
C:/boost_1_84_0\boost/multi_array/base.hpp(494): error C2143: syntax error: missing ';' before '}'
C:/boost_1_84_0\boost/multi_array/base.hpp(494): error C2238: unexpected token(s) preceding ';'
Several more errors occur when I attempt to use further multi_array functionality such as extents and indexing, this is just a minimal example. Additionally, the code compiles just fine when you change the file extention to .cpp, but I assume this is just NVCC falling back on the default cl.exe compiler. I specifically need multi_arrays to compile within a .cu file along with CUDA device code.
Any help is much appreciated, thank you.
The following macros are missing a BOOST_ prefix, which is against Boost library guidelines:
./libs/multi_array/test/generative_tests.hpp:#ifndef GENERATIVE_TESTS_RG072001_HPP
./libs/multi_array/test/generative_tests.hpp:#define GENERATIVE_TESTS_RG072001_HPP
./libs/multi_array/test/generative_tests.hpp:#endif // GENERATIVE_TESTS_RG072001_HPP
./boost/multi_array/base.hpp:#ifndef BASE_RG071801_HPP
./boost/multi_array/base.hpp:#define BASE_RG071801_HPP
./boost/multi_array/base.hpp:#endif // BASE_RG071801_HPP
./boost/multi_array/collection_concept.hpp:#ifndef COLLECTION_CONCEPT_RG103101_HPP
./boost/multi_array/collection_concept.hpp:#define COLLECTION_CONCEPT_RG103101_HPP
./boost/multi_array/collection_concept.hpp:#endif // COLLECTION_CONCEPT_RG103101_HPP
./boost/multi_array/range_list.hpp:#ifndef RANGE_LIST_RG072501_HPP
./boost/multi_array/range_list.hpp:#define RANGE_LIST_RG072501_HPP
./boost/multi_array/range_list.hpp:#endif // RANGE_LIST_RG072501_HPP
./boost/multi_array/iterator.hpp:#ifndef ITERATOR_RG071801_HPP
./boost/multi_array/iterator.hpp:#define ITERATOR_RG071801_HPP
./boost/multi_array/iterator.hpp:#endif // ITERATOR_RG071801_HPP
./boost/multi_array/copy_array.hpp:#ifndef COPY_ARRAY_RG092101_HPP
./boost/multi_array/copy_array.hpp:#define COPY_ARRAY_RG092101_HPP
./boost/multi_array/copy_array.hpp:#endif // COPY_ARRAY_RG092101_HPP
./boost/multi_array/subarray.hpp:#ifndef SUBARRAY_RG071801_HPP
./boost/multi_array/subarray.hpp:#define SUBARRAY_RG071801_HPP
./boost/multi_array/subarray.hpp:#endif // SUBARRAY_RG071801_HPP
Hello!
I think it would be great if multi_array had move semantics, at the moment unfortunately it is inefficient to return multi_arrays by value and the workaround is not great:
I think having move construction / assignment would be great
While not a C++ N-D array, NumPy provides an N-D array for Python. Might be nice to include this in the related work section of the docs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.