Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function: NdArrayConstIterator Line: 70 Error: NdArray has not been initialized. #191

Closed
ArEnSc opened this issue May 29, 2023 · 1 comment

Comments

@ArEnSc
Copy link

ArEnSc commented May 29, 2023

Describe the bug
At runtime without optimizations I am running into this error 1/3 times.
I am building on iOS. Maybe this is a timing issue with library initialization?

terminating with uncaught exception of type std::runtime_error: File: /opt/homebrew/opt/numcpp/include/NumCpp/NdArray/NdArrayIterators.hpp
Function: NdArrayConstIterator
Line: 70
Error: NdArray has not been initialized.

To Reproduce

#pragma once
#ifndef RWKV_TYPICAL_H
#define RWKV_TYPICAL_H

#import <Foundation/Foundation.h>

#ifdef __cplusplus
extern "C" {
#endif

int typical(float* _logits, float _temp = 0.9, float _tau = 0.8);
int greedy(float* _logits,float _temp = 0.9);
#ifdef __cplusplus
}
#endif

#endif
#import "typical.h"
#include "NumCpp.hpp"

#include <cassert>
int typical(float* _logits, float _temp, float _tau)
{
    assert(_logits != NULL);
    int len = 50277;
    // choose top token
    nc::NdArray<double> logits = nc::NdArray<double>(1,len);
    for (int i = 0; i < len; i++) {

        logits[i] = _logits[i];
    }

    nc::NdArray<double> probs = nc::special::softmax(logits);
    logits = -nc::log(probs);
    nc::NdArray<double> ent = nc::nansum(logits * probs);
    nc::NdArray<double> shifted_logits = nc::abs(logits - ent);
    nc::NdArray<uint32_t> sorted_ids = nc::argsort(shifted_logits);
    nc::NdArray<double> sorted_logits = shifted_logits[sorted_ids];
    nc::NdArray<double> sorted_probs = probs[sorted_ids];
    nc::NdArray<double> cumulative_probs = nc::cumsum(sorted_probs);
    nc::NdArray<double> tau = nc::NdArray<double>(1,1);
    tau[0] = _tau;
    auto mask = (cumulative_probs < tau);
    // convert mask to int
    nc::NdArray<int> mask_int = nc::NdArray<int>(1,mask.size());
    for (int i = 0; i < mask.size(); i++) {
        mask_int[i] = mask[i];
    }

    // get cutoff
    auto cutoff = nc::sum(mask_int);
    // set probs to 0
    probs[shifted_logits > sorted_logits[cutoff]] = 0;
    if (_temp != 1.0) {
        probs = nc::power(probs, 1.0 / _temp);
    }

    // get random token
    auto out = nc::random::discrete<int>(nc::shape(tau),probs);
    return out[0];
}

Expected behavior
Expected that it does not crash because of that issue

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

dpilger26 added a commit that referenced this issue Jun 22, 2023
* starting a new release candidate branch

* fixed clang tidy target, fixed some warnings

* fix some clang-tidy warnigns

* minor cleanup

* changing seed for functions unit tests

* formatting unit test code

* still fiddling with unit tests

* adding some utils to develop

* still fiddling with unit tests

* still fiddling with unit tests

* still fiddling with unit tests

* still messing with unit tests

* incrementing version in building docs

* removed boost/filesystem from readme example in support of PR #190

* added Poly1D operator() and eval() methods for evaluating arrays of values per PR #192.

* made reshape() documentation more clear for Issue #193

* removing unncessary throw exception from ndarray constIterator in support of Issue #191

* fixed some clang build errors from last commit

* append() now works with empty input arrays for Issue #194

* intermediate commit of new functionality, still some cleanups and alot of tests to write

* added unit tests for wrap and wrap2Pi

* adding some unit tests to incorporate

* intermediate commit

* another intermidiate commit

* intermediate commit, still lots of tests to write for the new functionality

* fixed some build errors

* fixed a build error

* added unit tests for cartesian

* added tests for new Vec3 constructor, normalize

* added unit tests for rows() and columns()

* cleanup/organized the tests a bit

* added gtests for Logger and BinaryLogger

* makeing ctest work

* don't build the logger gtests if NO_USE_BOOST is defined

* added tests for new celestial constructors

* added unit tests for new reference_frames

* added tests for euler and orientation

* completed bindings for new transforms

* added test stubs for transforms

* test stubs for all transforms

* completed alot of transforms unit tests

* missed some files from last commit

* cleanup of transforms tests

* add pymap3d to python requirements

* added AzElToECEF and AzElToLLA transforms

* added geocentricToGeodetic and vice versa to transforms

* renamed AzEl to AER and added range field, still need to populate

* making some functions lower case

* started adding range to some transforms

* adding more range calculations

* renamed some transforms for uniformity

* more transforms cleanup

* all transforms now have passing unit tests

* added vector overloads to various stack functions

* regenerated the docs

---------

Co-authored-by: = <=>
Co-authored-by: GitLab Runner <gitlab.runner@ballaerospace.com>
Co-authored-by: Pilger, David <david.pilger@ballaerospace.com>
@dpilger26
Copy link
Owner

Fixed as part of release version 2.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants