Coder Social home page Coder Social logo

cristi1990an / tensor-plus-plus Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 3.0 190 KB

tensor_lib::tensor is a class template that describes a mathematical tensor, implemented as a heap allocated array. It is build as an alternative to structures such as std::vector <std::vector <std::vector<...>>>, replicating its behaviour and syntax almost entirely with the added benefits of having its data contiguous in memory.

C++ 99.56% CMake 0.44%
cpp cpp20 tensor

tensor-plus-plus's People

Contributors

cristi1990an avatar federandink avatar

Stargazers

 avatar

Watchers

 avatar

tensor-plus-plus's Issues

From your comment on #3 here are some suggestions

From your comment on #3 here are some suggestions,

Project layout

  1. please provide a .clang-format file into the repo and use clang-format, it will help contribution
  2. organize your files, make tests/src/include directories
  3. use more tools, like sanitizers/clang-tidy...
  4. you might want to use a testing library (e.g.: boost test, google test, ...)
  5. watch out for your repo, there is a lot of duplicated commits, and strange merge from master, maybe get a better understanding of how Git works: https://git-scm.com/book/en/v2
    • you can use git revert for some or git reset/git commit --amend if it's not pushed
  6. you should use a better name for 'helpers.hpp' as it is just IO (generally avoid generic names like helper, utils, controller...)

On the code itself:

  1. you are using redundant == true and == false (clang-tidy is giving me this warning btw, you'd have to activate readability checks)
  2. be consistent on the use of ! or not pick one (! is more common)
  3. I am not a big fan of loops and ifs without blocks {} to avoid problems and be consistent
  4. param_1 You might want to name those (and also TEST_1...)
  5. generally avoid using raw new/delete it's not exception safe, etc, and in this case I think you could use std::swap_ranges, and why are you making copies?
    T* aux = new T[size];
  6. also, you could factorize your duplicated code, like for instance, call the lvalue swap simply like swap(left, right) in the rvalue overload, it works because the rvalue has been named in the function:
    void swap(subdimension<T, Rank, allocator_type>&& left, subdimension<T, Rank, allocator_type>&& right)
  7. if you haven't watched it already, here is a great talk on standard algorithms: https://www.youtube.com/watch?v=2olsGf6JIkU, generally CppCon is great and freely available on youtube :)
  8. avoid using reinterpret_cast and read carefully the rules if you don't know them already (it's always good to reread them: https://en.cppreference.com/w/cpp/language/reinterpret_cast), moreover here you could just call _data.data() or to be more generic std::data(_data):
    return reinterpret_cast<T*>(&it);
  9. if you want to be more generic, you should prefer free function for begin/end/data/size/... (std::begin/std::end/... instead of methods)
  10. swap and move operations should not throw
  11. I think you might want to follow more the rule of 0: https://en.cppreference.com/w/cpp/language/rule_of_three (e.g.: for your iterators) special members
  12. you should use std::equal with 4 iterators instead of 3 to do bound checking (I see that by design they have the same size, you should put comments at least then, there is also == it should work, maybe create a span with a templated size) minor issue
  13. This would probably better be some kind of assert, this seems to be a logic error:
    throw std::runtime_error("Can't swap subdimensions of different sizes!\n");
  14. Choose to use (void) or () and stay consistent:
    reference operator* (void) const noexcept

I might not have understood all your math/thinking/vision. Also I haven't done a detailed review.

Great work, Hope that'll help :)

Non conformant code (following the thread on reddit)

Hi, Nihili0 from reddit here

Just to let you know before you hit cryptic compiler error

constexpr void construct_order_array<1u>(const std::initializer_list<T>& data) TENSORLIB_NOEXCEPT_IN_RELEASE

you can't specialize functions on untemplated arguments

you can do:

struct S {
  template<typename T>
  void f(T const& t) {
  }

  template<>
  void f(int const& i) {
  }
};

but you can't do:

template<typename T>
struct S {
  template<typename U>
  void f(U const& u) {
  }

  template<>
  void f(int i) { // error: not a const&
  }

  template<std::size_t R>
  void f(useful_specializations::nested_initializer_list<T, R> const&) {
  }

  template <>
  constexpr void construct_order_array<1u>(const std::initializer_list<T>& data) { // error: not specializing on templated type
  }
};

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.