Git Product home page Git Product logo

hdc's People

Contributors

coobas avatar d-fridrich avatar jholloc avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

maarten-ic

hdc's Issues

[pyhdc] Numpy array in Fortran layout is interpreted as C layout?

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 ?!

Assignment of `std::vector<std::string>` gives unexpected results

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:

  • If this is supported, I would expect to either see an array of strings (or potentially a 2D character array) in vector_of_strings
  • If this is an unsupported use-case, a compile-time error should prevent assignment of a std::vector<std::string>

Segfault when creating many child nodes

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..

Constant `HDC` objects can be modified indirectly (may result in undefined behaviour)

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;
}

Expected behaviour:

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.

Actual behaviour:

Output of above test program:

{
        "only member" : 1
}
{
        "new member" : 1,
        "only member" : 1
}

Used version of the HDC library: 0.21.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.