EzDevInfo.com

spire

Powerful new number types and numeric abstractions for Scala.

Sum or Product of Rationals with Spire (how to get a scala.Numeric)

I thought this should be straight forward:

import spire.math.Rational

val seq  = Vector(Rational(1, 4), Rational(3, 4))
val sum  = seq.sum      // missing: scala.Numeric
val prod = seq.product  // missing: scala.Numeric

I guess this is just a question of bringing the right stuff into implicit scope. But what do I import?

I can see that in order to get a RationalIsNumeric, I have to do something like this:

import spire.math.Numeric._
implicit val err = new ApproximationContext(Rational(1, 192))
implicit val num = RationalIsNumeric

But that just gives me a spire.math.Numeric. So I try with this additionally:

import spire.math.compat._

But no luck...


Source: (StackOverflow)

Scala Spire: could not find implicit value for evidence parameter of type spire.algebra.EuclideanRing[T] x % 12 ^

I am not really sure what's going on here. I wanted to implement a few algorithms that I would like to operate on Ints and Floats. This led me to try out Spire. Here is the simplest example of the compile error I am facing.

import spire.algebra._  
import spire.math._      
import spire.implicits._ 

def mod12[T: Numeric](x: T): T = {
  x % 12
}

Error:(17, 4) could not find implicit value for evidence parameter of type spire.algebra.EuclideanRing[T] x % 12 ^


Source: (StackOverflow)

Advertisements

Insert columns form one excel book to another in C#

I need to take values form one sheet in one Excel workbook and insert them into another existing workbook.

The values I need to take are the first 6 columns of the first file:

enter image description here

And I want to insert them at the beginning of another book like so enter image description here

I've been using Spire.Xls to read values from the first sheet and I thought I could just do the same; parse the worksheet, read the values and just paste them into the other sheet, but that wouldn't work because three of the columns I want to copy have the same header "Descripcion" so my parser would only take the values form the first descripcion column and skip the other ones.

Is there any way, using Excel.Interop or maybe Spire itself to copy and paste entire columns between workbooks? Or alternately, is there any way to get all of the 3 "descripcion" values (without rewriting the title of the columns)?


Source: (StackOverflow)

Decode Non-English text with barcode reader C#.NET

hello I have this simple example of generating a bar code and decoding it again using Spire.Barcode library

        BarcodeSettings bcsettings = new BarcodeSettings();
        bcsettings.Data = "مرحباً";
        bcsettings.Type = BarCodeType.DataMatrix;
        BarCodeGenerator bcgen = new BarCodeGenerator(bcsettings);
        System.Drawing.Image bcimg = bcgen.GenerateImage();
        System.Drawing.Bitmap bcbitmap = new System.Drawing.Bitmap(bcimg);
        String bcdata = BarcodeScanner.ScanOne(bcbitmap);
        output.Text += bcdata;

the example works very well with English but the output shows like this when I use Arabic.

Barcode output for Arabic

Is there anyway to fix this?

Thanks in advance.


Source: (StackOverflow)

File doesn't exist exception - Spire PDF for .NET

I am using the following code to attempt to print a PDF file using Spire PDF.

Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();

doc.LoadFromFile(monroneyFilename);

doc.PrinterName = monroneyPrinter;
lock (printLock)
{
    doc.PrintDocument.Print();
}

When it gets to the LoadFromFile method, it gives me a File doesn't exist exception. The rest of the code doesn't execute.

The monroneyFilename is "p:\foldername\11111111111111111.pdf" where the ones are 17 characters representing a Vehicle Identification Number.

There are no spaces in the filename or folder name, so the other answers I've seen about this do not apply.

I'm running this from within an ASP.NET Web Service.

Anyone have any ideas?


Source: (StackOverflow)

Spire PDF Table pagination

I am using Spire.PDF for .NET to create pdf file and I have following problem with table pagination:

On every page I have header and footer so I need to set paginate bounds so that table doesn't go over header and footer and I do that like this:

tableLayout.PaginateBounds = new RectangleF(0, headerHeight, page.Canvas.ClientSize.Width, page.Canvas.ClientSize.Height - headerHeight - footerHeight);

and then I draw table with:

PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);

Problem appears when I need some text before table, so table doesn't start immediately after header but it starts on some y > headerHeight. In that case table is drawn immediately after header, over text so y from "table.Draw(page, new PointF(0, y), tableLayout)" is ignored.

Can this even be achieved with Spire PDF and how?


Source: (StackOverflow)

Could not load file or assembly 'Spire.License, Version=1.3.2.40, Culture=neutral, PublicKeyToken=b1144360237c8b3f' or one of its dependencies

I am using Spire.Xls in my web project to create an excel sheet on the fly.In local every thing is working fine but once i deployed it on the Server , it is throwing exception as

System.IO.FileNotFoundException: Could not load file or assembly 'Spire.License, Version=1.3.2.40, Culture=neutral, PublicKeyToken=b1144360237c8b3f' or one of its dependencies. The system cannot find the file specified. File name: 'Spire.License, Version=1.3.2.40, Culture=neutral, PublicKeyToken=b1144360237c8b3f'

Please find below the detailed error log :-

=== Pre-bind state information === LOG: User = IIS APPPOOL\ASP.NET v4.0 LOG: DisplayName = Spire.License, Version=1.3.2.40, Culture=neutral, PublicKeyToken=b1144360237c8b3f (Fully-specified) LOG: Appbase = file:///C:/ePareeksha/ePareeksha/ LOG: Initial PrivatePath = C:\ePareeksha\ePareeksha\bin

Calling assembly : Spire.XLS, Version=7.1.0.7040, Culture=neutral, PublicKeyToken=663f351905198cb3.

LOG: This bind starts in default load context. LOG: Using application configuration file: C:\ePareeksha\ePareeksha\web.config LOG: Using host configuration file: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG: Using machine configuration file from c:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Post-policy reference: Spire.License, Version=1.3.2.40, Culture=neutral, PublicKeyToken=b1144360237c8b3f LOG: The same bind was seen before, and was failed with hr = 0x80070002.

Please guide me that how i will fix this .


Source: (StackOverflow)

Using Spire.doc, Spire.xls and Spire.Presentation in same project

It's possible to use the 3 products in the same project?

Just downloaded the free versions of each and the Spire.PDF.dll version are different and causes error "System.IO.FileLoadException: Could not load file or assembly 'Spire.Pdf, Version=3.0.10.54040, Culture=neutral, PublicKeyToken=663f351905198cb3' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

Spire.doc uses version 3.0.10.54040 and Spire.Presentation uses 3.0.49.58040

I tried using dependentAssembly

  <dependentAssembly>
    <assemblyIdentity name="Spire.Pdf" publicKeyToken="663f351905198cb3" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.10.54040" newVersion="3.0.49.58040" />
  </dependentAssembly>

But get an error

TypeLoadException: Could not load type 'sprẒ' from assembly 'Spire.Pdf,
Version=3.0.49.58040, Culture=neutral, PublicKeyToken=663f351905198cb3'.

Source: (StackOverflow)

Implicits Confusion

The following polymorphic methods compile:

import spire.math._
import spire.implicits._

scala> def foo[A:Numeric](d : A) = 2 * d
foo: [A](d: A)(implicit evidence$1: spire.math.Numeric[A])A

scala> def foo[A:Numeric](d : A) = 2 + d
foo: [A](d: A)(implicit evidence$1: spire.math.Numeric[A])A

However, if I change the integer 2 to the double 2.0 the compiler complains about not finding an implicit value

scala> def foo[A:Numeric](d : A) = 2.0 + d
<console>:19: error: could not find implicit value for parameter ev: spire.algebra.Field[A]
       def foo[A:Numeric](d : A) = 2.0 + d
                                       ^

scala> def foo[A:Numeric](d : A) = 2.0 * d
<console>:19: error: could not find implicit value for parameter ev: spire.algebra.Field[A]
       def foo[A:Numeric](d : A) = 2.0 * d
                                       ^

I have tried to understand some of the other questions and answers on SO but I am none the wiser on how to solve this.


Source: (StackOverflow)

scala's spire framework : I am unable to operate on a group

I try to use spire, a math framework, but I have an error message:

import spire.algebra._
import spire.implicits._

trait AbGroup[A] extends Group[A]

final class Rationnel_Quadratique(val n1: Int = 2)(val coef: (Int, Int)) {
  override def toString = {
    coef match {
        case (c, i) =>
            s"$c + $i√$n"
    }
  }

  def a() = coef._1

  def b() = coef._2

  def n() = n1


} 

object Rationnel_Quadratique {

  def apply(coef: (Int, Int),n: Int = 2)= {
    new Rationnel_Quadratique(n)(coef)
  }

}

object AbGroup {

  implicit object RQAbGroup extends AbGroup[Rationnel_Quadratique] {

    def +(a: Rationnel_Quadratique, b: Rationnel_Quadratique): Rationnel_Quadratique = Rationnel_Quadratique(coef=(a.a() + b.a(), a.b() + b.b()))

    def inverse(a: Rationnel_Quadratique): Rationnel_Quadratique = Rationnel_Quadratique((-a.a(), -a.b()))

    def id: Rationnel_Quadratique = Rationnel_Quadratique((0, 0))
  }

} 


object euler66_2 extends App {

  val c = Rationnel_Quadratique((1, 2))
  val d = Rationnel_Quadratique((3, 4))
  val e = c + d
  println(e)

}

the program is expected to add 1+2√2 and 3+4√2, but instead I have this error:

could not find implicit value for evidence parameter of type spire.algebra.AdditiveSemigroup[Rationnel_Quadratique] val e = c + d ^

I think there is something essential I have missed (usage of implicits?)

olivier


Source: (StackOverflow)

ambiguous implicit values doing conversions with json types

I am trying to make a generic mapper from a JValue (from json4s) to a Scala case class (with contains spire numeric existential type) and vice versa having the scala case class similar to :

case class SomeStat[T : Numeric](a:T, b:T)

for the generic mapper I have something like:

final class SynchronizerClass[B : Numeric, A <: SomeStat[B]](implicit manifest: Manifest[B], a:Manifest[A])
{format => (
  {case j:JValue => {
    implicit val formats = format
    def extractNumber(j:JValue) = {
      for {
        a <- scala.util.Try((j \ "a").extract[B]).toOption
        b <- scala.util.Try((j \ "b").extract[B]).toOption
      } yield {
        SomeStat(a,b).asInstanceOf[A]
      }
    }
    (extractNumber(j)) getOrElse {
      throw new MappingException("Invalid Number Type")
    }
  }},
  {case x:SomeStat[A] =>
    implicit val formats = format
    Map(
      "a" -> Extraction.decompose(x.a),
      "b" -> Extraction.decompose(x.b)
    )}
  )}

the problem is that spire implicit has two for Numeric, as an example I am trying to construct something like this

val j:JValue = ??? // Some Json Value
val someStat = Extraction.decompose(SomeStat[BigDecimal](j))

Source: (StackOverflow)

Convert excel file to jpg in c#

I am trying to use Spire dll to convert excel file to jpg .

so i have a xlsm file like this :

enter image description here

i use this code to convert it to jpg :

    Workbook workbook = new Workbook();
    workbook.LoadFromFile(@"D:\a.xlsm");
    Worksheet sheet = workbook.Worksheets[1];
    sheet.SaveToImage("exceltoimage.jpg");
    System.Diagnostics.Process.Start("exceltoimage.jpg");

but the output is like this some of the cell can't be converted why i mean (#name)?

enter image description here

I have this warning in my page :

enter image description here


Source: (StackOverflow)

Getting exp to work in spire

I'me learning scala for the purpose of scientific programing. I'm trying to write some simple generic code using spire. I've got the following example working:

import spire.algebra._
import spire.math._
import spire.implicits._
object TestSqrt {
    def testSqrt[T: Numeric](x: T) = {
        sqrt(x)
    }

    def main(args: Array[String]){
        val x_d: Double = 4.0
        println(testSqrt(x_d))

        val x_i: Int = 4
        println(testSqrt(x_i))
    }
}

This prints out 2.0 and 2, as expected. The problem is that I can't get the same thing to work with the exp function. The following code does not compile:

import spire.algebra._
import spire.math._
import spire.implicits._
object TestExp {
    def testExp[T: Numeric](x: T) = {
        exp(x)
    }

    def main(args: Array[String]){
        val x_d: Double = 4.0
        println(testExp(x_d))

        val x_i: Int = 4
        println(testExp(x_i))
    }
}

The compiler says:

... could not find implicit value for parameter t: spire.algebra.Trig[T]
[error]         exp(x)
[error]            ^  
[error] one error found
[error] (compile:compile) Compilation failed

Am I doing something wrong, is exp not yet supported, or is this a bug? Can anyone provide a working example of using exp with a generic numeric type from spire?

UPDATE:

I can make exp work by using Trig instead of Numeric, like this:

import spire.algebra._
import spire.math._
import spire.implicits._
object TestExp {
    def testExp[T: Trig](x: T) = {
        exp(x)
    }

    def main(args: Array[String]){
        val x_d: Double = 1.0
        println(testExp(x_d))

        val x_f: Float = 1.0f
        println(testExp(x_f))
        // val x_i: Int = 4
        // println(testExp(x_i))
    }
}

However, it doesn't work with Int, only floating point types. Further, if I use Trig then I can't use sqrt. The following code does not compile:

}

import spire.algebra._
import spire.math._
import spire.implicits._
object TestSqrt {
    def testSqrt[T: Trig](x: T) = {
        sqrt(x)
    }

    def main(args: Array[String]){
        val x_d: Double = 4.0
        println(testSqrt(x_d))

        val x_i: Int = 4
        println(testSqrt(x_i))
    }
}

And gives the error:

... could not find implicit value for evidence parameter of type spire.algebra.Trig[Int]
[error]         println(testSqrt(x_i))
[error]                         ^
[error] two errors found
[error] (compile:compile) Compilation failed

What should I do if I want both exp and sqrt, and is there a way to make exp work with Integral types?


Source: (StackOverflow)