Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  cxx11_tensor_io.cpp

  Sprache: C
 

// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "main.h"
#include <sstream>
#include <string>
#include <Eigen/CXX11/Tensor>


template<int DataLayout>
static void test_output_0d()
{
  Tensor<int0, DataLayout> tensor;
  tensor() = 123;

  std::stringstream os;
  os << tensor;

  std::string expected("123");
  VERIFY_IS_EQUAL(std::string(os.str()), expected);
}


template<int DataLayout>
static void test_output_1d()
{
  Tensor<int1, DataLayout> tensor(5);
  for (int i = 0; i < 5; ++i) {
    tensor(i) = i;
  }

  std::stringstream os;
  os << tensor;

  std::string expected("0\n1\n2\n3\n4");
  VERIFY_IS_EQUAL(std::string(os.str()), expected);

  Eigen::Tensor<double,1,DataLayout> empty_tensor(0);
  std::stringstream empty_os;
  empty_os << empty_tensor;
  std::string empty_string;
  VERIFY_IS_EQUAL(std::string(empty_os.str()), empty_string);
}


template<int DataLayout>
static void test_output_2d()
{
  Tensor<int2, DataLayout> tensor(53);
  for (int i = 0; i < 5; ++i) {
    for (int j = 0; j < 3; ++j) {
      tensor(i, j) = i*j;
    }
  }

  std::stringstream os;
  os << tensor;

  std::string expected("0  0  0\n0  1  2\n0  2  4\n0  3  6\n0  4  8");
  VERIFY_IS_EQUAL(std::string(os.str()), expected);
}


template<int DataLayout>
static void test_output_expr()
{
  Tensor<int1, DataLayout> tensor1(5);
  Tensor<int1, DataLayout> tensor2(5);
  for (int i = 0; i < 5; ++i) {
    tensor1(i) = i;
    tensor2(i) = 7;
  }

  std::stringstream os;
  os << tensor1 + tensor2;

  std::string expected(" 7\n 8\n 9\n10\n11");
  VERIFY_IS_EQUAL(std::string(os.str()), expected);
}


template<int DataLayout>
static void test_output_string()
{
  Tensor<std::string, 2, DataLayout> tensor(53);
  tensor.setConstant(std::string("foo"));

  std::cout << tensor << std::endl;

  std::stringstream os;
  os << tensor;

  std::string expected("foo  foo  foo\nfoo  foo  foo\nfoo  foo  foo\nfoo  foo  foo\nfoo  foo  foo");
  VERIFY_IS_EQUAL(std::string(os.str()), expected);
}


template<int DataLayout>
static void test_output_const()
{
  Tensor<int1, DataLayout> tensor(5);
  for (int i = 0; i < 5; ++i) {
    tensor(i) = i;
  }

  TensorMap<Tensor<const int1, DataLayout> > tensor_map(tensor.data(), 5);

  std::stringstream os;
  os << tensor_map;

  std::string expected("0\n1\n2\n3\n4");
  VERIFY_IS_EQUAL(std::string(os.str()), expected);
}


EIGEN_DECLARE_TEST(cxx11_tensor_io)
{
  CALL_SUBTEST(test_output_0d<ColMajor>());
  CALL_SUBTEST(test_output_0d<RowMajor>());
  CALL_SUBTEST(test_output_1d<ColMajor>());
  CALL_SUBTEST(test_output_1d<RowMajor>());
  CALL_SUBTEST(test_output_2d<ColMajor>());
  CALL_SUBTEST(test_output_2d<RowMajor>());
  CALL_SUBTEST(test_output_expr<ColMajor>());
  CALL_SUBTEST(test_output_expr<RowMajor>());
  CALL_SUBTEST(test_output_string<ColMajor>());
  CALL_SUBTEST(test_output_string<RowMajor>());
  CALL_SUBTEST(test_output_const<ColMajor>());
  CALL_SUBTEST(test_output_const<RowMajor>());
}

Messung V0.5 in Prozent
C=89 H=92 G=90

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-07) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik