ukaea / hdc Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
When I assign a (2+D) numpy array in Fortran layout to a HDC container, the HDC library interprets this as a C layout array. The stored array then no longer matches the source array:
Reproduction:
import pyhdc
import numpy as np
c_array = np.arange(12).reshape((3,4))
hdc = pyhdc.HDC(c_array)
print(np.array_equal(hdc.to_python(), c_array)) # True
f_array = np.asfortranarray(c_array)
hdc = pyhdc.HDC(f_array)
print(np.array_equal(hdc.to_python(), f_array)) # False ?!
Assigning a vector of strings to an HDC node compiles successfully (unless -DDEBUG
is defined), but the result is unexpected:
#include <hdc.hpp>
int main() {
HDC test;
test["vector_of_strings"] = std::vector<std::string>({"string 1", "string 2"});
test.dump();
return 0;
}
Results in output
{
"vector_of_strings" : "\u043d\u022cgU"
}
Expected behaviour:
vector_of_strings
std::vector<std::string>
Hi @jholloc,
With the current master
branch I frequently get bad_alloc
exceptions and/or SEGFAULTS when initializing many child nodes on an HDC node.
Example program:
#include <hdc.hpp>
#include <iostream>
int main() {
HDC hdc;
for (int i=0; i<1024; i++ ) {
std::string child_name = "Child#" + std::to_string(i);
try {
hdc.get_or_create(child_name);
} catch (std::exception &ex) {
std::cerr << "Caught exception '" << ex.what() << "' at i = " << i << std::endl;
return 1;
}
}
return 0;
}
When I compile and run this program on the master
branch, this results in the program SEGFAULTing.
The last release (v0.21.0) doesn't have the same problem. After doing a git bisect, the issue seems to be this commit: 5fb812b
This commit touches a lot of logic, so I cannot pinpoint a likely cause..
A function accepting a const HDC
object can (accidentally) cast away const-ness as in the following example program.
#include <hdc.hpp>
void manipulate_const_hdc(HDC const &in) {
HDC copy = in;
copy["new member"] = 1;
}
int main() {
HDC test;
test["only member"] = 1;
test.dump();
manipulate_const_hdc(test);
test.dump();
return 0;
}
The function manipulate_const_hdc
gets a constant reference to a HDC object. It shouldn't be able to alter this object as doing so results in undefined behavior, see cppreference.com:
- A const object is
- an object whose type is const-qualified, or
- a non-mutable subobject of a const object.
Such object cannot be modified: attempt to do so directly is a compile-time error, and attempt to do so indirectly (e.g., by modifying the const object through a reference or pointer to non-const type) results in undefined behavior.
The copy assignment HDC copy = in;
should either be prohibited, or it should create a (deep) copy of the HDC object such that the assignment copy["new member"] = 1;
doesn't influence the original HDC object.
Output of above test program:
{
"only member" : 1
}
{
"new member" : 1,
"only member" : 1
}
Used version of the HDC library: 0.21.0
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.